-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests for interceptor * Bind client to getSigningKey Authored-by: Erik Fried <[email protected]>
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const nock = require('nock'); | ||
const { expect } = require('chai'); | ||
|
||
const { x5cSingle, x5cMultiple } = require('./keys'); | ||
const { JwksClient } = require('../src/JwksClient'); | ||
|
||
describe('JwksClient (interceptor)', () => { | ||
const jwksHost = 'http://my-authz-server'; | ||
|
||
beforeEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
describe('#getSigningKeys', () => { | ||
it('should prefer key from interceptor', async () => { | ||
const client = new JwksClient({ | ||
jwksUri: `${jwksHost}/.well-known/jwks.json`, | ||
getKeysInterceptor: () => Promise.resolve(x5cSingle.keys) | ||
}); | ||
|
||
nock(jwksHost) | ||
.get('/.well-known/jwks.json') | ||
.replyWithError('Call to jwksUri not expected'); | ||
|
||
const key = await client.getSigningKey('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA'); | ||
expect(key.kid).to.equal('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA'); | ||
}); | ||
|
||
it('should fallback to fetch from jwksUri', async () => { | ||
const client = new JwksClient({ | ||
jwksUri: `${jwksHost}/.well-known/jwks.json`, | ||
getKeysInterceptor: () => Promise.resolve([]) | ||
}); | ||
|
||
nock(jwksHost) | ||
.get('/.well-known/jwks.json') | ||
.reply(200, x5cMultiple); | ||
|
||
const key = await client.getSigningKey('RkI5MjI5OUY5ODc1N0Q4QzM0OUYzNkVGMTJDOUEzQkFCOTU3NjE2Rg'); | ||
expect(key.kid).to.equal('RkI5MjI5OUY5ODc1N0Q4QzM0OUYzNkVGMTJDOUEzQkFCOTU3NjE2Rg'); | ||
}); | ||
}); | ||
}); |