Skip to content

Commit

Permalink
feat(AWS API Gateway): Allow use of custom authorizer with authorizerId
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Lanners <adam@onetapaway.com>
  • Loading branch information
darksun and Adam Lanners committed Dec 21, 2021
1 parent 86fa604 commit c0eda27
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/plugins/aws/package/compile/events/apiGateway/index.js
Expand Up @@ -66,7 +66,9 @@ const authorizerSchema = {
resultTtlInSeconds: { type: 'integer', minimum: 0, maximum: 3600 },
scopes: { type: 'array', items: { type: 'string' } },
type: {
anyOf: ['token', 'cognito_user_pools', 'request', 'aws_iam'].map(caseInsensitive),
anyOf: ['token', 'cognito_user_pools', 'request', 'aws_iam', 'custom'].map(
caseInsensitive
),
},
},
required: [],
Expand Down
Expand Up @@ -1508,4 +1508,67 @@ describe('test/unit/lib/plugins/aws/package/compile/events/apiGateway/lib/valida
'API_GATEWAY_MISSING_REST_API_ROOT_RESOURCE_ID'
);
});

it('should throw when using a CUSTOM authorizer without an authorizer id', async () => {
await expect(
runServerless({
fixture: 'function',
command: 'package',
configExt: {
functions: {
first: {
handler: 'index.handler',
events: [
{
http: {
method: 'POST',
path: '/custom-authorizer',
integration: 'lambda-proxy',
authorizer: {
type: 'CUSTOM',
},
},
},
],
},
},
},
})
).to.be.eventually.rejected.and.have.property(
'code',
'API_GATEWAY_MISSING_AUTHORIZER_NAME_OR_ARN'
);
});

it('should not throw when using CUSTOM authorizer with an authorizer id', async () => {
const result = await runServerless({
fixture: 'function',
command: 'package',
configExt: {
functions: {
first: {
handler: 'index.handler',
events: [
{
http: {
method: 'POST',
path: '/custom-authorizer',
integration: 'lambda-proxy',
authorizer: {
type: 'CUSTOM',
authorizerId: 'MyAuthorizerId',
},
},
},
],
},
},
},
});

cfResources = result.cfTemplate.Resources;
naming = result.awsNaming;
const resource = getApiGatewayMethod('/custom-authorizer', 'POST');
expect(resource.Properties.AuthorizationType).to.equal('CUSTOM');
});
});

0 comments on commit c0eda27

Please sign in to comment.