1 | import nock from 'nock';
|
2 | import * as jwksRsaType from '../index';
|
3 | import {expect} from 'chai';
|
4 | const jwksRsa: typeof jwksRsaType = require('../src');
|
5 |
|
6 | describe('typescript definition', () => {
|
7 | const jwksHost = 'http://my-authz-server';
|
8 |
|
9 | const givenPublicCertOnAuthzServer = (kid: string, cert: string) => {
|
10 | nock(jwksHost)
|
11 | .get('/.well-known/jwks.json')
|
12 | .reply(200, {
|
13 | keys: [
|
14 | {
|
15 | alg: 'RS256',
|
16 | kty: 'RSA',
|
17 | use: 'sig',
|
18 | x5c: [cert],
|
19 | kid
|
20 | }
|
21 | ]
|
22 | });
|
23 | }
|
24 |
|
25 | describe('hapiJwt2KeyAsync', () => {
|
26 | it('should return a secret provider function', async () => {
|
27 | givenPublicCertOnAuthzServer('someKeyId', 'pk1');
|
28 |
|
29 | const secretProvider = jwksRsa.hapiJwt2KeyAsync({
|
30 | jwksUri: `${jwksHost}/.well-known/jwks.json`
|
31 | });
|
32 | const { key } = await secretProvider({
|
33 | header: {
|
34 | 'alg': 'RS256',
|
35 | 'kid': 'someKeyId'
|
36 | }
|
37 | });
|
38 |
|
39 | expect(key).to.contain('pk1');
|
40 | });
|
41 | });
|
42 | });
|