Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/__mocks__/mockDataFromES.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const mockResourcePath = () => {
const mockArborist = () => {
nock(config.arboristEndpoint)
.persist()
.get('/auth/mapping')
.post('/auth/mapping')
.reply(200, {
'internal-project-1': [ // accessible
{
Expand Down
23 changes: 21 additions & 2 deletions src/server/auth/arboristClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,34 @@ class ArboristClient {
// Make request to arborist for list of resources with access
const resourcesEndpoint = `${this.baseEndpoint}/auth/mapping`;
log.debug('[ArboristClient] listAuthorizedResources jwt: ', jwt);

const headers = (jwt) ? { Authorization: `bearer ${jwt}` } : {};
return fetch(
resourcesEndpoint,
{
method: 'GET',
method: 'POST',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change since the POST endpoint in older Arborist versions does not accept a token. I think we should add a retry here to make it backwards compatible - if the POST request doesn't work, try a GET request.

And a comment explaining the situation - we can remove the retry in a little while, when it will likely not cause issues

headers,
},
).then(
(response) => response.json(),
(response) => {
if (response.status === 400) {
// Retry with GET instead of POST. Older version of Arborist POST auth/mapping
// didn't support token authentication.
// This catch block can be removed in a little while, when it will likely not cause issues
return fetch(
resourcesEndpoint,
{
method: 'GET',
headers,
},
).then((res) => res.json());
}
return response.json();
},
(err) => {
log.error(err);
throw new CodedError(500, err);
},
).then(
(result) => {
const data = {
Expand Down