From 2400ffc67e1bef985aeb2d98d80897d0dff5718f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Thu, 25 Apr 2024 16:01:06 +0200 Subject: [PATCH] feat: remove bearer token middleware flag (#6934) ## About the changes Removes the bearer token middleware flag for GA --- .../__snapshots__/create-config.test.ts.snap | 1 - .../bearer-token-middleware.test.ts | 19 ++---------------- src/lib/middleware/bearer-token-middleware.ts | 20 ++++--------------- src/lib/types/experimental.ts | 5 ----- 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/src/lib/__snapshots__/create-config.test.ts.snap b/src/lib/__snapshots__/create-config.test.ts.snap index 36b3cf5d2a..072f46c644 100644 --- a/src/lib/__snapshots__/create-config.test.ts.snap +++ b/src/lib/__snapshots__/create-config.test.ts.snap @@ -78,7 +78,6 @@ exports[`should create default config 1`] = ` "anonymiseEventLog": false, "applicationOverviewNewQuery": false, "automatedActions": false, - "bearerTokenMiddleware": false, "caseInsensitiveInOperators": false, "celebrateUnleash": false, "collectTrafficDataUsage": false, diff --git a/src/lib/middleware/bearer-token-middleware.test.ts b/src/lib/middleware/bearer-token-middleware.test.ts index 83d7873962..54a5508c07 100644 --- a/src/lib/middleware/bearer-token-middleware.test.ts +++ b/src/lib/middleware/bearer-token-middleware.test.ts @@ -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( diff --git a/src/lib/middleware/bearer-token-middleware.ts b/src/lib/middleware/bearer-token-middleware.ts index 4b805d83a9..3e431b1664 100644 --- a/src/lib/middleware/bearer-token-middleware.ts +++ b/src/lib/middleware/bearer-token-middleware.ts @@ -2,27 +2,15 @@ import type { Request, Response, NextFunction } from 'express'; import type { IUnleashConfig } from '../types'; export const bearerTokenMiddleware = ({ - server, getLogger, - flagResolver, -}: Pick) => { +}: Pick) => { 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(); }; diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index 37f86ccd89..e8fb7c0d8a 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -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,