forked from aws/serverless-application-model
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Crash when using an invalid method in open api (aws#2001)
When customers use auth and define an invalid method in the open api definition, SAM would return a 'server error'. This was actually due to SAM attempting to get the method from the path. If the method was not a supported method and non-lowercase, SAM would attempt to fetch the lower case method and crash with a KeyError. This PR addresses that by checking for the valid methods supported. Co-authored-by: Jacob Fuss <[email protected]>
- Loading branch information
Showing
6 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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
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
47 changes: 47 additions & 0 deletions
47
tests/translator/input/error_api_with_invalid_path_object.yaml
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,47 @@ | ||
Globals: | ||
Api: | ||
Name: "some api" | ||
Variables: | ||
SomeVar: Value | ||
Auth: | ||
DefaultAuthorizer: MyCognitoAuth | ||
Authorizers: | ||
MyCognitoAuth: | ||
UserPoolArn: !GetAtt MyUserPool.Arn | ||
|
||
Resources: | ||
ImplicitApiFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: s3://sam-demo-bucket/member_portal.zip | ||
Handler: index.gethtml | ||
Runtime: nodejs12.x | ||
|
||
ExplicitApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
StageName: SomeStage | ||
DefinitionBody: | ||
swagger: 2.0 | ||
paths: | ||
"/a": | ||
SomeInvalidKey: | ||
x-amazon-apigateway-integration: | ||
httpMethod: POST | ||
type: aws_proxy | ||
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations | ||
responses: {} | ||
|
||
MyUserPool: | ||
Type: AWS::Cognito::UserPool | ||
Properties: | ||
UserPoolName: UserPoolName | ||
Policies: | ||
PasswordPolicy: | ||
MinimumLength: 8 | ||
UsernameAttributes: | ||
Schema: | ||
- AttributeDataType: String | ||
Name: email | ||
Required: false |
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
3 changes: 3 additions & 0 deletions
3
tests/translator/output/error_api_with_invalid_path_object.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,3 @@ | ||
{ | ||
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Path '/a' contains method 'SomeInvalidKey' which is not a supported method ['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH']" | ||
} |
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