-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from badgateway/error-on-bad-token-replies
Throw error when we get an invalid reply back from a token endpoint.
- Loading branch information
Showing
4 changed files
with
78 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { OAuth2Client } from '../src'; | ||
|
||
|
||
describe('tokenResponseToOAuth2Token', () => { | ||
|
||
it('should convert a JSON response to a OAuth2Token', async () => { | ||
|
||
const client = new OAuth2Client({ | ||
clientId: 'foo', | ||
}); | ||
const token = await client.tokenResponseToOAuth2Token(Promise.resolve({ | ||
token_type: 'bearer', | ||
access_token: 'foo-bar', | ||
})); | ||
|
||
expect(token).to.deep.equal({ | ||
accessToken: 'foo-bar', | ||
expiresAt: null, | ||
refreshToken: null, | ||
}); | ||
|
||
}); | ||
|
||
it('should error when an invalid JSON object is passed', async () => { | ||
|
||
const client = new OAuth2Client({ | ||
clientId: 'foo', | ||
}); | ||
|
||
let caught = false; | ||
try { | ||
await client.tokenResponseToOAuth2Token(Promise.resolve({ | ||
funzies: 'foo-bar', | ||
} as any)); | ||
} catch (err) { | ||
expect(err).to.be.an.instanceof(TypeError); | ||
caught = true; | ||
} | ||
|
||
expect(caught).to.equal(true); | ||
|
||
}); | ||
it('should error when an empty body is passed', async () => { | ||
|
||
const client = new OAuth2Client({ | ||
clientId: 'foo', | ||
}); | ||
|
||
let caught = false; | ||
try { | ||
await client.tokenResponseToOAuth2Token(Promise.resolve(undefined as any)); | ||
} catch (err) { | ||
expect(err).to.be.an.instanceof(TypeError); | ||
caught = true; | ||
} | ||
|
||
expect(caught).to.equal(true); | ||
|
||
}); | ||
}); |