Skip to content

Commit 4a2d628

Browse files
committed
cleanup
1 parent db9166c commit 4a2d628

File tree

9 files changed

+58
-24
lines changed

9 files changed

+58
-24
lines changed

infrastructure/terraform/components/sandbox/aws_cognito_user_pool_sandbox.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ resource "aws_cognito_user_pool" "sandbox" {
99
}
1010

1111
schema {
12-
name = "sbx:client_id"
13-
attribute_data_type = "String"
14-
mutable = true
15-
required = false
12+
name = "sbx:client_id"
13+
attribute_data_type = "String"
14+
mutable = true
15+
required = false
1616
string_attribute_constraints {}
1717
}
1818
}

infrastructure/terraform/modules/backend-api/spec.tmpl.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
},
99
{
1010
"properties": {
11+
"clientId": {
12+
"type": "string"
13+
},
1114
"createdAt": {
1215
"format": "date-time",
1316
"type": "string"
1417
},
18+
"createdBy": {
19+
"type": "string"
20+
},
1521
"id": {
1622
"type": "string"
1723
},
@@ -24,18 +30,12 @@
2430
},
2531
"updatedBy": {
2632
"type": "string"
27-
},
28-
"createdBy": {
29-
"type": "string"
30-
},
31-
"clientId": {
32-
"type": "string"
3333
}
3434
},
3535
"required": [
36+
"createdAt",
3637
"id",
3738
"templateStatus",
38-
"createdAt",
3939
"updatedAt"
4040
],
4141
"type": "object"

infrastructure/terraform/modules/cognito-triggers/module_pre_token_generation_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ module "pre_token_generation_lambda" {
3434
source_arn = "arn:aws:cognito-idp:${var.region}:${var.aws_account_id}:userpool/${var.user_pool_id}"
3535
source_account = var.aws_account_id
3636
}]
37-
}
37+
}

lambdas/authorizer/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const generateMethodArn = (
2020
const generatePolicy = (
2121
Resource: string,
2222
Effect: 'Allow' | 'Deny',
23-
context?: { user: string; clientId: string | undefined }
23+
context?: { user: string; clientId?: string }
2424
) => ({
2525
principalId: 'api-caller',
2626
policyDocument: {

lambdas/backend-api/src/templates/infra/template-repository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ export class TemplateRepository {
627627

628628
const andConditions = [
629629
'attribute_exists(id)',
630-
'NOT templateStatus IN (:deleted, :submitted)',
630+
'NOT #templateStatus IN (:deleted, :submitted)',
631631
...(conditionExpression.$and || []),
632632
].join(' AND ');
633633

@@ -640,9 +640,9 @@ export class TemplateRepository {
640640
UpdateExpression: `SET ${updateExpression.join(', ')}, #updatedAt = :updatedAt, #updatedBy = :updatedBy`,
641641
ExpressionAttributeNames: {
642642
...expressionAttributeNames,
643-
'#updatedAt': ':updatedAt',
644-
'#updatedBy': ':updatedBy',
645-
'#templateStatus': ':templateStatus',
643+
'#updatedAt': 'updatedAt',
644+
'#updatedBy': 'updatedBy',
645+
'#templateStatus': 'templateStatus',
646646
},
647647
ExpressionAttributeValues: {
648648
...expressionAttributeValues,

lambdas/backend-client/src/types/generated/types.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
export type BaseCreatedTemplate = BaseTemplate & {
4+
clientId?: string;
45
createdAt: string;
6+
createdBy?: string;
57
id: string;
68
templateStatus: TemplateStatus;
79
updatedAt: string;
810
updatedBy?: string;
9-
createdBy?: string;
10-
clientId?: string;
1111
};
1212

1313
export type BaseTemplate = {

tests/accessibility/test-user-client.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export class TestUserClient {
2828
},
2929
],
3030
MessageAction: 'SUPPRESS',
31-
ClientMetadata: {
32-
'nhs-notify-client-id': 'client-id',
33-
},
3431
})
3532
);
3633

utils/utils/src/__tests__/lambda-cognito-authorizer.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ describe('LambdaCognitoAuthorizer', () => {
8989
token_use: 'access',
9090
client_id: 'user-pool-client-id',
9191
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id',
92+
'nhs-notify:client-id': 'nhs-notify-client-id',
9293
},
9394
'key',
9495
{
@@ -98,7 +99,34 @@ describe('LambdaCognitoAuthorizer', () => {
9899

99100
const res = await authorizer.authorize(userPoolId, userPoolClientId, jwt);
100101

101-
expect(res).toEqual({ success: true, subject: 'sub' });
102+
expect(res).toEqual({
103+
success: true,
104+
subject: 'sub',
105+
clientId: 'nhs-notify-client-id',
106+
});
107+
expect(mockLogger.logMessages).toEqual([]);
108+
});
109+
110+
test('returns success on valid token without notify-client-id', async () => {
111+
const jwt = sign(
112+
{
113+
token_use: 'access',
114+
client_id: 'user-pool-client-id',
115+
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id',
116+
},
117+
'key',
118+
{
119+
keyid: 'key-id',
120+
}
121+
);
122+
123+
const res = await authorizer.authorize(userPoolId, userPoolClientId, jwt);
124+
125+
expect(res).toEqual({
126+
success: true,
127+
subject: 'sub',
128+
clientId: 'nhs-notify-client-id',
129+
});
102130
expect(mockLogger.logMessages).toEqual([]);
103131
});
104132

@@ -125,6 +153,7 @@ describe('LambdaCognitoAuthorizer', () => {
125153
token_use: 'access',
126154
client_id: 'user-pool-client-id',
127155
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id',
156+
clientId: 'nhs-notify-client-id',
128157
},
129158
'key'
130159
);
@@ -146,6 +175,7 @@ describe('LambdaCognitoAuthorizer', () => {
146175
token_use: 'access',
147176
client_id: 'user-pool-client-id-2',
148177
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id',
178+
clientId: 'nhs-notify-client-id',
149179
},
150180
'key',
151181
{
@@ -171,6 +201,7 @@ describe('LambdaCognitoAuthorizer', () => {
171201
token_use: 'access',
172202
client_id: 'user-pool-client-id',
173203
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id-2',
204+
clientId: 'nhs-notify-client-id',
174205
},
175206
'key',
176207
{
@@ -196,6 +227,7 @@ describe('LambdaCognitoAuthorizer', () => {
196227
token_use: 'id',
197228
client_id: 'user-pool-client-id',
198229
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id',
230+
clientId: 'nhs-notify-client-id',
199231
},
200232
'key',
201233
{
@@ -222,6 +254,7 @@ describe('LambdaCognitoAuthorizer', () => {
222254
token_use: 'access',
223255
client_id: 'user-pool-client-id',
224256
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id-cognito-error',
257+
clientId: 'nhs-notify-client-id',
225258
},
226259
'key',
227260
{
@@ -253,6 +286,7 @@ describe('LambdaCognitoAuthorizer', () => {
253286
token_use: 'access',
254287
client_id: 'user-pool-client-id',
255288
iss: `https://cognito-idp.eu-west-2.amazonaws.com/${iss}`,
289+
clientId: 'nhs-notify-client-id',
256290
},
257291
'key',
258292
{
@@ -279,6 +313,7 @@ describe('LambdaCognitoAuthorizer', () => {
279313
token_use: 'access',
280314
client_id: 'user-pool-client-id',
281315
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id-cognito-no-sub',
316+
clientId: 'nhs-notify-client-id',
282317
},
283318
'key',
284319
{
@@ -307,6 +342,7 @@ describe('LambdaCognitoAuthorizer', () => {
307342
token_use: 'access',
308343
client_id: 'user-pool-client-id',
309344
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id',
345+
clientId: 'nhs-notify-client-id',
310346
},
311347
'key',
312348
{
@@ -337,6 +373,7 @@ describe('LambdaCognitoAuthorizer', () => {
337373
client_id: 'user-pool-client-id',
338374
iss: 'https://cognito-idp.eu-west-2.amazonaws.com/user-pool-id',
339375
exp: 1_640_995_200,
376+
clientId: 'nhs-notify-client-id',
340377
},
341378
'key',
342379
{

utils/utils/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export type GuardDutyMalwareScanStatusPassed = Extract<
9696
>;
9797

9898
export type DatabaseTemplate = {
99+
clientId?: string;
99100
createdAt: string;
100101
createdBy?: string;
101102
files?: LetterFiles;
@@ -110,7 +111,6 @@ export type DatabaseTemplate = {
110111
templateType: TemplateType;
111112
updatedAt: string;
112113
updatedBy?: string;
113-
clientId?: string;
114114
} & DbOnlyTemplateProperties;
115115

116116
type DbOnlyTemplateProperties = {

0 commit comments

Comments
 (0)