-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apigateway): allow overriding authorizer on methods (#30415)
### Issue # (if applicable) Closes #8827. ### Reason for this change Customers could not override the authorizer defined in the default method configuration if they want to set the authorization type to None. ### Description of changes If the customer set the authorization type to None while creating a new method, we will not use the authorizer value defined in the default configuration and instead we will set it to undefined. ### Description of how you validated changes added unit, and integration test cases. ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
11 changed files
with
1,125 additions
and
3 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...shot/apigatewaywithoverridingdefaultauthorizerDefaultTestDeployAssert5491B2D1.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...ot/apigatewaywithoverridingdefaultauthorizerDefaultTestDeployAssert5491B2D1.template.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...gateway/test/authorizers/integ.api-with-overriding-default-authorizer.js.snapshot/cdk.out
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...eway/test/authorizers/integ.api-with-overriding-default-authorizer.js.snapshot/integ.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...t-authorizer.js.snapshot/integtest-restapi-with-overriding-default-authorizer.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
272 changes: 272 additions & 0 deletions
272
...authorizer.js.snapshot/integtest-restapi-with-overriding-default-authorizer.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,272 @@ | ||
{ | ||
"Resources": { | ||
"UserPool6BA7E5F2": { | ||
"Type": "AWS::Cognito::UserPool", | ||
"Properties": { | ||
"AccountRecoverySetting": { | ||
"RecoveryMechanisms": [ | ||
{ | ||
"Name": "verified_phone_number", | ||
"Priority": 1 | ||
}, | ||
{ | ||
"Name": "verified_email", | ||
"Priority": 2 | ||
} | ||
] | ||
}, | ||
"AdminCreateUserConfig": { | ||
"AllowAdminCreateUserOnly": false | ||
}, | ||
"AutoVerifiedAttributes": [ | ||
"email" | ||
], | ||
"EmailVerificationMessage": "The verification code to your new account is {####}", | ||
"EmailVerificationSubject": "Verify your new account", | ||
"SmsVerificationMessage": "The verification code to your new account is {####}", | ||
"UsernameAttributes": [ | ||
"email" | ||
], | ||
"VerificationMessageTemplate": { | ||
"DefaultEmailOption": "CONFIRM_WITH_CODE", | ||
"EmailMessage": "The verification code to your new account is {####}", | ||
"EmailSubject": "Verify your new account", | ||
"SmsMessage": "The verification code to your new account is {####}" | ||
} | ||
}, | ||
"UpdateReplacePolicy": "Retain", | ||
"DeletionPolicy": "Retain" | ||
}, | ||
"AuthorizerBD825682": { | ||
"Type": "AWS::ApiGateway::Authorizer", | ||
"Properties": { | ||
"IdentitySource": "method.request.header.Authorization", | ||
"Name": "integtestrestapiwithoverridingdefaultauthorizerAuthorizerF0743170", | ||
"ProviderARNs": [ | ||
{ | ||
"Fn::GetAtt": [ | ||
"UserPool6BA7E5F2", | ||
"Arn" | ||
] | ||
} | ||
], | ||
"RestApiId": { | ||
"Ref": "ActionsApiGatewayF80386B7" | ||
}, | ||
"Type": "COGNITO_USER_POOLS" | ||
} | ||
}, | ||
"ActionsApiGatewayF80386B7": { | ||
"Type": "AWS::ApiGateway::RestApi", | ||
"Properties": { | ||
"Name": "Actions-ApiGateway" | ||
} | ||
}, | ||
"ActionsApiGatewayDeployment50B6E6A66403e42852ae63ad13a2b7635300f8a9": { | ||
"Type": "AWS::ApiGateway::Deployment", | ||
"Properties": { | ||
"Description": "Automatically created by the RestApi construct", | ||
"RestApiId": { | ||
"Ref": "ActionsApiGatewayF80386B7" | ||
} | ||
}, | ||
"DependsOn": [ | ||
"ActionsApiGatewayANY11FE5E47", | ||
"ActionsApiGatewayGET12E87C75", | ||
"ActionsApiGatewayOPTIONS8EA1F997", | ||
"AuthorizerBD825682" | ||
] | ||
}, | ||
"ActionsApiGatewayDeploymentStageprod812022BF": { | ||
"Type": "AWS::ApiGateway::Stage", | ||
"Properties": { | ||
"DeploymentId": { | ||
"Ref": "ActionsApiGatewayDeployment50B6E6A66403e42852ae63ad13a2b7635300f8a9" | ||
}, | ||
"RestApiId": { | ||
"Ref": "ActionsApiGatewayF80386B7" | ||
}, | ||
"StageName": "prod" | ||
} | ||
}, | ||
"ActionsApiGatewayOPTIONS8EA1F997": { | ||
"Type": "AWS::ApiGateway::Method", | ||
"Properties": { | ||
"ApiKeyRequired": false, | ||
"AuthorizationType": "NONE", | ||
"HttpMethod": "OPTIONS", | ||
"Integration": { | ||
"IntegrationResponses": [ | ||
{ | ||
"ResponseParameters": { | ||
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'", | ||
"method.response.header.Access-Control-Allow-Origin": "'*'", | ||
"method.response.header.Access-Control-Allow-Methods": "'OPTIONS,GET,PUT,POST,DELETE,PATCH,HEAD'", | ||
"method.response.header.Access-Control-Max-Age": "'864000'" | ||
}, | ||
"StatusCode": "204" | ||
} | ||
], | ||
"RequestTemplates": { | ||
"application/json": "{ statusCode: 200 }" | ||
}, | ||
"Type": "MOCK" | ||
}, | ||
"MethodResponses": [ | ||
{ | ||
"ResponseParameters": { | ||
"method.response.header.Access-Control-Allow-Headers": true, | ||
"method.response.header.Access-Control-Allow-Origin": true, | ||
"method.response.header.Access-Control-Allow-Methods": true, | ||
"method.response.header.Access-Control-Max-Age": true | ||
}, | ||
"StatusCode": "204" | ||
} | ||
], | ||
"ResourceId": { | ||
"Fn::GetAtt": [ | ||
"ActionsApiGatewayF80386B7", | ||
"RootResourceId" | ||
] | ||
}, | ||
"RestApiId": { | ||
"Ref": "ActionsApiGatewayF80386B7" | ||
} | ||
} | ||
}, | ||
"ActionsApiGatewayANY11FE5E47": { | ||
"Type": "AWS::ApiGateway::Method", | ||
"Properties": { | ||
"AuthorizationType": "NONE", | ||
"HttpMethod": "ANY", | ||
"Integration": { | ||
"IntegrationResponses": [ | ||
{ | ||
"StatusCode": "200" | ||
} | ||
], | ||
"PassthroughBehavior": "NEVER", | ||
"RequestTemplates": { | ||
"application/json": "{ \"statusCode\": 200 }" | ||
}, | ||
"Type": "MOCK" | ||
}, | ||
"MethodResponses": [ | ||
{ | ||
"StatusCode": "200" | ||
} | ||
], | ||
"ResourceId": { | ||
"Fn::GetAtt": [ | ||
"ActionsApiGatewayF80386B7", | ||
"RootResourceId" | ||
] | ||
}, | ||
"RestApiId": { | ||
"Ref": "ActionsApiGatewayF80386B7" | ||
} | ||
} | ||
}, | ||
"ActionsApiGatewayGET12E87C75": { | ||
"Type": "AWS::ApiGateway::Method", | ||
"Properties": { | ||
"AuthorizationScopes": [ | ||
"scope" | ||
], | ||
"AuthorizationType": "COGNITO_USER_POOLS", | ||
"AuthorizerId": { | ||
"Ref": "AuthorizerBD825682" | ||
}, | ||
"HttpMethod": "GET", | ||
"Integration": { | ||
"IntegrationResponses": [ | ||
{ | ||
"StatusCode": "200" | ||
} | ||
], | ||
"PassthroughBehavior": "NEVER", | ||
"RequestTemplates": { | ||
"application/json": "{ \"statusCode\": 200 }" | ||
}, | ||
"Type": "MOCK" | ||
}, | ||
"MethodResponses": [ | ||
{ | ||
"StatusCode": "200" | ||
} | ||
], | ||
"ResourceId": { | ||
"Fn::GetAtt": [ | ||
"ActionsApiGatewayF80386B7", | ||
"RootResourceId" | ||
] | ||
}, | ||
"RestApiId": { | ||
"Ref": "ActionsApiGatewayF80386B7" | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"ActionsApiGatewayEndpoint261B645B": { | ||
"Value": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"https://", | ||
{ | ||
"Ref": "ActionsApiGatewayF80386B7" | ||
}, | ||
".execute-api.", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
".", | ||
{ | ||
"Ref": "AWS::URLSuffix" | ||
}, | ||
"/", | ||
{ | ||
"Ref": "ActionsApiGatewayDeploymentStageprod812022BF" | ||
}, | ||
"/" | ||
] | ||
] | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.