Skip to content

Commit 85546d8

Browse files
Fix linting
1 parent ed9edae commit 85546d8

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
{
8989
"files": ["*.test.{ts,tsx}"],
9090
"rules": {
91-
"unicorn/no-useless-undefined": "off"
91+
"unicorn/no-useless-undefined": "off",
92+
"unicorn/consistent-function-scoping": "off"
9293
}
9394
}
9495
]

lambdas/authorizer/src/__tests__/index.test.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ jest.mock('@aws-sdk/client-cognito-identity-provider', () => {
4141
});
4242
const warnMock = jest.spyOn(logger, 'warn');
4343
const 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

5057
const 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

152158
test('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(

lambdas/authorizer/src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
GetUserCommand,
88
} from '@aws-sdk/client-cognito-identity-provider';
99
import { jwtDecode } from 'jwt-decode';
10-
import { verify, } from 'jsonwebtoken';
11-
import { logger } from './logger';
10+
import { verify } from 'jsonwebtoken';
1211
import getJwksClient from 'jwks-rsa';
12+
import { logger } from './logger';
1313

1414
const cognitoClient = new CognitoIdentityProviderClient({
1515
region: 'eu-west-2',
@@ -53,12 +53,12 @@ export const handler: APIGatewayTokenAuthorizerHandler = async ({
5353
const issuer = `https://cognito-idp.eu-west-2.amazonaws.com/${userPoolId}`;
5454

5555
const jwksClient = getJwksClient({
56-
jwksUri: `${issuer}/.well-known/jwks.json`
56+
jwksUri: `${issuer}/.well-known/jwks.json`,
5757
});
5858

5959
const decodedToken = jwtDecode(authorizationToken, { header: true });
6060

61-
const kid = decodedToken.kid;
61+
const { kid } = decodedToken;
6262

6363
if (!kid) {
6464
logger.warn('Authorization token missing kid');
@@ -71,10 +71,8 @@ export const handler: APIGatewayTokenAuthorizerHandler = async ({
7171
issuer,
7272
});
7373

74-
const {
75-
client_id: clientId,
76-
token_use: tokenUse,
77-
} = $AccessToken.parse(verifiedToken);
74+
const { client_id: clientId, token_use: tokenUse } =
75+
$AccessToken.parse(verifiedToken);
7876

7977
// client_id claim
8078
if (clientId !== userPoolClientId) {

0 commit comments

Comments
 (0)