Skip to content

Commit

Permalink
fix(apigatewayv2): http api - default route does not use the default …
Browse files Browse the repository at this point in the history
…authorizer (#14904)

The default authorizer worked by passing the authorizer config to routes in the api by the addRoutes method.

We completely forgot about the use case of the default integration, so currently using default integration + default authorizer does not create an authorizer.

This PR fixes the bug and allows using default authorizer + default integration as expected.

Reported by #10534 (comment)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
iRoachie authored Jun 3, 2021
1 parent f66f4b8 commit 25412a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/lib/http/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ export class HttpApi extends HttpApiBase {
httpApi: this,
routeKey: HttpRouteKey.DEFAULT,
integration: props.defaultIntegration,
authorizer: props.defaultAuthorizer,
authorizationScopes: props.defaultAuthorizationScopes,
});
}

Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,24 @@ describe('HttpApi', () => {
});
});

test('can add default authorizer when using default integration', () => {
const stack = new Stack();

const authorizer = new DummyAuthorizer();

new HttpApi(stack, 'api', {
defaultIntegration: new DummyRouteIntegration(),
defaultAuthorizer: authorizer,
defaultAuthorizationScopes: ['read:pets'],
});

expect(stack).toHaveResource('AWS::ApiGatewayV2::Route', {
AuthorizerId: 'auth-1234',
AuthorizationType: 'JWT',
AuthorizationScopes: ['read:pets'],
});
});

test('can add default authorizer, but remove it for a route', () => {
const stack = new Stack();
const authorizer = new DummyAuthorizer();
Expand Down

0 comments on commit 25412a6

Please sign in to comment.