mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Make sure we deny deprecating default strategy
This commit is contained in:
parent
ef19dfa7cb
commit
5f736ccf18
@ -85,14 +85,18 @@ class StrategyController extends Controller {
|
||||
async deprecateStrategy(req, res) {
|
||||
const userName = extractUser(req);
|
||||
const { strategyName } = req.params;
|
||||
try {
|
||||
await this.strategyService.deprecateStrategy(
|
||||
strategyName,
|
||||
userName,
|
||||
);
|
||||
res.status(200).end();
|
||||
} catch (error) {
|
||||
handleErrors(res, this.logger, error);
|
||||
if (strategyName === 'default') {
|
||||
res.status(403).end();
|
||||
} else {
|
||||
try {
|
||||
await this.strategyService.deprecateStrategy(
|
||||
strategyName,
|
||||
userName,
|
||||
);
|
||||
res.status(200).end();
|
||||
} catch (error) {
|
||||
handleErrors(res, this.logger, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,3 +248,11 @@ test('reactivating a non-existent strategy yields 404', t => {
|
||||
.post(`${base}/api/admin/strategies/non-existent-strategy/reactivate`)
|
||||
.expect(404);
|
||||
});
|
||||
test(`deprecating 'default' strategy will yield 403`, t => {
|
||||
t.plan(0);
|
||||
const { request, base, perms } = getSetup();
|
||||
perms.withPermissions(UPDATE_STRATEGY);
|
||||
return request
|
||||
.post(`${base}/api/admin/strategies/default/deprecate`)
|
||||
.expect(403);
|
||||
});
|
||||
|
@ -166,3 +166,9 @@ test.serial('can reactivate a deprecated strategy', async t => {
|
||||
.expect(200)
|
||||
.expect(res => t.is(res.body.deprecated, false));
|
||||
});
|
||||
|
||||
test.serial('cannot deprecate default strategy', async t => {
|
||||
t.plan(0);
|
||||
const request = await setupApp(stores);
|
||||
await request.post('/api/admin/strategies/default/deprecate').expect(403);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user