mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
feat: prevent self dependencies (#5090)
This commit is contained in:
parent
8954277d20
commit
f8855f8234
@ -90,6 +90,12 @@ export class DependentFeaturesService {
|
||||
): Promise<void> {
|
||||
const { enabled, feature: parent, variants } = dependentFeature;
|
||||
|
||||
if (child === parent) {
|
||||
throw new InvalidOperationError(
|
||||
'A feature flag cannot depend on itself.',
|
||||
);
|
||||
}
|
||||
|
||||
const [children, parentExists] = await Promise.all([
|
||||
this.dependentFeaturesReadModel.getChildren([child]),
|
||||
this.featuresReadModel.featureExists(parent),
|
||||
|
@ -194,3 +194,16 @@ test('should check if any dependencies exist', async () => {
|
||||
const { body: dependenciesExistAfter } = await checkDependenciesExist();
|
||||
expect(dependenciesExistAfter).toBe(true);
|
||||
});
|
||||
|
||||
test('should not allow to add dependency to self', async () => {
|
||||
const parent = uuidv4();
|
||||
await app.createFeature(parent);
|
||||
|
||||
await addFeatureDependency(
|
||||
parent,
|
||||
{
|
||||
feature: parent,
|
||||
},
|
||||
403,
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user