1
0
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:
Christopher Kolstad 2021-01-22 10:03:01 +01:00
parent ef19dfa7cb
commit 5f736ccf18
No known key found for this signature in database
GPG Key ID: 319DE53FE911815A
3 changed files with 26 additions and 8 deletions

View File

@ -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);
}
}
}

View File

@ -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);
});

View File

@ -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);
});