1
0
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:
Gastón Fournier 2024-04-25 16:01:06 +02:00 committed by GitHub
parent d6d4d5372f
commit 2400ffc67e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 39 deletions

View File

@ -78,7 +78,6 @@ exports[`should create default config 1`] = `
"anonymiseEventLog": false,
"applicationOverviewNewQuery": false,
"automatedActions": false,
"bearerTokenMiddleware": false,
"caseInsensitiveInOperators": false,
"celebrateUnleash": false,
"collectTrafficDataUsage": false,

View File

@ -16,11 +16,6 @@ describe('bearerTokenMiddleware', () => {
beforeEach(() => {
config = createTestConfig({
getLogger,
experimental: {
flags: {
bearerTokenMiddleware: true,
},
},
});
});
@ -64,14 +59,9 @@ describe('bearerTokenMiddleware', () => {
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({
getLogger,
experimental: {
flags: {
bearerTokenMiddleware: false,
},
},
});
const middleware = bearerTokenMiddleware(
@ -88,17 +78,12 @@ describe('bearerTokenMiddleware', () => {
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({
getLogger,
server: {
baseUriPath: '/some-test-instance',
},
experimental: {
flags: {
bearerTokenMiddleware: false,
},
},
});
const middleware = bearerTokenMiddleware(

View File

@ -2,27 +2,15 @@ import type { Request, Response, NextFunction } from 'express';
import type { IUnleashConfig } from '../types';
export const bearerTokenMiddleware = ({
server,
getLogger,
flagResolver,
}: Pick<IUnleashConfig, 'server' | 'getLogger' | 'flagResolver'>) => {
}: Pick<IUnleashConfig, 'getLogger'>) => {
const logger = getLogger('/middleware/bearer-token-middleware.ts');
logger.debug('Enabling bearer token middleware');
const baseUriPath = server.baseUriPath || '';
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) {
req.headers.authorization = authHeader.replace(
/^Bearer\s+/i,
'',
);
}
if (authHeader) {
req.headers.authorization = authHeader.replace(/^Bearer\s+/i, '');
}
next();
};

View File

@ -53,7 +53,6 @@ export type IFlagKey =
| 'displayEdgeBanner'
| 'projectOverviewRefactor'
| 'disableShowContextFieldSelectionValues'
| 'bearerTokenMiddleware'
| 'projectOverviewRefactorFeedback'
| 'featureLifecycle'
| 'projectListFilterMyProjects'
@ -261,10 +260,6 @@ const flags: IFlags = {
.UNLEASH_EXPERIMENTAL_DISABLE_SHOW_CONTEXT_FIELD_SELECTION_VALUES,
false,
),
bearerTokenMiddleware: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_BEARER_TOKEN_MIDDLEWARE,
false,
),
projectOverviewRefactorFeedback: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_PROJECT_OVERVIEW_REFACTOR_FEEDBACK,
false,