mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-18 01:18:23 +02:00
chore!: remove deprecated POST ui-config endpoint (#10027)
https://linear.app/unleash/issue/2-3472/remove-post-apiadminui-config-deprecated-in-690 Removes POST `/api/admin/ui-config` which was deprecated in v6.9. Also cleans up related code.
This commit is contained in:
parent
27781fea47
commit
e52fcd11e0
@ -215,22 +215,6 @@ export class FrontendApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async setFrontendSettings(
|
|
||||||
value: FrontendSettings,
|
|
||||||
auditUser: IAuditUser,
|
|
||||||
): Promise<void> {
|
|
||||||
const error = validateOrigins(value.frontendApiOrigins);
|
|
||||||
if (error) {
|
|
||||||
throw new BadDataError(error);
|
|
||||||
}
|
|
||||||
await this.services.settingService.insert(
|
|
||||||
frontendSettingsKey,
|
|
||||||
value,
|
|
||||||
auditUser,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async setFrontendCorsSettings(
|
async setFrontendCorsSettings(
|
||||||
value: FrontendSettings['frontendApiOrigins'],
|
value: FrontendSettings['frontendApiOrigins'],
|
||||||
auditUser: IAuditUser,
|
auditUser: IAuditUser,
|
||||||
|
@ -2,7 +2,6 @@ import { resolveOrigin } from './cors-origin-middleware.js';
|
|||||||
import FakeSettingStore from '../../test/fixtures/fake-setting-store.js';
|
import FakeSettingStore from '../../test/fixtures/fake-setting-store.js';
|
||||||
import { createTestConfig } from '../../test/config/test-config.js';
|
import { createTestConfig } from '../../test/config/test-config.js';
|
||||||
import FakeEventStore from '../../test/fixtures/fake-event-store.js';
|
import FakeEventStore from '../../test/fixtures/fake-event-store.js';
|
||||||
import { randomId } from '../util/random-id.js';
|
|
||||||
import FakeProjectStore from '../../test/fixtures/fake-project-store.js';
|
import FakeProjectStore from '../../test/fixtures/fake-project-store.js';
|
||||||
import {
|
import {
|
||||||
FrontendApiService,
|
FrontendApiService,
|
||||||
@ -56,32 +55,21 @@ test('resolveOrigin', () => {
|
|||||||
|
|
||||||
test('corsOriginMiddleware origin validation', async () => {
|
test('corsOriginMiddleware origin validation', async () => {
|
||||||
const { frontendApiService } = createSettingService([]);
|
const { frontendApiService } = createSettingService([]);
|
||||||
const userName = randomId();
|
|
||||||
await expect(() =>
|
await expect(() =>
|
||||||
frontendApiService.setFrontendSettings(
|
frontendApiService.setFrontendCorsSettings(['a'], TEST_AUDIT_USER),
|
||||||
{ frontendApiOrigins: ['a'] },
|
|
||||||
TEST_AUDIT_USER,
|
|
||||||
),
|
|
||||||
).rejects.toThrow('Invalid origin: a');
|
).rejects.toThrow('Invalid origin: a');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('corsOriginMiddleware without config', async () => {
|
test('corsOriginMiddleware without config', async () => {
|
||||||
const { frontendApiService, settingStore } = createSettingService([]);
|
const { frontendApiService, settingStore } = createSettingService([]);
|
||||||
const userName = randomId();
|
|
||||||
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
||||||
frontendApiOrigins: [],
|
frontendApiOrigins: [],
|
||||||
});
|
});
|
||||||
await frontendApiService.setFrontendSettings(
|
await frontendApiService.setFrontendCorsSettings([], TEST_AUDIT_USER);
|
||||||
{ frontendApiOrigins: [] },
|
|
||||||
TEST_AUDIT_USER,
|
|
||||||
);
|
|
||||||
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
||||||
frontendApiOrigins: [],
|
frontendApiOrigins: [],
|
||||||
});
|
});
|
||||||
await frontendApiService.setFrontendSettings(
|
await frontendApiService.setFrontendCorsSettings(['*'], TEST_AUDIT_USER);
|
||||||
{ frontendApiOrigins: ['*'] },
|
|
||||||
TEST_AUDIT_USER,
|
|
||||||
);
|
|
||||||
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
||||||
frontendApiOrigins: ['*'],
|
frontendApiOrigins: ['*'],
|
||||||
});
|
});
|
||||||
@ -93,19 +81,15 @@ test('corsOriginMiddleware without config', async () => {
|
|||||||
|
|
||||||
test('corsOriginMiddleware with config', async () => {
|
test('corsOriginMiddleware with config', async () => {
|
||||||
const { frontendApiService, settingStore } = createSettingService(['*']);
|
const { frontendApiService, settingStore } = createSettingService(['*']);
|
||||||
const userName = randomId();
|
|
||||||
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
||||||
frontendApiOrigins: ['*'],
|
frontendApiOrigins: ['*'],
|
||||||
});
|
});
|
||||||
await frontendApiService.setFrontendSettings(
|
await frontendApiService.setFrontendCorsSettings([], TEST_AUDIT_USER);
|
||||||
{ frontendApiOrigins: [] },
|
|
||||||
TEST_AUDIT_USER,
|
|
||||||
);
|
|
||||||
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
||||||
frontendApiOrigins: [],
|
frontendApiOrigins: [],
|
||||||
});
|
});
|
||||||
await frontendApiService.setFrontendSettings(
|
await frontendApiService.setFrontendCorsSettings(
|
||||||
{ frontendApiOrigins: ['https://example.com', 'https://example.org'] },
|
['https://example.com', 'https://example.org'],
|
||||||
TEST_AUDIT_USER,
|
TEST_AUDIT_USER,
|
||||||
);
|
);
|
||||||
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
expect(await frontendApiService.getFrontendSettings(false)).toEqual({
|
||||||
@ -120,16 +104,12 @@ test('corsOriginMiddleware with config', async () => {
|
|||||||
test('corsOriginMiddleware with caching enabled', async () => {
|
test('corsOriginMiddleware with caching enabled', async () => {
|
||||||
const { frontendApiService } = createSettingService([]);
|
const { frontendApiService } = createSettingService([]);
|
||||||
|
|
||||||
const userName = randomId();
|
|
||||||
expect(await frontendApiService.getFrontendSettings()).toEqual({
|
expect(await frontendApiService.getFrontendSettings()).toEqual({
|
||||||
frontendApiOrigins: [],
|
frontendApiOrigins: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
//setting
|
//setting
|
||||||
await frontendApiService.setFrontendSettings(
|
await frontendApiService.setFrontendCorsSettings(['*'], TEST_AUDIT_USER);
|
||||||
{ frontendApiOrigins: ['*'] },
|
|
||||||
TEST_AUDIT_USER,
|
|
||||||
);
|
|
||||||
|
|
||||||
//still get cached value
|
//still get cached value
|
||||||
expect(await frontendApiService.getFrontendSettings()).toEqual({
|
expect(await frontendApiService.getFrontendSettings()).toEqual({
|
||||||
|
@ -184,7 +184,6 @@ export * from './segment-strategies-schema.js';
|
|||||||
export * from './segments-schema.js';
|
export * from './segments-schema.js';
|
||||||
export * from './set-cors-schema.js';
|
export * from './set-cors-schema.js';
|
||||||
export * from './set-strategy-sort-order-schema.js';
|
export * from './set-strategy-sort-order-schema.js';
|
||||||
export * from './set-ui-config-schema.js';
|
|
||||||
export * from './sort-order-schema.js';
|
export * from './sort-order-schema.js';
|
||||||
export * from './splash-request-schema.js';
|
export * from './splash-request-schema.js';
|
||||||
export * from './splash-response-schema.js';
|
export * from './splash-response-schema.js';
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import type { FromSchema } from 'json-schema-to-ts';
|
|
||||||
|
|
||||||
export const setUiConfigSchema = {
|
|
||||||
$id: '#/components/schemas/setUiConfigSchema',
|
|
||||||
type: 'object',
|
|
||||||
additionalProperties: false,
|
|
||||||
description: 'Unleash configuration settings affect the admin UI.',
|
|
||||||
properties: {
|
|
||||||
frontendSettings: {
|
|
||||||
type: 'object',
|
|
||||||
description: 'Settings related to the front-end API.',
|
|
||||||
additionalProperties: false,
|
|
||||||
required: ['frontendApiOrigins'],
|
|
||||||
properties: {
|
|
||||||
frontendApiOrigins: {
|
|
||||||
description:
|
|
||||||
'The list of origins that the front-end API should accept requests from.',
|
|
||||||
example: ['*'],
|
|
||||||
type: 'array',
|
|
||||||
items: { type: 'string' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
components: {},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export type SetUiConfigSchema = FromSchema<typeof setUiConfigSchema>;
|
|
@ -21,7 +21,6 @@ import type { EmailService } from '../../services/email-service.js';
|
|||||||
import { emptyResponse } from '../../openapi/util/standard-responses.js';
|
import { emptyResponse } from '../../openapi/util/standard-responses.js';
|
||||||
import type { IAuthRequest } from '../unleash-types.js';
|
import type { IAuthRequest } from '../unleash-types.js';
|
||||||
import NotFoundError from '../../error/notfound-error.js';
|
import NotFoundError from '../../error/notfound-error.js';
|
||||||
import type { SetUiConfigSchema } from '../../openapi/spec/set-ui-config-schema.js';
|
|
||||||
import type { SetCorsSchema } from '../../openapi/spec/set-cors-schema.js';
|
import type { SetCorsSchema } from '../../openapi/spec/set-cors-schema.js';
|
||||||
import { createRequestSchema } from '../../openapi/util/create-request-schema.js';
|
import { createRequestSchema } from '../../openapi/util/create-request-schema.js';
|
||||||
import type {
|
import type {
|
||||||
@ -103,25 +102,6 @@ class ConfigController extends Controller {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.route({
|
|
||||||
method: 'post',
|
|
||||||
path: '',
|
|
||||||
handler: this.setUiConfig,
|
|
||||||
permission: ADMIN,
|
|
||||||
middleware: [
|
|
||||||
openApiService.validPath({
|
|
||||||
tags: ['Admin UI'],
|
|
||||||
summary: 'Set UI configuration',
|
|
||||||
description:
|
|
||||||
'Deprecated. Use `./cors` instead. Sets the UI configuration for this Unleash instance.',
|
|
||||||
operationId: 'setUiConfig',
|
|
||||||
requestBody: createRequestSchema('setUiConfigSchema'),
|
|
||||||
responses: { 200: emptyResponse },
|
|
||||||
deprecated: true,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
this.route({
|
this.route({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
path: '/cors',
|
path: '/cors',
|
||||||
@ -210,22 +190,6 @@ class ConfigController extends Controller {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUiConfig(
|
|
||||||
req: IAuthRequest<void, void, SetUiConfigSchema>,
|
|
||||||
res: Response<string>,
|
|
||||||
): Promise<void> {
|
|
||||||
if (req.body.frontendSettings) {
|
|
||||||
await this.frontendApiService.setFrontendSettings(
|
|
||||||
req.body.frontendSettings,
|
|
||||||
req.audit,
|
|
||||||
);
|
|
||||||
res.sendStatus(204);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundError();
|
|
||||||
}
|
|
||||||
|
|
||||||
async setCors(
|
async setCors(
|
||||||
req: IAuthRequest<void, void, SetCorsSchema>,
|
req: IAuthRequest<void, void, SetCorsSchema>,
|
||||||
res: Response<string>,
|
res: Response<string>,
|
||||||
|
@ -58,8 +58,8 @@ test('gets ui config with disablePasswordAuth', async () => {
|
|||||||
|
|
||||||
test('gets ui config with frontendSettings', async () => {
|
test('gets ui config with frontendSettings', async () => {
|
||||||
const frontendApiOrigins = ['https://example.net'];
|
const frontendApiOrigins = ['https://example.net'];
|
||||||
await app.services.frontendApiService.setFrontendSettings(
|
await app.services.frontendApiService.setFrontendCorsSettings(
|
||||||
{ frontendApiOrigins },
|
frontendApiOrigins,
|
||||||
TEST_AUDIT_USER,
|
TEST_AUDIT_USER,
|
||||||
);
|
);
|
||||||
await app.request
|
await app.request
|
||||||
@ -71,35 +71,6 @@ test('gets ui config with frontendSettings', async () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sets ui config with frontendSettings', async () => {
|
|
||||||
const frontendApiOrigins = ['https://example.org'];
|
|
||||||
await app.request
|
|
||||||
.get('/api/admin/ui-config')
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
.expect((res) => expect(res.body.frontendApiOrigins).toEqual(['*']));
|
|
||||||
await app.request
|
|
||||||
.post('/api/admin/ui-config')
|
|
||||||
.send({ frontendSettings: { frontendApiOrigins: [] } })
|
|
||||||
.expect(204);
|
|
||||||
await app.request
|
|
||||||
.get('/api/admin/ui-config')
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
.expect((res) => expect(res.body.frontendApiOrigins).toEqual([]));
|
|
||||||
await app.request
|
|
||||||
.post('/api/admin/ui-config')
|
|
||||||
.send({ frontendSettings: { frontendApiOrigins } })
|
|
||||||
.expect(204);
|
|
||||||
await app.request
|
|
||||||
.get('/api/admin/ui-config')
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
|
||||||
.expect((res) =>
|
|
||||||
expect(res.body.frontendApiOrigins).toEqual(frontendApiOrigins),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('maxSessionsCount', () => {
|
describe('maxSessionsCount', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
// prevent memoization of session count
|
// prevent memoization of session count
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
title: My requests are being blocked by CORS
|
title: My requests are being blocked by CORS
|
||||||
---
|
---
|
||||||
|
|
||||||
1. Make sure you've configured CORS access in Unleash admin UI settings as defined in the [Unleash CORS Policy docs](/reference/front-end-api#configure-cross-origin-resource-sharing-cors). These settings can be changed in the Unleash Dashboard under **Settings -> CORS Origins** or by using the [API](/reference/api/unleash/set-ui-config). Allowing all origins (using a single asterisk) will address this matter and is a great starting point when troubleshooting the behavior.
|
1. Make sure you've configured CORS access in Unleash admin UI settings as defined in the [Unleash CORS Policy docs](/reference/front-end-api#configure-cross-origin-resource-sharing-cors). These settings can be changed in the Unleash Dashboard under **Settings -> CORS Origins** or by using the [API](/reference/api/unleash/set-cors). Allowing all origins (using a single asterisk) will address this matter and is a great starting point when troubleshooting the behavior.
|
||||||
1. When receiving "**No 'Access-Control-Policy' header is present on the requested resource**", using the command `curl -I https://<host>/<endpoint>` will allow us to verify that the response includes the header `Access-Control-Allow-Origin: *`.
|
1. When receiving "**No 'Access-Control-Policy' header is present on the requested resource**", using the command `curl -I https://<host>/<endpoint>` will allow us to verify that the response includes the header `Access-Control-Allow-Origin: *`.
|
Loading…
Reference in New Issue
Block a user