Skip to content

Commit 3933b8c

Browse files
committed
CCM-11889: use internal user id for auth
1 parent 5241739 commit 3933b8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+258
-279
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const allowPolicy = {
4242
],
4343
},
4444
context: {
45-
user: 'sub',
45+
internalUserId: 'user-1234',
4646
clientId: 'client-123',
4747
},
4848
};
@@ -76,7 +76,7 @@ afterEach(() => {
7676
test('returns Allow policy on valid token with clientId', async () => {
7777
lambdaCognitoAuthorizer.authorize.mockResolvedValue({
7878
success: true,
79-
subject: 'sub',
79+
internalUserId: 'user-1234',
8080
clientId: 'client-123',
8181
});
8282

lambdas/authorizer/src/index.ts

Lines changed: 2 additions & 2 deletions
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 }
23+
context?: { internalUserId: string; clientId?: string }
2424
) => ({
2525
principalId: 'api-caller',
2626
policyDocument: {
@@ -66,7 +66,7 @@ export const handler: APIGatewayRequestAuthorizerHandler = async (event) => {
6666

6767
if (authResult.success) {
6868
return generatePolicy(methodArn, 'Allow', {
69-
user: authResult.subject,
69+
internalUserId: authResult.internalUserId,
7070
clientId: authResult.clientId,
7171
});
7272
}

lambdas/backend-api/src/__tests__/api/count-routing-configs.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const setup = () => {
2121
describe('CountRoutingConfigs handler', () => {
2222
test.each([
2323
['undefined', undefined],
24-
['missing user', { clientId: 'client-id', user: undefined }],
25-
['missing client', { clientId: undefined, user: 'user-id' }],
24+
['missing user', { clientId: 'client-id', internalUserId: undefined }],
25+
['missing client', { clientId: undefined, internalUserId: 'user-1234' }],
2626
])(
2727
'should return 400 - Invalid request when requestContext is %s',
2828
async (_, ctx) => {
@@ -62,7 +62,7 @@ describe('CountRoutingConfigs handler', () => {
6262

6363
const event = mock<APIGatewayProxyEvent>();
6464
event.requestContext.authorizer = {
65-
user: 'sub',
65+
internalUserId: 'user-1234',
6666
clientId: 'nhs-notify-client-id',
6767
};
6868

@@ -81,7 +81,7 @@ describe('CountRoutingConfigs handler', () => {
8181
});
8282

8383
expect(mocks.routingConfigClient.countRoutingConfigs).toHaveBeenCalledWith(
84-
{ userId: 'sub', clientId: 'nhs-notify-client-id' },
84+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
8585
{ status: 'DRAFT' }
8686
);
8787
});
@@ -95,7 +95,7 @@ describe('CountRoutingConfigs handler', () => {
9595

9696
const event = mock<APIGatewayProxyEvent>();
9797
event.requestContext.authorizer = {
98-
user: 'sub',
98+
internalUserId: 'user-1234',
9999
clientId: 'nhs-notify-client-id',
100100
};
101101
event.queryStringParameters = {
@@ -110,7 +110,7 @@ describe('CountRoutingConfigs handler', () => {
110110
});
111111

112112
expect(mocks.routingConfigClient.countRoutingConfigs).toHaveBeenCalledWith(
113-
{ userId: 'sub', clientId: 'nhs-notify-client-id' },
113+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
114114
{ status: 'COMPLETED' }
115115
);
116116
});

lambdas/backend-api/src/__tests__/api/create-routing-config.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('Create Routing Config Handler', () => {
1717

1818
test.each([
1919
['undefined', undefined],
20-
['missing user', { clientId: 'client-id', user: undefined }],
21-
['missing client', { clientId: undefined, user: 'user-id' }],
20+
['missing user', { clientId: 'client-id', internalUserId: undefined }],
21+
['missing client', { clientId: undefined, internalUserId: 'user-1234' }],
2222
])(
2323
'should return 400 - Invalid request when requestContext is %s',
2424
async (_, ctx) => {
@@ -63,7 +63,7 @@ describe('Create Routing Config Handler', () => {
6363

6464
const event = mock<APIGatewayProxyEvent>({
6565
requestContext: {
66-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
66+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
6767
},
6868
body: undefined,
6969
});
@@ -83,7 +83,7 @@ describe('Create Routing Config Handler', () => {
8383

8484
expect(mocks.routingConfigClient.createRoutingConfig).toHaveBeenCalledWith(
8585
{},
86-
{ userId: 'sub', clientId: 'nhs-notify-client-id' }
86+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' }
8787
);
8888
});
8989

@@ -101,7 +101,7 @@ describe('Create Routing Config Handler', () => {
101101

102102
const event = mock<APIGatewayProxyEvent>({
103103
requestContext: {
104-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
104+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
105105
},
106106
body: JSON.stringify({ id: 1 }),
107107
});
@@ -118,7 +118,7 @@ describe('Create Routing Config Handler', () => {
118118

119119
expect(mocks.routingConfigClient.createRoutingConfig).toHaveBeenCalledWith(
120120
{ id: 1 },
121-
{ userId: 'sub', clientId: 'nhs-notify-client-id' }
121+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' }
122122
);
123123
});
124124

@@ -156,7 +156,7 @@ describe('Create Routing Config Handler', () => {
156156

157157
const event = mock<APIGatewayProxyEvent>({
158158
requestContext: {
159-
authorizer: { user: 'sub', clientId: 'notify-client-id' },
159+
authorizer: { internalUserId: 'user-1234', clientId: 'notify-client-id' },
160160
},
161161
body: JSON.stringify(create),
162162
});
@@ -171,7 +171,7 @@ describe('Create Routing Config Handler', () => {
171171
expect(mocks.routingConfigClient.createRoutingConfig).toHaveBeenCalledWith(
172172
create,
173173
{
174-
userId: 'sub',
174+
internalUserId: 'user-1234',
175175
clientId: 'notify-client-id',
176176
}
177177
);

lambdas/backend-api/src/__tests__/api/create.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('Template API - Create', () => {
1717

1818
test.each([
1919
['undefined', undefined],
20-
['missing user', { clientId: 'client-id', user: undefined }],
21-
['missing client', { clientId: undefined, user: 'user-id' }],
20+
['missing user', { clientId: 'client-id', internalUserId: undefined }],
21+
['missing client', { clientId: undefined, internalUserId: 'user-1234' }],
2222
])(
2323
'should return 400 - Invalid request when requestContext is %s',
2424
async (_, ctx) => {
@@ -61,7 +61,7 @@ describe('Template API - Create', () => {
6161

6262
const event = mock<APIGatewayProxyEvent>({
6363
requestContext: {
64-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
64+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
6565
},
6666
body: undefined,
6767
});
@@ -81,7 +81,7 @@ describe('Template API - Create', () => {
8181

8282
expect(mocks.templateClient.createTemplate).toHaveBeenCalledWith(
8383
{},
84-
{ userId: 'sub', clientId: 'nhs-notify-client-id' }
84+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' }
8585
);
8686
});
8787

@@ -99,7 +99,7 @@ describe('Template API - Create', () => {
9999

100100
const event = mock<APIGatewayProxyEvent>({
101101
requestContext: {
102-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
102+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
103103
},
104104
body: JSON.stringify({ id: 1 }),
105105
});
@@ -116,7 +116,7 @@ describe('Template API - Create', () => {
116116

117117
expect(mocks.templateClient.createTemplate).toHaveBeenCalledWith(
118118
{ id: 1 },
119-
{ userId: 'sub', clientId: 'nhs-notify-client-id' }
119+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' }
120120
);
121121
});
122122

@@ -143,7 +143,7 @@ describe('Template API - Create', () => {
143143

144144
const event = mock<APIGatewayProxyEvent>({
145145
requestContext: {
146-
authorizer: { user: 'sub', clientId: 'notify-client-id' },
146+
authorizer: { internalUserId: 'user-1234', clientId: 'notify-client-id' },
147147
},
148148
body: JSON.stringify(create),
149149
});
@@ -156,7 +156,7 @@ describe('Template API - Create', () => {
156156
});
157157

158158
expect(mocks.templateClient.createTemplate).toHaveBeenCalledWith(create, {
159-
userId: 'sub',
159+
internalUserId: 'user-1234',
160160
clientId: 'notify-client-id',
161161
});
162162
});

lambdas/backend-api/src/__tests__/api/delete-routing-config.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('Delete Routing Config Handler', () => {
1616

1717
test.each([
1818
['undefined', undefined],
19-
['missing user', { clientId: 'client-id', user: undefined }],
20-
['missing client', { clientId: undefined, user: 'user-id' }],
19+
['missing user', { clientId: 'client-id', internalUserId: undefined }],
20+
['missing client', { clientId: undefined, internalUserId: 'user-1234' }],
2121
])(
2222
'should return 400 - Invalid request when requestContext is %s',
2323
async (_, ctx) => {
@@ -52,7 +52,7 @@ describe('Delete Routing Config Handler', () => {
5252

5353
const event = mock<APIGatewayProxyEvent>({
5454
requestContext: {
55-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
55+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
5656
},
5757
body: JSON.stringify({ name: 'test' }),
5858
pathParameters: { routingConfigId: undefined },
@@ -90,7 +90,7 @@ describe('Delete Routing Config Handler', () => {
9090

9191
const event = mock<APIGatewayProxyEvent>({
9292
requestContext: {
93-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
93+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
9494
},
9595
pathParameters: { routingConfigId: '1-2-3' },
9696
headers: {
@@ -111,7 +111,7 @@ describe('Delete Routing Config Handler', () => {
111111
expect(mocks.routingConfigClient.deleteRoutingConfig).toHaveBeenCalledWith(
112112
'1-2-3',
113113
{
114-
userId: 'sub',
114+
internalUserId: 'user-1234',
115115
clientId: 'nhs-notify-client-id',
116116
},
117117
'0'
@@ -127,7 +127,7 @@ describe('Delete Routing Config Handler', () => {
127127

128128
const event = mock<APIGatewayProxyEvent>({
129129
requestContext: {
130-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
130+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
131131
},
132132
pathParameters: { routingConfigId: '1-2-3' },
133133
headers: {
@@ -145,7 +145,7 @@ describe('Delete Routing Config Handler', () => {
145145
expect(mocks.routingConfigClient.deleteRoutingConfig).toHaveBeenCalledWith(
146146
'1-2-3',
147147
{
148-
userId: 'sub',
148+
internalUserId: 'user-1234',
149149
clientId: 'nhs-notify-client-id',
150150
},
151151
'0'
@@ -167,7 +167,7 @@ describe('Delete Routing Config Handler', () => {
167167

168168
const event = mock<APIGatewayProxyEvent>({
169169
requestContext: {
170-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
170+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
171171
},
172172
pathParameters: { routingConfigId: '1-2-3' },
173173
headers: {},
@@ -186,7 +186,7 @@ describe('Delete Routing Config Handler', () => {
186186

187187
expect(mocks.routingConfigClient.deleteRoutingConfig).toHaveBeenCalledWith(
188188
'1-2-3',
189-
{ userId: 'sub', clientId: 'nhs-notify-client-id' },
189+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
190190
''
191191
);
192192
});

lambdas/backend-api/src/__tests__/api/delete.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('Template API - Delete', () => {
1616

1717
test.each([
1818
['undefined', undefined],
19-
['missing user', { clientId: 'client-id', user: undefined }],
20-
['missing client', { clientId: undefined, user: 'user-id' }],
19+
['missing user', { clientId: 'client-id', internalUserId: undefined }],
20+
['missing client', { clientId: undefined, internalUserId: 'user-1234' }],
2121
])(
2222
'should return 400 - Invalid request when requestContext is %s',
2323
async (_, ctx) => {
@@ -50,7 +50,7 @@ describe('Template API - Delete', () => {
5050

5151
const event = mock<APIGatewayProxyEvent>({
5252
requestContext: {
53-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
53+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
5454
},
5555
body: JSON.stringify({ name: 'test' }),
5656
pathParameters: { templateId: undefined },
@@ -86,7 +86,7 @@ describe('Template API - Delete', () => {
8686

8787
const event = mock<APIGatewayProxyEvent>({
8888
requestContext: {
89-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
89+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
9090
},
9191
pathParameters: { templateId: '1-2-3' },
9292
headers: {
@@ -107,7 +107,7 @@ describe('Template API - Delete', () => {
107107
expect(mocks.templateClient.deleteTemplate).toHaveBeenCalledWith(
108108
'1-2-3',
109109
{
110-
userId: 'sub',
110+
internalUserId: 'user-1234',
111111
clientId: 'nhs-notify-client-id',
112112
},
113113
'0'
@@ -123,7 +123,7 @@ describe('Template API - Delete', () => {
123123

124124
const event = mock<APIGatewayProxyEvent>({
125125
requestContext: {
126-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
126+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
127127
},
128128
pathParameters: { templateId: '1-2-3' },
129129
headers: {
@@ -141,7 +141,7 @@ describe('Template API - Delete', () => {
141141
expect(mocks.templateClient.deleteTemplate).toHaveBeenCalledWith(
142142
'1-2-3',
143143
{
144-
userId: 'sub',
144+
internalUserId: 'user-1234',
145145
clientId: 'nhs-notify-client-id',
146146
},
147147
'0'
@@ -163,7 +163,7 @@ describe('Template API - Delete', () => {
163163

164164
const event = mock<APIGatewayProxyEvent>({
165165
requestContext: {
166-
authorizer: { user: 'sub', clientId: 'nhs-notify-client-id' },
166+
authorizer: { internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
167167
},
168168
pathParameters: { templateId: '1-2-3' },
169169
headers: {},
@@ -182,7 +182,7 @@ describe('Template API - Delete', () => {
182182

183183
expect(mocks.templateClient.deleteTemplate).toHaveBeenCalledWith(
184184
'1-2-3',
185-
{ userId: 'sub', clientId: 'nhs-notify-client-id' },
185+
{ internalUserId: 'user-1234', clientId: 'nhs-notify-client-id' },
186186
''
187187
);
188188
});

0 commit comments

Comments
 (0)