Skip to content

Commit

Permalink
Added unit tests and update return value for raw auth
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDaemonBarber committed Apr 15, 2024
1 parent 0b1f820 commit ad4b443
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/common/utils/auth-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ export default (
}

if (scheme === 'raw') {
return '${token}';
return `${replace(token, config)}`;
}
};
9 changes: 9 additions & 0 deletions test/fixtures/client/filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions test/functional/server-client-universal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`,
// );
Expand All @@ -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();
});

Expand Down
7 changes: 7 additions & 0 deletions test/setup/test-web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit ad4b443

Please sign in to comment.