From ad4b44336766a16d0b3905288cced617ff6ccc48 Mon Sep 17 00:00:00 2001 From: Andy Sweeney <47143023+TheDaemonBarber@users.noreply.github.com> Date: Mon, 15 Apr 2024 09:31:30 +0000 Subject: [PATCH] Added unit tests and update return value for raw auth --- lib/common/utils/auth-header.ts | 2 +- test/fixtures/client/filters.json | 9 +++++++++ test/functional/server-client-universal.test.ts | 9 +++++++++ test/setup/test-web-server.ts | 7 +++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/common/utils/auth-header.ts b/lib/common/utils/auth-header.ts index a6098cc46..3a809c745 100644 --- a/lib/common/utils/auth-header.ts +++ b/lib/common/utils/auth-header.ts @@ -33,6 +33,6 @@ export default ( } if (scheme === 'raw') { - return '${token}'; + return `${replace(token, config)}`; } }; diff --git a/test/fixtures/client/filters.json b/test/fixtures/client/filters.json index 4aa87d0c8..3c316927b 100644 --- a/test/fixtures/client/filters.json +++ b/test/fixtures/client/filters.json @@ -31,6 +31,15 @@ } }, + { + "path": "/echo-auth-header-with-raw-auth/:data", + "method": "GET", + "origin": "http://localhost:9000", + "auth": { + "scheme": "raw", + "token": "${RAW_AUTH}" + } + }, { "path": "/echo-param/:param", diff --git a/test/functional/server-client-universal.test.ts b/test/functional/server-client-universal.test.ts index 4b063f0b6..e2f6eaff0 100644 --- a/test/functional/server-client-universal.test.ts +++ b/test/functional/server-client-universal.test.ts @@ -44,6 +44,7 @@ describe('proxy requests originating from behind the broker server', () => { process.env.AZURE_REPOS_HOST = 'hostname'; process.env.AZURE_REPOS_ORG = 'org'; process.env.JIRA_PAT = 'jirapat'; + process.env.RAW_AUTH = 'CustomScheme CustomToken' process.env.JIRA_HOSTNAME = 'hostname'; process.env.SNYK_BROKER_CLIENT_CONFIGURATION__common__default__BROKER_SERVER_URL = `http://localhost:${bs.port}`; process.env.SNYK_FILTER_RULES_PATHS__github = clientAccept; @@ -90,6 +91,10 @@ describe('proxy requests originating from behind the broker server', () => { { headers: { 'x-broker-ws-response': 'whatever' } }, ); + const response6 = await axiosClient.get( + `http://localhost:${bs.port}/broker/${process.env.BROKER_TOKEN_4}/echo-auth-header-with-raw-auth/xyz`, + ); + // const response6 = await axiosClient.get( // `http://localhost:${bs.port}/broker/${process.env.BROKER_TOKEN_3}/echo-auth-header-with-token-auth/xyz`, // ); @@ -109,6 +114,10 @@ describe('proxy requests originating from behind the broker server', () => { expect(response5.status).toEqual(200); expect(response5.data).toEqual(`Bearer ${process.env.JIRA_PAT}`); + + expect(response6.status).toEqual(200); + expect(response6.data).toEqual(`${process.env.RAW_AUTH}`); + expect(response.headers['x-broker-ws-response']).not.toBeNull(); }); diff --git a/test/setup/test-web-server.ts b/test/setup/test-web-server.ts index 01456ad54..bf7a7c73d 100644 --- a/test/setup/test-web-server.ts +++ b/test/setup/test-web-server.ts @@ -187,6 +187,13 @@ const applyEchoRoutes = (app: Express) => { }, ); + echoRouter.get( + '/echo-auth-header-with-raw-auth/:param', + (req: express.Request, resp: express.Response) => { + resp.send(req.headers.authorization); + }, + ); + echoRouter.get( '/echo-origin/:param', (req: express.Request, resp: express.Response) => {