mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: resolve correct environment for admin tokens (#1951)
This commit is contained in:
parent
651994a5a0
commit
655c0dea2c
@ -8,7 +8,7 @@ import {
|
|||||||
mapFeaturesForClient,
|
mapFeaturesForClient,
|
||||||
mapSegmentsForClient,
|
mapSegmentsForClient,
|
||||||
} from '../util/offline-unleash-client';
|
} from '../util/offline-unleash-client';
|
||||||
import { ALL_PROJECTS } from '../util/constants';
|
import { ALL_ENVS, ALL_PROJECTS } from '../util/constants';
|
||||||
import { UnleashEvents } from 'unleash-client';
|
import { UnleashEvents } from 'unleash-client';
|
||||||
import { ANY_EVENT } from '../util/anyEventEmitter';
|
import { ANY_EVENT } from '../util/anyEventEmitter';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@ -99,7 +99,7 @@ export class ProxyRepository
|
|||||||
return mapFeaturesForClient(
|
return mapFeaturesForClient(
|
||||||
await this.services.featureToggleServiceV2.getClientFeatures({
|
await this.services.featureToggleServiceV2.getClientFeatures({
|
||||||
project: await this.projectIdsForToken(),
|
project: await this.projectIdsForToken(),
|
||||||
environment: this.token.environment,
|
environment: this.environmentNameForToken(),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -118,4 +118,12 @@ export class ProxyRepository
|
|||||||
|
|
||||||
return this.token.projects;
|
return this.token.projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private environmentNameForToken(): string {
|
||||||
|
if (this.token.environment === ALL_ENVS) {
|
||||||
|
return 'default';
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.token.environment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,6 +190,12 @@ test('should allow requests with a token secret alias', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should allow requests with an admin token', async () => {
|
test('should allow requests with an admin token', async () => {
|
||||||
|
const featureA = randomId();
|
||||||
|
await createFeatureToggle({
|
||||||
|
name: featureA,
|
||||||
|
enabled: true,
|
||||||
|
strategies: [{ name: 'default', constraints: [], parameters: {} }],
|
||||||
|
});
|
||||||
const adminToken = await createApiToken(ApiTokenType.ADMIN, {
|
const adminToken = await createApiToken(ApiTokenType.ADMIN, {
|
||||||
projects: ['*'],
|
projects: ['*'],
|
||||||
environment: '*',
|
environment: '*',
|
||||||
@ -199,7 +205,8 @@ test('should allow requests with an admin token', async () => {
|
|||||||
.set('Authorization', adminToken.secret)
|
.set('Authorization', adminToken.secret)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect((res) => expect(res.body).toEqual({ toggles: [] }));
|
.expect((res) => expect(res.body.toggles).toHaveLength(1))
|
||||||
|
.expect((res) => expect(res.body.toggles[0].name).toEqual(featureA));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not allow admin requests with a frontend token', async () => {
|
test('should not allow admin requests with a frontend token', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user