Skip to content

Commit

Permalink
feat: prevent self dependencies (#5090)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Oct 19, 2023
1 parent 8954277 commit f8855f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 13 additions & 0 deletions src/lib/features/dependent-features/dependent.features.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});

0 comments on commit f8855f8

Please sign in to comment.