Skip to content

Commit

Permalink
add custom authorizer to data schema, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnagopinath committed Apr 22, 2021
1 parent 55d81f9 commit 3934a23
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/events/aws/api-gateway-event-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"accountId": "123456789012",
"resourceId": "us4z18",
"stage": "test",
"authorizer": {},
"protocol": "",
"requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9",
"identity": {
"accessKey": "",
Expand All @@ -40,6 +42,7 @@
"caller": "",
"apiKey": "",
"sourceIp": "192.168.100.1",
"principalOrgId": "o-hefegcwbcibwue",
"cognitoAuthenticationType": "",
"cognitoAuthenticationProvider": "",
"userArn": "",
Expand Down
20 changes: 20 additions & 0 deletions lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ describe("createApigEvent()", () => {
expect(parsedBody.last_name).to.equal("Smith");
expect(event.httpMethod).to.equal("GET");
});

it("should return APIG mocked event with custom authorizer", () => {
const event = createEvent("aws:apiGateway", {
requestContext: {
authorizer: {
user_info: JSON.stringify({
id: 1234,
name: "Sam Smith",
}),
},
},
} as any);

expect(!!event.requestContext.authorizer).to.be.true;

const authorizer = event.requestContext.authorizer || {};
const parsedAuthorizer = JSON.parse(authorizer.user_info || "");
expect(parsedAuthorizer.id).to.eql(1234);
expect(parsedAuthorizer.name).to.eql("Sam Smith");
});
});

describe("createWebsocketEvent()", () => {
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SNSEvent,
CloudWatchLogsEvent,
CognitoUserPoolEvent,
APIGatewayProxyWithLambdaAuthorizerEvent,
} from "aws-lambda";
import {
AlexaSmartHomeEvent,
Expand Down

0 comments on commit 3934a23

Please sign in to comment.