1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-14 00:19:16 +01:00

fix: feature type is now validated (#7769)

Previously people were able to send random data to feature type. Now it
is validated.

Fixes https://github.com/Unleash/unleash/issues/7751

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.io>
This commit is contained in:
Jaanus Sellin 2024-08-06 12:27:20 +03:00 committed by GitHub
parent cd5a458d10
commit 0118f88964
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 49 additions and 24 deletions

View File

@ -244,11 +244,11 @@ test('should filter features by type', async () => {
});
await app.createFeature({
name: 'my_feature_b',
type: 'experimental',
type: 'experiment',
});
const { body } = await filterFeaturesByType(
'IS_ANY_OF:experimental,kill-switch',
'IS_ANY_OF:experiment,kill-switch',
);
expect(body).toMatchObject({
@ -263,7 +263,7 @@ test('should filter features by created by', async () => {
});
await app.createFeature({
name: 'my_feature_b',
type: 'experimental',
type: 'experiment',
});
const { body } = await filterFeaturesByCreatedBy('IS:1');

View File

@ -2030,7 +2030,7 @@ test('should clone feature flag without strategies', async () => {
const envName = 'some-env-3';
const featureName = 'feature.flag.base';
const cloneName = 'feature.flag.clone';
const type = 'eExperiment';
const type = 'experiment';
const description = 'Lorem ipsum...';
// Create environment
@ -2069,7 +2069,7 @@ test('should clone feature flag WITH strategies', async () => {
const envName = 'some-env-4';
const featureName = 'feature.flag.base.2';
const cloneName = 'feature.flag.clone.2';
const type = 'eExperiment';
const type = 'experiment';
const description = 'Lorem ipsum...';
// Create environment
@ -2124,7 +2124,7 @@ test('should clone feature flag WITH variants', async () => {
const envName = 'some-env-5';
const featureName = 'feature.flag.base.3';
const cloneName = 'feature.flag.clone.3';
const type = 'eExperiment';
const type = 'experiment';
const description = 'Lorem ipsum...';
const variants = [
{ name: 'variant1', weight: 50 },
@ -2211,7 +2211,7 @@ test('should clone feature flag without replacing groupId', async () => {
test('should clone feature flag WITHOUT createdAt field', async () => {
const featureName = 'feature.flag.base.5';
const cloneName = 'feature.flag.clone.5';
const type = 'eExperiment';
const type = 'experiment';
const description = 'Lorem ipsum...';
const originalCreatedAt = new Date(2011, 11, 11);
@ -3707,3 +3707,13 @@ test('can get evaluation metrics', async () => {
],
});
});
test("Should not be able to create flag with a type that doesn't exist", async () => {
await app.request
.post('/api/admin/projects/default/features')
.send({
type: 'random',
name: 'random.type.flag',
})
.expect(400);
});

View File

@ -150,7 +150,7 @@ test('response for project overview should include feature type counts', async (
});
await app.createFeature({
name: 'my-new-development-toggle',
type: 'development',
type: 'experiment',
});
const { body } = await app.request
.get('/api/admin/projects/default/overview')
@ -159,7 +159,7 @@ test('response for project overview should include feature type counts', async (
expect(body).toMatchObject({
featureTypeCounts: [
{
type: 'development',
type: 'experiment',
count: 1,
},
{

View File

@ -13,7 +13,13 @@ export const createFeatureSchema = {
description: 'Unique feature name',
},
type: {
type: 'string',
enum: [
'experiment',
'kill-switch',
'release',
'operational',
'permission',
],
example: 'release',
description:
"The feature flag's [type](https://docs.getunleash.io/reference/feature-toggle-types). One of experiment, kill-switch, release, operational, or permission",

View File

@ -13,7 +13,13 @@ export const updateFeatureSchema = {
description: 'Detailed description of the feature',
},
type: {
type: 'string',
enum: [
'experiment',
'kill-switch',
'release',
'operational',
'permission',
],
example: 'kill-switch',
description:
'Type of the flag e.g. experiment, kill-switch, release, operational, permission',

View File

@ -125,7 +125,7 @@ test('Can tag features', async () => {
};
await app.request.post('/api/admin/projects/default/features').send({
name: featureName,
type: 'killswitch',
type: 'kill-switch',
enabled: true,
strategies: [{ name: 'default' }],
});
@ -141,7 +141,7 @@ test('Can tag features', async () => {
await app.request.post('/api/admin/projects/default/features').send({
name: featureName2,
type: 'killswitch',
type: 'kill-switch',
enabled: true,
strategies: [{ name: 'default' }],
});
@ -175,17 +175,20 @@ test('Can bulk remove tags', async () => {
await app.request.post('/api/admin/projects/default/features').send({
name: featureName,
type: 'killswitch',
type: 'kill-switch',
enabled: true,
strategies: [{ name: 'default' }],
});
await app.request.post('/api/admin/projects/default/features').send({
name: featureName2,
type: 'killswitch',
enabled: true,
strategies: [{ name: 'default' }],
});
await app.request
.post('/api/admin/projects/default/features')
.send({
name: featureName2,
type: 'kill-switch',
enabled: true,
strategies: [{ name: 'default' }],
})
.expect(201);
await app.request
.put('/api/admin/projects/default/tags')

View File

@ -224,7 +224,7 @@ test('Can get strategies for specific environment', async () => {
// Create feature flag
await app.request.post('/api/admin/projects/default/features').send({
name: featureName,
type: 'killswitch',
type: 'kill-switch',
});
// Add global strategy
@ -277,13 +277,13 @@ test('Can use multiple filters', async () => {
await app.request.post('/api/admin/projects/default/features').send({
name: 'test.feature',
type: 'killswitch',
type: 'kill-switch',
enabled: true,
strategies: [{ name: 'default' }],
});
await app.request.post('/api/admin/projects/default/features').send({
name: 'test.feature2',
type: 'killswitch',
type: 'kill-switch',
enabled: true,
strategies: [{ name: 'default' }],
});
@ -367,7 +367,7 @@ test('Can add tags while creating feature flag', async () => {
await app.request.post('/api/admin/projects/default/features').send({
name: featureName,
type: 'killswitch',
type: 'kill-switch',
tags,
});