Skip to content

Commit

Permalink
Merge pull request #742 from TheDaemonBarber/patch-1
Browse files Browse the repository at this point in the history
feat: add raw auth scheme
  • Loading branch information
aarlaud authored Apr 16, 2024
2 parents 043a748 + a6785ac commit 3c6d490
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/common/utils/auth-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ export default (

return `Basic ${basicAuth}`;
}

if (scheme === 'raw') {
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 3c6d490

Please sign in to comment.