Skip to content

Commit

Permalink
Merge pull request #212 from horike37/feature/fix_missing_scopes
Browse files Browse the repository at this point in the history
fix: scopes is now passed through validation
  • Loading branch information
theburningmonk committed Jun 8, 2019
2 parents f72f3bd + 091534e commit 484486d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/deploy/events/apiGateway/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ module.exports = {
let identityValidationExpression;
let claims;
let authorizerId;
let scopes;

if (typeof authorizer === 'string') {
if (authorizer.toUpperCase() === 'AWS_IAM') {
Expand Down Expand Up @@ -186,6 +187,10 @@ module.exports = {
type = authorizer.type;
}

if (Array.isArray(authorizer.scopes)) {
scopes = authorizer.scopes;
}

resultTtlInSeconds = Number.parseInt(authorizer.resultTtlInSeconds, 10);
resultTtlInSeconds = Number.isNaN(resultTtlInSeconds) ? 300 : resultTtlInSeconds;
claims = authorizer.claims || [];
Expand Down Expand Up @@ -226,6 +231,7 @@ module.exports = {
identitySource,
identityValidationExpression,
claims,
scopes,
};
},

Expand Down
33 changes: 32 additions & 1 deletion lib/deploy/events/apiGateway/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,38 @@ describe('#httpValidate()', () => {
expect(authorizer.identityValidationExpression).to.equal('foo');
});

it('should accept authorizer config with scopes', () => {
serverlessStepFunctions.serverless.service.functions = {
foo: {},
};

serverlessStepFunctions.serverless.service.stepFunctions = {
stateMachines: {
first: {
events: [
{
http: {
method: 'GET',
path: 'foo/bar',
integration: 'MOCK',
authorizer: {
name: 'authorizer',
arn: 'arn:aws:cognito-idp:eu-west-1:xxxxxxxxxx',
identitySouce: 'method.request.header.Authorization',
scopes: ['scope1', 'scope2'],
},
},
},
],
},
},
};

const validated = serverlessStepFunctions.httpValidate();
const authorizer = validated.events[0].http.authorizer;
expect(authorizer.scopes).to.deep.equal(['scope1', 'scope2']);
});

it('should accept authorizer config with a type', () => {
serverlessStepFunctions.serverless.service.functions = {
foo: {},
Expand Down Expand Up @@ -509,7 +541,6 @@ describe('#httpValidate()', () => {
expect(validated.events[0].http.authorizer.authorizerId).to.equal('12345');
});


it('should accept authorizer config with a lambda arn', () => {
serverlessStepFunctions.serverless.service.stepFunctions = {
stateMachines: {
Expand Down

0 comments on commit 484486d

Please sign in to comment.