mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
fix: Return all toggles when env var is set and flag is on
Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
456eb04591
commit
689b46c517
@ -20,6 +20,7 @@ import {
|
|||||||
import { Context } from 'unleash-client';
|
import { Context } from 'unleash-client';
|
||||||
import { enrichContextWithIp } from '../../proxy';
|
import { enrichContextWithIp } from '../../proxy';
|
||||||
import { corsOriginMiddleware } from '../../middleware';
|
import { corsOriginMiddleware } from '../../middleware';
|
||||||
|
import * as process from 'process';
|
||||||
|
|
||||||
interface ApiUserRequest<
|
interface ApiUserRequest<
|
||||||
PARAM = any,
|
PARAM = any,
|
||||||
@ -145,7 +146,10 @@ export default class ProxyController extends Controller {
|
|||||||
res: Response<ProxyFeaturesSchema>,
|
res: Response<ProxyFeaturesSchema>,
|
||||||
) {
|
) {
|
||||||
let toggles;
|
let toggles;
|
||||||
if (this.flagResolver.isEnabled('proxyReturnAllToggles')) {
|
if (
|
||||||
|
this.flagResolver.isEnabled('proxyReturnAllToggles') &&
|
||||||
|
Boolean(process.env.RETURN_ALL_TOGGLES)
|
||||||
|
) {
|
||||||
toggles = await this.services.proxyService.getAllProxyFeatures(
|
toggles = await this.services.proxyService.getAllProxyFeatures(
|
||||||
req.user,
|
req.user,
|
||||||
ProxyController.createContext(req),
|
ProxyController.createContext(req),
|
||||||
|
@ -86,7 +86,7 @@ export class ProxyService {
|
|||||||
|
|
||||||
return definitions.map((feature) => ({
|
return definitions.map((feature) => ({
|
||||||
name: feature.name,
|
name: feature.name,
|
||||||
enabled: Boolean(feature.enabled),
|
enabled: Boolean(client.isEnabled(feature.name)),
|
||||||
variant: client.forceGetVariant(feature.name, context),
|
variant: client.forceGetVariant(feature.name, context),
|
||||||
impressionData: Boolean(feature.impressionData),
|
impressionData: Boolean(feature.impressionData),
|
||||||
}));
|
}));
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
IStrategyConfig,
|
IStrategyConfig,
|
||||||
} from '../../../../lib/types';
|
} from '../../../../lib/types';
|
||||||
import { ProxyRepository } from '../../../../lib/proxy';
|
import { ProxyRepository } from '../../../../lib/proxy';
|
||||||
|
import * as process from 'process';
|
||||||
|
|
||||||
let app: IUnleashTest;
|
let app: IUnleashTest;
|
||||||
let db: ITestDb;
|
let db: ITestDb;
|
||||||
@ -935,6 +936,7 @@ test('Should not recursively set off timers on events', async () => {
|
|||||||
|
|
||||||
test('should return all features when specified', async () => {
|
test('should return all features when specified', async () => {
|
||||||
app.config.experimental.flags.proxyReturnAllToggles = true;
|
app.config.experimental.flags.proxyReturnAllToggles = true;
|
||||||
|
process.env.RETURN_ALL_TOGGLES = 'true';
|
||||||
const frontendToken = await createApiToken(ApiTokenType.FRONTEND);
|
const frontendToken = await createApiToken(ApiTokenType.FRONTEND);
|
||||||
await createFeatureToggle({
|
await createFeatureToggle({
|
||||||
name: 'enabledFeature1',
|
name: 'enabledFeature1',
|
||||||
@ -944,12 +946,32 @@ test('should return all features when specified', async () => {
|
|||||||
await createFeatureToggle({
|
await createFeatureToggle({
|
||||||
name: 'enabledFeature2',
|
name: 'enabledFeature2',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
strategies: [{ name: 'default', constraints: [], parameters: {} }],
|
strategies: [
|
||||||
|
{
|
||||||
|
name: 'flexibleRollout',
|
||||||
|
constraints: [],
|
||||||
|
parameters: {
|
||||||
|
rollout: '100',
|
||||||
|
stickiness: 'default',
|
||||||
|
groupId: 'some-new',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
await createFeatureToggle({
|
await createFeatureToggle({
|
||||||
name: 'disabledFeature',
|
name: 'disabledFeature',
|
||||||
enabled: false,
|
enabled: true,
|
||||||
strategies: [{ name: 'default', constraints: [], parameters: {} }],
|
strategies: [
|
||||||
|
{
|
||||||
|
name: 'flexibleRollout',
|
||||||
|
constraints: [],
|
||||||
|
parameters: {
|
||||||
|
rollout: '0',
|
||||||
|
stickiness: 'default',
|
||||||
|
groupId: 'some-new',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
await app.request
|
await app.request
|
||||||
.get('/api/frontend')
|
.get('/api/frontend')
|
||||||
@ -982,6 +1004,69 @@ test('should return all features when specified', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return all features when env var is set only', async () => {
|
||||||
|
app.config.experimental.flags.proxyReturnAllToggles = true;
|
||||||
|
const frontendToken = await createApiToken(ApiTokenType.FRONTEND);
|
||||||
|
await createFeatureToggle({
|
||||||
|
name: 'enabledFeature1',
|
||||||
|
enabled: true,
|
||||||
|
strategies: [{ name: 'default', constraints: [], parameters: {} }],
|
||||||
|
});
|
||||||
|
await createFeatureToggle({
|
||||||
|
name: 'enabledFeature2',
|
||||||
|
enabled: true,
|
||||||
|
strategies: [
|
||||||
|
{
|
||||||
|
name: 'flexibleRollout',
|
||||||
|
constraints: [],
|
||||||
|
parameters: {
|
||||||
|
rollout: '100',
|
||||||
|
stickiness: 'default',
|
||||||
|
groupId: 'some-new',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
await createFeatureToggle({
|
||||||
|
name: 'disabledFeature',
|
||||||
|
enabled: true,
|
||||||
|
strategies: [
|
||||||
|
{
|
||||||
|
name: 'flexibleRollout',
|
||||||
|
constraints: [],
|
||||||
|
parameters: {
|
||||||
|
rollout: '0',
|
||||||
|
stickiness: 'default',
|
||||||
|
groupId: 'some-new',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
await app.request
|
||||||
|
.get('/api/frontend')
|
||||||
|
.set('Authorization', frontendToken.secret)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200)
|
||||||
|
.expect((res) => {
|
||||||
|
expect(res.body).toEqual({
|
||||||
|
toggles: [
|
||||||
|
{
|
||||||
|
name: 'enabledFeature1',
|
||||||
|
enabled: true,
|
||||||
|
impressionData: false,
|
||||||
|
variant: { enabled: false, name: 'disabled' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'enabledFeature2',
|
||||||
|
enabled: true,
|
||||||
|
impressionData: false,
|
||||||
|
variant: { enabled: false, name: 'disabled' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('should return maxAge header on options call', async () => {
|
test('should return maxAge header on options call', async () => {
|
||||||
await app.request
|
await app.request
|
||||||
.options('/api/frontend')
|
.options('/api/frontend')
|
||||||
|
Loading…
Reference in New Issue
Block a user