Skip to content

Commit

Permalink
fix: non-string error responses are not treated as OpenIdConnectError
Browse files Browse the repository at this point in the history
```
{ error:
      { code: 400,
        message: 'Request contains an invalid argument.',
        status: 'INVALID_ARGUMENT' } }
```
This is not an OpenIdConnectError and will no longer be returned as
such, this will now fall under throwing HTTPError instances instead.

See #125
  • Loading branch information
panva committed Sep 27, 2018
1 parent 4ced646 commit 782d464
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/is_standard_body_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function isStandardBodyError(error) {
if (error instanceof this.httpClient.HTTPError) {
try {
error.response.body = JSON.parse(error.response.body);
return !!error.response.body.error;
return typeof error.response.body.error === 'string' && error.response.body.error.length;
} catch (err) {}
}

Expand Down
14 changes: 14 additions & 0 deletions test/issuer/discover_issuer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ const fail = () => { throw new Error('expected promise to be rejected'); };
});
});

it('is rejected with HTTPError when error is not a string', function () {
nock('https://op.example.com', { allowUnmocked: true })
.get('/.well-known/openid-configuration')
.reply(400, {
error: {},
error_description: 'bad things are happening',
});

return Issuer.discover('https://op.example.com')
.then(fail, function (error) {
expect(error).to.be.an.instanceof(Issuer.httpClient.HTTPError);
});
});

it('is rejected with when non 200 is returned', function () {
nock('https://op.example.com', { allowUnmocked: true })
.get('/.well-known/openid-configuration')
Expand Down

0 comments on commit 782d464

Please sign in to comment.