mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: remove bearer token middleware flag (#6934)
## About the changes Removes the bearer token middleware flag for GA
This commit is contained in:
parent
d6d4d5372f
commit
2400ffc67e
@ -78,7 +78,6 @@ exports[`should create default config 1`] = `
|
|||||||
"anonymiseEventLog": false,
|
"anonymiseEventLog": false,
|
||||||
"applicationOverviewNewQuery": false,
|
"applicationOverviewNewQuery": false,
|
||||||
"automatedActions": false,
|
"automatedActions": false,
|
||||||
"bearerTokenMiddleware": false,
|
|
||||||
"caseInsensitiveInOperators": false,
|
"caseInsensitiveInOperators": false,
|
||||||
"celebrateUnleash": false,
|
"celebrateUnleash": false,
|
||||||
"collectTrafficDataUsage": false,
|
"collectTrafficDataUsage": false,
|
||||||
|
@ -16,11 +16,6 @@ describe('bearerTokenMiddleware', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config = createTestConfig({
|
config = createTestConfig({
|
||||||
getLogger,
|
getLogger,
|
||||||
experimental: {
|
|
||||||
flags: {
|
|
||||||
bearerTokenMiddleware: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -64,14 +59,9 @@ describe('bearerTokenMiddleware', () => {
|
|||||||
expect(req.headers.authorization).toBe(exampleSignalToken);
|
expect(req.headers.authorization).toBe(exampleSignalToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should always run for signal endpoint, regardless of the flag', () => {
|
it('should always run for signal endpoint, without base path', () => {
|
||||||
const configWithBearerTokenMiddlewareFlagDisabled = createTestConfig({
|
const configWithBearerTokenMiddlewareFlagDisabled = createTestConfig({
|
||||||
getLogger,
|
getLogger,
|
||||||
experimental: {
|
|
||||||
flags: {
|
|
||||||
bearerTokenMiddleware: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const middleware = bearerTokenMiddleware(
|
const middleware = bearerTokenMiddleware(
|
||||||
@ -88,17 +78,12 @@ describe('bearerTokenMiddleware', () => {
|
|||||||
expect(req.headers.authorization).toBe(exampleSignalToken);
|
expect(req.headers.authorization).toBe(exampleSignalToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should always run for signal endpoint, regardless of the flag, supporting instance path', () => {
|
it('should always run for signal endpoint, regardless of the flag, with base path', () => {
|
||||||
const configWithBearerTokenMiddlewareFlagDisabled = createTestConfig({
|
const configWithBearerTokenMiddlewareFlagDisabled = createTestConfig({
|
||||||
getLogger,
|
getLogger,
|
||||||
server: {
|
server: {
|
||||||
baseUriPath: '/some-test-instance',
|
baseUriPath: '/some-test-instance',
|
||||||
},
|
},
|
||||||
experimental: {
|
|
||||||
flags: {
|
|
||||||
bearerTokenMiddleware: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const middleware = bearerTokenMiddleware(
|
const middleware = bearerTokenMiddleware(
|
||||||
|
@ -2,27 +2,15 @@ import type { Request, Response, NextFunction } from 'express';
|
|||||||
import type { IUnleashConfig } from '../types';
|
import type { IUnleashConfig } from '../types';
|
||||||
|
|
||||||
export const bearerTokenMiddleware = ({
|
export const bearerTokenMiddleware = ({
|
||||||
server,
|
|
||||||
getLogger,
|
getLogger,
|
||||||
flagResolver,
|
}: Pick<IUnleashConfig, 'getLogger'>) => {
|
||||||
}: Pick<IUnleashConfig, 'server' | 'getLogger' | 'flagResolver'>) => {
|
|
||||||
const logger = getLogger('/middleware/bearer-token-middleware.ts');
|
const logger = getLogger('/middleware/bearer-token-middleware.ts');
|
||||||
logger.debug('Enabling bearer token middleware');
|
logger.debug('Enabling bearer token middleware');
|
||||||
const baseUriPath = server.baseUriPath || '';
|
|
||||||
|
|
||||||
return (req: Request, _: Response, next: NextFunction) => {
|
return (req: Request, _: Response, next: NextFunction) => {
|
||||||
if (
|
|
||||||
req.path.startsWith(`${baseUriPath}/api/signal-endpoint/`) ||
|
|
||||||
flagResolver.isEnabled('bearerTokenMiddleware')
|
|
||||||
) {
|
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
|
|
||||||
if (authHeader) {
|
if (authHeader) {
|
||||||
req.headers.authorization = authHeader.replace(
|
req.headers.authorization = authHeader.replace(/^Bearer\s+/i, '');
|
||||||
/^Bearer\s+/i,
|
|
||||||
'',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
@ -53,7 +53,6 @@ export type IFlagKey =
|
|||||||
| 'displayEdgeBanner'
|
| 'displayEdgeBanner'
|
||||||
| 'projectOverviewRefactor'
|
| 'projectOverviewRefactor'
|
||||||
| 'disableShowContextFieldSelectionValues'
|
| 'disableShowContextFieldSelectionValues'
|
||||||
| 'bearerTokenMiddleware'
|
|
||||||
| 'projectOverviewRefactorFeedback'
|
| 'projectOverviewRefactorFeedback'
|
||||||
| 'featureLifecycle'
|
| 'featureLifecycle'
|
||||||
| 'projectListFilterMyProjects'
|
| 'projectListFilterMyProjects'
|
||||||
@ -261,10 +260,6 @@ const flags: IFlags = {
|
|||||||
.UNLEASH_EXPERIMENTAL_DISABLE_SHOW_CONTEXT_FIELD_SELECTION_VALUES,
|
.UNLEASH_EXPERIMENTAL_DISABLE_SHOW_CONTEXT_FIELD_SELECTION_VALUES,
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
bearerTokenMiddleware: parseEnvVarBoolean(
|
|
||||||
process.env.UNLEASH_EXPERIMENTAL_BEARER_TOKEN_MIDDLEWARE,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
projectOverviewRefactorFeedback: parseEnvVarBoolean(
|
projectOverviewRefactorFeedback: parseEnvVarBoolean(
|
||||||
process.env.UNLEASH_EXPERIMENTAL_PROJECT_OVERVIEW_REFACTOR_FEEDBACK,
|
process.env.UNLEASH_EXPERIMENTAL_PROJECT_OVERVIEW_REFACTOR_FEEDBACK,
|
||||||
false,
|
false,
|
||||||
|
Loading…
Reference in New Issue
Block a user