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:
parent
cd5a458d10
commit
0118f88964
@ -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');
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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,
|
||||
},
|
||||
{
|
||||
|
@ -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",
|
||||
|
@ -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',
|
||||
|
@ -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')
|
||||
|
@ -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,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user