Merge pull request #4650 from thomasmichaelwallace/master

allow authorizer.name to override implied authorizer.arn name.
This commit is contained in:
Takahiro Horike 2018-01-16 08:55:01 +09:00 committed by GitHub
commit 63f15f6741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -220,7 +220,11 @@ module.exports = {
type = 'AWS_IAM';
} else if (authorizer.arn) {
arn = authorizer.arn;
name = this.provider.naming.extractAuthorizerNameFromArn(arn);
if (_.isString(authorizer.name)) {
name = authorizer.name;
} else {
name = this.provider.naming.extractAuthorizerNameFromArn(arn);
}
} else if (authorizer.name) {
name = authorizer.name;
arn = this.getLambdaArn(name);

View File

@ -934,6 +934,30 @@ describe('#validate()', () => {
expect(validated.events[0].http.authorizer.arn).to.equal('xxx:dev-authorizer');
});
it('should handle an authorizer.arn with an explicit authorizer.name object', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {
events: [
{
http: {
path: 'foo/bar',
method: 'GET',
authorizer: {
arn: 'xxx:dev-authorizer',
name: 'custom-name',
},
},
},
],
},
};
const validated = awsCompileApigEvents.validate();
expect(validated.events).to.be.an('Array').with.length(1);
expect(validated.events[0].http.authorizer.name).to.equal('custom-name');
expect(validated.events[0].http.authorizer.arn).to.equal('xxx:dev-authorizer');
});
it('should throw an error if the provided config is not an object', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {