1
0
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:
Mateusz Kwasniewski 2023-10-19 08:57:23 +02:00 committed by GitHub
parent 8954277d20
commit f8855f8234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -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),

View File

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