From d6ca1b166b56463af07e6c376a59491561677ebd Mon Sep 17 00:00:00 2001 From: kwasniew Date: Thu, 19 Oct 2023 08:23:31 +0200 Subject: [PATCH 1/3] feat: prevent self dependencies --- .../dependent-features-service.ts | 4 ++++ .../dependent.features.e2e.test.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/lib/features/dependent-features/dependent-features-service.ts b/src/lib/features/dependent-features/dependent-features-service.ts index fd7603094600..4b29e3df8122 100644 --- a/src/lib/features/dependent-features/dependent-features-service.ts +++ b/src/lib/features/dependent-features/dependent-features-service.ts @@ -90,6 +90,10 @@ export class DependentFeaturesService { ): Promise { const { enabled, feature: parent, variants } = dependentFeature; + if (child === parent) { + throw new InvalidOperationError('Self dependency not allowed.'); + } + const [children, parentExists] = await Promise.all([ this.dependentFeaturesReadModel.getChildren([child]), this.featuresReadModel.featureExists(parent), diff --git a/src/lib/features/dependent-features/dependent.features.e2e.test.ts b/src/lib/features/dependent-features/dependent.features.e2e.test.ts index 3fac621fa327..6e135b758e5a 100644 --- a/src/lib/features/dependent-features/dependent.features.e2e.test.ts +++ b/src/lib/features/dependent-features/dependent.features.e2e.test.ts @@ -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, + ); +}); From d77f5250695c743a8f616850b92d649307cc07e2 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Thu, 19 Oct 2023 08:40:25 +0200 Subject: [PATCH 2/3] Update src/lib/features/dependent-features/dependent-features-service.ts Co-authored-by: Thomas Heartman --- .../features/dependent-features/dependent-features-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/features/dependent-features/dependent-features-service.ts b/src/lib/features/dependent-features/dependent-features-service.ts index 4b29e3df8122..48bcae8d6cc7 100644 --- a/src/lib/features/dependent-features/dependent-features-service.ts +++ b/src/lib/features/dependent-features/dependent-features-service.ts @@ -91,7 +91,7 @@ export class DependentFeaturesService { const { enabled, feature: parent, variants } = dependentFeature; if (child === parent) { - throw new InvalidOperationError('Self dependency not allowed.'); + throw new InvalidOperationError('A feature flag cannot depend on itself.'); } const [children, parentExists] = await Promise.all([ From 2f96a118c91e80f045687d99b3667475f829324c Mon Sep 17 00:00:00 2001 From: kwasniew Date: Thu, 19 Oct 2023 08:49:00 +0200 Subject: [PATCH 3/3] feat: prevent self dependencies --- .../features/dependent-features/dependent-features-service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/features/dependent-features/dependent-features-service.ts b/src/lib/features/dependent-features/dependent-features-service.ts index 48bcae8d6cc7..318b7740e4ec 100644 --- a/src/lib/features/dependent-features/dependent-features-service.ts +++ b/src/lib/features/dependent-features/dependent-features-service.ts @@ -91,7 +91,9 @@ export class DependentFeaturesService { const { enabled, feature: parent, variants } = dependentFeature; if (child === parent) { - throw new InvalidOperationError('A feature flag cannot depend on itself.'); + throw new InvalidOperationError( + 'A feature flag cannot depend on itself.', + ); } const [children, parentExists] = await Promise.all([