1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: use correct project field for proxy features (#1946)

This commit is contained in:
olav 2022-08-19 12:54:40 +02:00 committed by GitHub
parent b8b802c8ed
commit f39f3d59ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -98,7 +98,7 @@ export class ProxyRepository
private async featuresForToken(): Promise<FeatureInterface[]> {
return mapFeaturesForClient(
await this.services.featureToggleServiceV2.getClientFeatures({
project: await this.projectNamesForToken(),
project: await this.projectIdsForToken(),
environment: this.token.environment,
}),
);
@ -110,10 +110,10 @@ export class ProxyRepository
);
}
private async projectNamesForToken(): Promise<string[]> {
private async projectIdsForToken(): Promise<string[]> {
if (this.token.projects.includes(ALL_PROJECTS)) {
const allProjects = await this.stores.projectStore.getAll();
return allProjects.map((project) => project.name);
return allProjects.map((project) => project.id);
}
return this.token.projects;

View File

@ -38,7 +38,7 @@ export const createApiToken = (
): Promise<IApiToken> => {
return app.services.apiTokenService.createApiTokenWithProjects({
type,
projects: ['default'],
projects: ['*'],
environment: 'default',
username: `${type}-token-${randomId()}`,
...overrides,
@ -82,12 +82,12 @@ const createFeatureToggle = async ({
);
};
const createProject = async (id: string): Promise<void> => {
const createProject = async (id: string, name: string): Promise<void> => {
const user = await db.stores.userStore.insert({
name: randomId(),
email: `${randomId()}@example.com`,
});
await app.services.projectService.createProject({ id, name: id }, user);
await app.services.projectService.createProject({ id, name }, user);
};
test('should require a frontend token or an admin token', async () => {
@ -527,9 +527,11 @@ test('should filter features by constraints', async () => {
test('should filter features by project', async () => {
const projectA = 'projectA';
const projectB = 'projectB';
await createProject(projectA);
await createProject(projectB);
const frontendTokenDefault = await createApiToken(ApiTokenType.FRONTEND);
await createProject(projectA, randomId());
await createProject(projectB, randomId());
const frontendTokenDefault = await createApiToken(ApiTokenType.FRONTEND, {
projects: ['default'],
});
const frontendTokenProjectA = await createApiToken(ApiTokenType.FRONTEND, {
projects: [projectA],
});