Skip to content

Commit 1764e1d

Browse files
author
Aleksander Dikanski
committed
Add test for referenced authorizers
1 parent 696c24a commit 1764e1d

File tree

3 files changed

+471
-4
lines changed

3 files changed

+471
-4
lines changed

lib/stackops/apiGateway.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,13 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
225225
const authorizerType = _.get(authorizer, 'Properties.Type');
226226
if (authorizerType === 'TOKEN' || authorizerType === 'REQUEST') {
227227
const uriParts = authorizer.Properties.AuthorizerUri['Fn::Join'][1];
228-
const funcIndex = _.findIndex(uriParts, part =>
229-
_.has(part, 'Fn::GetAtt') || _.startsWith(part, 'arn:aws:lambda'));
228+
if(_.every(uriParts, part => !_.startsWith(part, 'arn:aws:lambda'))) {
229+
const funcIndex = _.findIndex(uriParts, part =>
230+
_.has(part, 'Fn::GetAtt') || _.startsWith(part, 'arn:aws:lambda'));
230231

231-
// Use the SERVERLESS_ALIAS stage variable to determine the called function alias
232-
uriParts.splice(funcIndex + 1, 0, ':${stageVariables.SERVERLESS_ALIAS}');
232+
// Use the SERVERLESS_ALIAS stage variable to determine the called function alias
233+
uriParts.splice(funcIndex + 1, 0, ':${stageVariables.SERVERLESS_ALIAS}');
234+
}
233235
}
234236

235237
authorizer.Properties.Name = `${authorizer.Properties.Name}-${this._alias}`;
@@ -268,6 +270,7 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
268270
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, functionName));
269271
const isExternalRef = _.startsWith(permission.Properties.FunctionName, 'arn:aws:lambda');
270272

273+
console.log('checking permission: ', name, JSON.stringify(permission), ' isExternalRef: ' + isExternalRef);
271274
// Adjust references and alias permissions
272275
if (!isExternalRef) {
273276
permission.Properties.FunctionName = { Ref: aliasName };

0 commit comments

Comments
 (0)