Skip to content

Commit 510d21c

Browse files
committed
try fix packaging
1 parent 514a82a commit 510d21c

File tree

4 files changed

+67
-542
lines changed

4 files changed

+67
-542
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
export { baseJestConfig as default } from 'nhs-notify-web-template-management-utils'; // eslint-disable-line no-restricted-exports
1+
import type { Config } from 'jest';
2+
import { baseJestConfig } from 'nhs-notify-web-template-management-utils'; // eslint-disable-line no-restricted-exports
3+
4+
const config: Config = {
5+
...baseJestConfig,
6+
testEnvironment: 'node',
7+
};
8+
9+
export default config;

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

Lines changed: 49 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,92 +25,64 @@ beforeEach(() => {
2525
jest.clearAllMocks();
2626
});
2727

28-
describe('download authorizer handler', () => {});
29-
30-
test('returns request, when request is valid', async () => {
31-
lambdaCognitoAuthorizer.authorize.mockResolvedValue({
32-
success: true,
33-
subject: 'sub',
34-
});
35-
36-
const res = await handler(
37-
mock<CloudFrontRequestEvent>({
38-
Records: [
39-
{
40-
cf: {
41-
request: {
42-
uri: '',
43-
headers: {
44-
cookies: [{ value: '' }],
45-
},
46-
origin: {
47-
s3: {
48-
customHeaders: {},
28+
const userPoolId = 'user-pool-id';
29+
const userPoolClientId = 'user-pool-client-id';
30+
31+
function makeEvent(
32+
uri: string,
33+
cookie: string | undefined,
34+
customHeaders?: Record<string, string | undefined>
35+
) {
36+
return {
37+
Records: [
38+
{
39+
cf: {
40+
request: {
41+
uri,
42+
headers: {
43+
cookie: [{ value: cookie }],
44+
},
45+
origin: {
46+
s3: {
47+
customHeaders: {
48+
'x-user-pool-id': [{ value: userPoolId }],
49+
'x-user-pool-client-id': [{ value: userPoolClientId }],
50+
...customHeaders,
4951
},
5052
},
5153
},
5254
},
5355
},
54-
],
55-
})
56-
);
56+
},
57+
],
58+
};
59+
}
5760

58-
expect(res).toEqual({});
59-
expect(mockLogger.warn).not.toHaveBeenCalled();
60-
expect(mockLogger.error).not.toHaveBeenCalled();
61+
describe('download authorizer handler', () => {
62+
test('returns request, when request is valid', async () => {
63+
const subject = 'F3FE88F4-4E9E-41EB-BF1E-DC299911968B';
6164

62-
expect(lambdaCognitoAuthorizer.authorize).toHaveBeenCalledWith(
63-
'user-pool-id',
64-
'user-pool-client-id',
65-
'jwt'
66-
);
67-
});
65+
lambdaCognitoAuthorizer.authorize.mockResolvedValue({
66+
success: true,
67+
subject,
68+
});
6869

69-
// test('returns Deny policy on lambda misconfiguration', async () => {
70-
// process.env.USER_POOL_ID = '';
70+
const uri = `/${subject}/template-id/proof1.pdf`;
71+
const cookie = `CognitoIdentityServiceProvider.${userPoolClientId}.${subject}.AccessToken=jwt`;
7172

72-
// const res = await handler(
73-
// mock<APIGatewayRequestAuthorizerEvent>({
74-
// requestContext,
75-
// headers: { Authorization: '123' },
76-
// type: 'REQUEST',
77-
// }),
78-
// mock<Context>(),
79-
// jest.fn()
80-
// );
73+
const event = mock<CloudFrontRequestEvent>(makeEvent(uri, cookie));
8174

82-
// expect(res).toEqual(denyPolicy);
83-
// expect(mockLogger.error).toHaveBeenCalledWith('Lambda misconfiguration');
84-
// });
75+
const res = await handler(event);
8576

86-
// test('returns Deny policy if no Authorization token in header', async () => {
87-
// const res = await handler(
88-
// mock<APIGatewayRequestAuthorizerEvent>({
89-
// requestContext,
90-
// headers: { Authorization: undefined },
91-
// type: 'REQUEST',
92-
// }),
93-
// mock<Context>(),
94-
// jest.fn()
95-
// );
77+
expect(res).toEqual(event.Records[0].cf.request);
78+
expect(mockLogger.warn).not.toHaveBeenCalled();
79+
expect(mockLogger.error).not.toHaveBeenCalled();
9680

97-
// expect(res).toEqual(denyPolicy);
98-
// });
99-
100-
// test('returns Deny policy when authorization fails', async () => {
101-
// lambdaCognitoAuthorizer.authorize.mockResolvedValue({
102-
// success: false,
103-
// });
104-
105-
// const res = await handler(
106-
// mock<APIGatewayRequestAuthorizerEvent>({
107-
// requestContext,
108-
// headers: { Authorization: 'jwt' },
109-
// type: 'REQUEST',
110-
// }),
111-
// mock<Context>(),
112-
// jest.fn()
113-
// );
114-
115-
// expect(res).toEqual(denyPolicy);
116-
// });
81+
expect(lambdaCognitoAuthorizer.authorize).toHaveBeenCalledWith(
82+
'user-pool-id',
83+
'user-pool-client-id',
84+
'jwt',
85+
subject
86+
);
87+
});
88+
});

0 commit comments

Comments
 (0)