update test coverage, fixed typo

update test coverage

update test coverage

add api gateway authorizer with authorizeId
This commit is contained in:
Toan Nguyen 2017-09-02 13:50:00 +02:00 committed by Frank Schmid
parent c90486d50f
commit eac5ab5f04
No known key found for this signature in database
GPG Key ID: D6D684E158939B0C
3 changed files with 42 additions and 1 deletions

View File

@ -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);

View File

@ -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 = [
{
@ -322,6 +348,7 @@ describe('#compileMethods()', () => {
authorizer: {
name: 'Authorizer',
},
integration: 'AWS',
path: 'users/create',
method: 'post',
},

View File

@ -227,6 +227,7 @@ module.exports = {
let resultTtlInSeconds;
let identityValidationExpression;
let claims;
let authorizerId;
if (typeof authorizer === 'string') {
if (authorizer.toUpperCase() === 'AWS_IAM') {
@ -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;
@ -284,6 +288,7 @@ module.exports = {
type,
name,
arn,
authorizerId,
resultTtlInSeconds,
identitySource,
identityValidationExpression,