Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prevent self dependencies #5090

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export class DependentFeaturesService {
): Promise<void> {
const { enabled, feature: parent, variants } = dependentFeature;

if (child === parent) {
throw new InvalidOperationError('Self dependency not allowed.');
kwasniew marked this conversation as resolved.
Show resolved Hide resolved
}

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