-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Added OpenApi body integration testing and updated property builder #5291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lucashuy
merged 5 commits into
aws:feat/terraform-start-api
from
lucashuy:open-api-authorizers
Jun 8, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25a62b6
Added OpenApi body integration testing and updated property builder
lucashuy cccf537
Added more test cases
lucashuy 8537225
Changed tearDown to tearDownClass
lucashuy e6ed491
Updated JSON body parser to handle parsing errors and added unit tests
lucashuy 6238cb4
Removed V1 references
lucashuy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Binary file added
BIN
+551 Bytes
tests/integration/testdata/start_api/terraform/lambda-auth-openapi/lambda-functions.zip
Binary file not shown.
112 changes: 112 additions & 0 deletions
112
tests/integration/testdata/start_api/terraform/lambda-auth-openapi/main.tf
This file contains hidden or 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,112 @@ | ||
| provider "aws" {} | ||
|
|
||
| data "aws_region" "current" {} | ||
|
|
||
| resource "aws_api_gateway_authorizer" "header_authorizer" { | ||
| name = "header-authorizer-open-api" | ||
| rest_api_id = aws_api_gateway_rest_api.api.id | ||
| authorizer_uri = aws_lambda_function.authorizer.invoke_arn | ||
| authorizer_credentials = aws_iam_role.invocation_role.arn | ||
| identity_source = "method.request.header.myheader" | ||
| identity_validation_expression = "^123$" | ||
| } | ||
|
|
||
| resource "aws_lambda_function" "authorizer" { | ||
| filename = "lambda-functions.zip" | ||
| function_name = "authorizer-open-api" | ||
| role = aws_iam_role.invocation_role.arn | ||
| handler = "handlers.auth_handler" | ||
| runtime = "python3.8" | ||
| source_code_hash = filebase64sha256("lambda-functions.zip") | ||
| } | ||
|
|
||
| resource "aws_lambda_function" "hello_endpoint" { | ||
| filename = "lambda-functions.zip" | ||
| function_name = "hello-lambda-open-api" | ||
| role = aws_iam_role.invocation_role.arn | ||
| handler = "handlers.hello_handler" | ||
| runtime = "python3.8" | ||
| source_code_hash = filebase64sha256("lambda-functions.zip") | ||
| } | ||
|
|
||
| resource "aws_api_gateway_rest_api" "api" { | ||
| name = "api-open-api" | ||
| body = jsonencode({ | ||
| swagger = "2.0" | ||
| info = { | ||
| title = "api-body" | ||
| version = "1.0" | ||
| } | ||
| securityDefinitions = { | ||
| TokenAuthorizer = { | ||
| type = "apiKey" | ||
| in = "header" | ||
| name = "myheader" | ||
| x-amazon-apigateway-authtype = "custom" | ||
| x-amazon-apigateway-authorizer = { | ||
| type = "TOKEN" | ||
| authorizerUri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${aws_lambda_function.authorizer.arn}/invocations" | ||
| } | ||
| } | ||
| RequestAuthorizer = { | ||
| type = "apiKey" | ||
| in = "unused" | ||
| name = "unused" | ||
| x-amazon-apigateway-authtype = "custom" | ||
| x-amazon-apigateway-authorizer = { | ||
| type = "REQUEST" | ||
| identitySource = "method.request.header.myheader, method.request.querystring.mystring" | ||
| authorizerUri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${aws_lambda_function.authorizer.arn}/invocations" | ||
| } | ||
| } | ||
| } | ||
| paths = { | ||
| "/hello" = { | ||
| get = { | ||
| security = [ | ||
| {TokenAuthorizer = []} | ||
| ] | ||
| x-amazon-apigateway-integration = { | ||
| httpMethod = "GET" | ||
| payloadFormatVersion = "1.0" | ||
| type = "AWS_PROXY" | ||
| uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${aws_lambda_function.hello_endpoint.arn}/invocations" | ||
| } | ||
| } | ||
| } | ||
| "/hello-request" = { | ||
| get = { | ||
| security = [ | ||
| {RequestAuthorizer = []} | ||
| ] | ||
| x-amazon-apigateway-integration = { | ||
| httpMethod = "GET" | ||
| payloadFormatVersion = "1.0" | ||
| type = "AWS_PROXY" | ||
| uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${aws_lambda_function.hello_endpoint.arn}/invocations" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_iam_role" "invocation_role" { | ||
| name = "iam-lambda-open-api" | ||
| path = "/" | ||
| assume_role_policy = <<EOF | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Action": "sts:AssumeRole", | ||
| "Principal": { | ||
| "Service": "lambda.amazonaws.com" | ||
| }, | ||
| "Effect": "Allow", | ||
| "Sid": "" | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch