Skip to content

Commit

Permalink
add functional tests for http api (#1635)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreya authored and sriram-mv committed Dec 4, 2019
1 parent 7c9407d commit c9c3d77
Show file tree
Hide file tree
Showing 11 changed files with 678 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ boto3~=1.10, >=1.10.29
jmespath~=0.9.4
PyYAML~=5.1
cookiecutter~=1.6.0
aws-sam-translator==1.18.0
aws-sam-translator==1.19.0
docker~=4.0
dateparser~=0.7
python-dateutil~=2.6, <2.8.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: python3.7
Events:
SimpleCase:
Type: HttpApi
Properties:
ApiId: !Ref MyApi
SimpleCase2:
Type: HttpApi
Properties:
ApiId: !Ref MyApi2
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
Auth:
Authorizers:
OAuth2:
AuthorizationScopes:
- scope4
JwtConfiguration:
issuer: "https://www.example.com/v1/connect/oidc"
audience:
- MyApi
IdentitySource: "$request.querystring.param"
DefaultAuthorizer: OAuth2

MyApi2:
Type: AWS::Serverless::HttpApi
Properties:
Auth:
Authorizers:
OAuth2:
JwtConfiguration:
issuer: "https://www.example.com/v1/connect/oidc"
audience:
- MyApi
IdentitySource: "$request.querystring.param"
DefaultAuthorizer: OAuth2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Resources:
Api:
Type: AWS::Serverless::HttpApi
Function:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
CodeUri: s3://bucket/key
Runtime: python3.7
Events:
Api:
Type: HttpApi
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Resources:
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
DefinitionUri: s3://bucket/key
Tags:
Tag: value
StageName: !Join ["", ["Stage", "Name"]]

MyApi2:
Type: AWS::Serverless::HttpApi
Properties:
DefinitionUri:
Bucket: bucket
Key: key
Version: version
Tags:
Tag: value

Function:
Type: AWS::Serverless::Function
Properties:
Runtime: python3.7
Handler: index.handler
CodeUri: s3://bucket/key
Events:
Api:
Type: HttpApi
Properties:
ApiId: MyApi
Api2:
Type: HttpApi
Properties:
ApiId: !Ref MyApi2
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: nodejs4.3
Policies: AmazonDynamoDBFullAccess
Events:
Basic: # integration exists
Type: HttpApi
Properties:
Path: /basic
Method: post
ApiId: !Ref MyApi
SimpleCase: # path exists, integration doesn't
Type: HttpApi
Properties:
ApiId: !Ref MyApi
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
DefinitionBody:
info:
version: '1.0'
title:
Ref: AWS::StackName
paths:
"/basic":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations
payloadFormatVersion: '1.0'
security:
- OpenIdAuth:
- scope3
responses: {}
"/integration":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations
payloadFormatVersion: '1.0'
security:
- OpenIdAuth:
- scope1
- scope2
responses: {}
"$default":
x-amazon-apigateway-any-method:
isDefaultRoute: true
security:
- OpenIdAuth:
- scope1
- scope2
responses: {}
"/oauth2":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations
payloadFormatVersion: '1.0'
security:
- oauth2Auth:
- scope4
responses: {}
openapi: 3.0.1
securitySchemes:
oauth2Auth:
type: oauth2
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
OpenIdAuth:
type: openIdConnect
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
openIdConnectUrl: https://www.example.com/v1/connect
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
Conditions:
condition:
Fn::Equals:
- true
- true
Resources:
HttpApiFunction:
Condition: condition
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: python3.7
Events:
Basic: # integration exists
Type: HttpApi
Properties:
Path: /basic
Method: post
ApiId: !Ref MyApi
Basic2: # integration exists, auth doesn't
Type: HttpApi
Properties:
Path: /basic
Method: get
ApiId: !Ref MyApi
Auth:
Authorizer: OAuth2
AuthorizationScopes:
- basic
SimpleCase: # path exists, integration doesn't
Type: HttpApi
Properties:
ApiId: !Ref MyApi
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
Auth:
Authorizers:
OAuth2:
AuthorizationScopes:
- scope4
JwtConfiguration:
issuer: "https://www.example.com/v1/connect/oidc"
audience:
- MyApi
IdentitySource: "$request.querystring.param"
DefaultAuthorizer: OAuth2
DefinitionBody:
info:
version: '1.0'
title:
Ref: AWS::StackName
paths:
"/basic":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations
payloadFormatVersion: '1.0'
security:
- OpenIdAuth:
- scope3
responses: {}
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations
payloadFormatVersion: '1.0'
responses: {}
"/integration":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations
payloadFormatVersion: '1.0'
security:
- OpenIdAuth:
- scope1
- scope2
responses: {}
"$default":
x-amazon-apigateway-any-method:
isDefaultRoute: true
security:
- OpenIdAuth:
- scope1
- scope2
responses: {}
"/oauth2":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations
payloadFormatVersion: '1.0'
security:
- oauth2Auth:
- scope4
responses: {}
openapi: 3.0.1
securitySchemes:
oauth2Auth:
type: oauth2
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
OpenIdAuth:
type: openIdConnect
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
openIdConnectUrl: https://www.example.com/v1/connect
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: nodejs4.3
Events:
SimpleCase:
Type: HttpApi
Properties:
ApiId: !Ref MyApi
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
StageName: Prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: nodejs4.3
Policies: AmazonDynamoDBFullAccess
Events:
Basic:
Type: HttpApi
Properties:
Path: /basic
Method: post
SimpleCase:
Type: HttpApi

HttpApiFunction2:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: nodejs4.3
Policies: AmazonDynamoDBFullAccess
Events:
Basic2:
Type: HttpApi
Properties:
Path: /basic2
Method: post
Loading

0 comments on commit c9c3d77

Please sign in to comment.