Skip to content

Commit

Permalink
Merge 6765242 into 475474a
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Mar 25, 2024
2 parents 475474a + 6765242 commit e7910db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/access_functions.js
Expand Up @@ -138,9 +138,9 @@ function pepResponse(req, res) {
.then((response) => {
debug(req.user ? 'Permitted.' : 'Public path.');
res.statusCode = response.statusCode;
res.headers = response.headers;
if (response.headers['content-type']){
res.type(response.headers['content-type'])
res.set(response.headers);
if (response.headers['content-type']) {
res.type(response.headers['content-type']);
}
return response.body ? res.send(response.body) : res.send();
})
Expand Down
26 changes: 26 additions & 0 deletions test/unit/authentication-test.js
Expand Up @@ -260,4 +260,30 @@ describe('Authentication: Keyrock IDM', () => {
});
});
});

describe('When a restricted path is requested and headers are returned', () => {
beforeEach(() => {
contextBrokerMock = nock('http://fiware.org:1026').get('/restricted').reply(
StatusCodes.OK,
{},
{
'Content-Type': 'application/ld+json',
'NGSILD-Results-Count': 140000
}
);
idmMock = nock('http://keyrock.com:3000')
.get('/user?access_token=' + shortToken + '&app_id=application_id')
.reply(StatusCodes.OK, keyrock_user_response);
});
it('should return all headers and set the content-type', (done) => {
got.get('restricted', bearer_token).then((response) => {
contextBrokerMock.done();
idmMock.done();
should.equal(response.statusCode, StatusCodes.OK);
should.equal(response.headers['ngsild-results-count'], 140000);
should.equal(response.headers['content-type'], 'application/ld+json; charset=utf-8');
done();
});
});
});
});

0 comments on commit e7910db

Please sign in to comment.