Skip to content

Commit

Permalink
update test coverage, fixed typo
Browse files Browse the repository at this point in the history
update test coverage

update test coverage

add api gateway authorizer with authorizeId
  • Loading branch information
Toan Nguyen authored and Frank Schmid committed May 23, 2018
1 parent c90486d commit eac5ab5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ module.exports = {
}

if (http.authorizer) {
if (http.authorizer.type && http.authorizer.authorizerId) {
return {
Properties: {
AuthorizationType: http.authorizer.type,
AuthorizerId: http.authorizer.authorizerId,
},
};
}

const authorizerLogicalId = this.provider.naming
.getAuthorizerLogicalId(http.authorizer.name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,32 @@ describe('#compileMethods()', () => {
});
});

it('should set custom authorizer config with authorizeId', () => {
awsCompileApigEvents.validated.events = [
{
functionName: 'First',
http: {
path: 'users/create',
method: 'post',
authorizer: {
type: 'COGNITO_USER_POOLS',
authorizerId: 'gy7lyj',
},
},
},
];
return awsCompileApigEvents.compileMethods().then(() => {
expect(
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
.Resources.ApiGatewayMethodUsersCreatePost.Properties.AuthorizationType
).to.equal('COGNITO_USER_POOLS');
expect(
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
.Resources.ApiGatewayMethodUsersCreatePost.Properties.AuthorizerId
).to.equal('gy7lyj');
});
});

it('should set authorizer config if given as ARN string', () => {
awsCompileApigEvents.validated.events = [
{
Expand All @@ -322,6 +348,7 @@ describe('#compileMethods()', () => {
authorizer: {
name: 'Authorizer',
},
integration: 'AWS',
path: 'users/create',
method: 'post',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ module.exports = {
let resultTtlInSeconds;
let identityValidationExpression;
let claims;
let authorizerId;

if (typeof authorizer === 'string') {
if (authorizer.toUpperCase() === 'AWS_IAM') {
Expand All @@ -239,7 +240,10 @@ module.exports = {
name = this.provider.naming.extractAuthorizerNameFromArn(arn);
}
} else if (typeof authorizer === 'object') {
if (authorizer.type && authorizer.type.toUpperCase() === 'AWS_IAM') {
if (authorizer.type && authorizer.authorizerId) {
type = authorizer.type;
authorizerId = authorizer.authorizerId;
} else if (authorizer.type && authorizer.type.toUpperCase() === 'AWS_IAM') {
type = 'AWS_IAM';
} else if (authorizer.arn) {
arn = authorizer.arn;
Expand Down Expand Up @@ -284,6 +288,7 @@ module.exports = {
type,
name,
arn,
authorizerId,
resultTtlInSeconds,
identitySource,
identityValidationExpression,
Expand Down

0 comments on commit eac5ab5

Please sign in to comment.