Skip to content

Commit

Permalink
feat(AWS API Gateway): Allow CF funcs in authorizer.scopes (#11505)
Browse files Browse the repository at this point in the history
  • Loading branch information
franzmango committed Nov 8, 2022
1 parent 7847b20 commit 4169ae1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/plugins/aws/package/compile/events/api-gateway/index.js
Expand Up @@ -63,7 +63,12 @@ const authorizerSchema = {
managedExternally: { type: 'boolean' },
name: { type: 'string' },
resultTtlInSeconds: { type: 'integer', minimum: 0, maximum: 3600 },
scopes: { type: 'array', items: { type: 'string' } },
scopes: {
type: 'array',
items: {
anyOf: [{ type: 'string' }, { $ref: '#/definitions/awsCfInstruction' }],
},
},
type: {
anyOf: ['token', 'cognito_user_pools', 'request', 'aws_iam', 'custom'].map(
caseInsensitive
Expand Down
Expand Up @@ -749,6 +749,38 @@ describe('#compileMethods()', () => {
).to.not.have.property('AuthorizationScopes');
});

it('should pass on import functions for a cognito user pool authorizer scopes', () => {
awsCompileApigEvents.validated.events = [
{
functionName: 'First',
http: {
authorizer: {
name: 'authorizer',
type: 'COGNITO_USER_POOLS',
authorizerId: { Ref: 'CognitoAuthorizer' },
scopes: [
{
'Fn::ImportValue': 'ImportedScope',
},
],
},
integration: 'AWS',
path: 'users/create',
method: 'post',
},
},
];

awsCompileApigEvents.compileMethods();
const resource =
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources
.ApiGatewayMethodUsersCreatePost;

expect(resource.Properties.AuthorizationScopes[0]).to.deep.equal({
'Fn::ImportValue': 'ImportedScope',
});
});

it('should set claims for a cognito user pool', () => {
awsCompileApigEvents.validated.events = [
{
Expand Down

0 comments on commit 4169ae1

Please sign in to comment.