Skip to content

Commit

Permalink
feat(cb2-8066): add permissions for get tech records v2 (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulien-bjss committed May 22, 2023
1 parent 1b50f1a commit d490a25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/functions/functionalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const functionConfig: { [key: string]: NonEmptyArray<IApiAccess> } = {
verbs: ["GET", "OPTIONS"],
path: "vehicles/*",
},
{
verbs: ["GET", "OPTIONS"],
path: "v2/vehicles/*",
},
{
verbs: ["GET", "OPTIONS"],
path: "reference/*",
Expand All @@ -35,6 +39,10 @@ export const functionConfig: { [key: string]: NonEmptyArray<IApiAccess> } = {
verbs: ["GET", "OPTIONS"],
path: "vehicles/*",
},
{
verbs: ["GET", "OPTIONS"],
path: "v2/vehicles/*",
},
],
"TechRecord.Archive": [
{
Expand Down Expand Up @@ -142,12 +150,12 @@ export const functionConfig: { [key: string]: NonEmptyArray<IApiAccess> } = {
{
verbs: ["GET", "OPTIONS"],
path: "reference/*",
}
},
],
"ReferenceData.Amend": [
{
verbs: ["GET", "OPTIONS", "PUT", "POST", "DELETE"],
path: "reference/*",
}
},
],
};
8 changes: 4 additions & 4 deletions tests/unit/functions/authoriser.unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("authorizer() unit tests", () => {
});

it("should fail on non-2xx HTTP status", async () => {
(getValidJwt as jest.Mock) = jest.fn().mockRejectedValue({ statusCode: 418, body: "I'm a teapot", options: { url: "http://example.org" }, response: {} as IncomingMessage});
(getValidJwt as jest.Mock) = jest.fn().mockRejectedValue({ statusCode: 418, body: "I'm a teapot", options: { url: "http://example.org" }, response: {} as IncomingMessage });

await expectUnauthorised(event);
});
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("authorizer() unit tests", () => {

expect(returnValue.principalId).toEqual(jwtJson.payload.sub);

expect(returnValue.policyDocument.Statement.length).toEqual(2);
expect(returnValue.policyDocument.Statement.length).toEqual(4);
expect(returnValue.policyDocument.Statement).toContainEqual({
Effect: "Allow",
Action: "execute-api:Invoke",
Expand All @@ -122,7 +122,7 @@ describe("authorizer() unit tests", () => {
const returnValue: APIGatewayAuthorizerResult = await authorizer(event, exampleContext());

expect(returnValue.principalId).toEqual(jwtJson.payload.sub);
expect(returnValue.policyDocument.Statement.length).toEqual(6);
expect(returnValue.policyDocument.Statement.length).toEqual(8);
});

it("should return an accurate policy based on functional roles", async () => {
Expand All @@ -131,7 +131,7 @@ describe("authorizer() unit tests", () => {
const returnValue: APIGatewayAuthorizerResult = await authorizer(event, exampleContext());

expect(returnValue.principalId).toEqual(jwtJson.payload.sub);
expect(returnValue.policyDocument.Statement.length).toEqual(6);
expect(returnValue.policyDocument.Statement.length).toEqual(8);

const post: { Action: string; Effect: string; Resource: string } = returnValue.policyDocument.Statement[0] as unknown as { Action: string; Effect: string; Resource: string };
expect(post.Effect).toEqual("Allow");
Expand Down

0 comments on commit d490a25

Please sign in to comment.