@@ -41,11 +41,18 @@ jest.mock('@aws-sdk/client-cognito-identity-provider', () => {
4141} ) ;
4242const warnMock = jest . spyOn ( logger , 'warn' ) ;
4343const errorMock = jest . spyOn ( logger , 'error' ) ;
44- jest . mock ( 'jwks-rsa' , ( ) => ( ) => ( {
45- getSigningKey : ( ) => ( {
46- getPublicKey : ( ) => 'key'
47- } )
48- } ) ) ;
44+
45+ jest . mock ( 'jwks-rsa' , ( ) => {
46+ const getPublicKey = ( ) => 'key' ;
47+
48+ const getSigningKey = ( ) => ( {
49+ getPublicKey,
50+ } ) ;
51+
52+ const jwksClient = { getSigningKey } ;
53+
54+ return ( ) => jwksClient ;
55+ } ) ;
4956
5057const allowPolicy = {
5158 principalId : 'api-caller' ,
@@ -118,7 +125,8 @@ test('returns Deny policy on malformed token', async () => {
118125 expect ( res ) . toEqual ( denyPolicy ) ;
119126 expect ( errorMock ) . toHaveBeenCalledWith (
120127 expect . objectContaining ( {
121- message : 'Invalid token specified: invalid base64 for part #1 (base64 string is not of the correct length)' ,
128+ message :
129+ 'Invalid token specified: invalid base64 for part #1 (base64 string is not of the correct length)' ,
122130 } )
123131 ) ;
124132} ) ;
@@ -130,7 +138,7 @@ test('returns Deny policy on token with missing kid', async () => {
130138 client_id : 'user-pool-client-id' ,
131139 iss : 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id' ,
132140 } ,
133- 'key' ,
141+ 'key'
134142 ) ;
135143
136144 const res = await handler (
@@ -144,9 +152,7 @@ test('returns Deny policy on token with missing kid', async () => {
144152 ) ;
145153
146154 expect ( res ) . toEqual ( denyPolicy ) ;
147- expect ( warnMock ) . toHaveBeenCalledWith (
148- 'Authorization token missing kid'
149- ) ;
155+ expect ( warnMock ) . toHaveBeenCalledWith ( 'Authorization token missing kid' ) ;
150156} ) ;
151157
152158test ( 'returns Deny policy on token with incorrect client_id claim' , async ( ) => {
@@ -159,7 +165,7 @@ test('returns Deny policy on token with incorrect client_id claim', async () =>
159165 'key' ,
160166 {
161167 keyid : 'key-id' ,
162- } ,
168+ }
163169 ) ;
164170
165171 const res = await handler (
@@ -188,7 +194,7 @@ test('returns Deny policy on token with incorrect iss claim', async () => {
188194 'key' ,
189195 {
190196 keyid : 'key-id' ,
191- } ,
197+ }
192198 ) ;
193199
194200 const res = await handler (
@@ -204,7 +210,8 @@ test('returns Deny policy on token with incorrect iss claim', async () => {
204210 expect ( res ) . toEqual ( denyPolicy ) ;
205211 expect ( errorMock ) . toHaveBeenCalledWith (
206212 expect . objectContaining ( {
207- message : 'jwt issuer invalid. expected: https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id' ,
213+ message :
214+ 'jwt issuer invalid. expected: https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id' ,
208215 } )
209216 ) ;
210217} ) ;
@@ -219,7 +226,7 @@ test('returns Deny policy on token with incorrect token_use claim', async () =>
219226 'key' ,
220227 {
221228 keyid : 'key-id' ,
222- } ,
229+ }
223230 ) ;
224231
225232 const res = await handler (
@@ -250,7 +257,7 @@ test('returns Deny policy on Cognito not validating the token', async () => {
250257 'key' ,
251258 {
252259 keyid : 'key-id' ,
253- } ,
260+ }
254261 ) ;
255262
256263 const res = await handler (
@@ -281,7 +288,7 @@ test('returns Allow policy on valid token', async () => {
281288 'key' ,
282289 {
283290 keyid : 'key-id' ,
284- } ,
291+ }
285292 ) ;
286293
287294 const res = await handler (
@@ -305,12 +312,12 @@ test('returns Deny policy on expired token', async () => {
305312 token_use : 'access' ,
306313 client_id : 'user-pool-client-id' ,
307314 iss : 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id' ,
308- exp : 1640995200 ,
315+ exp : 1_640_995_200 ,
309316 } ,
310317 'key' ,
311318 {
312319 keyid : 'key-id' ,
313- } ,
320+ }
314321 ) ;
315322
316323 const res = await handler (
0 commit comments