-
Notifications
You must be signed in to change notification settings - Fork 4
NRL-512 Initial implementation for rejecting HEAD requests #938
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c1ea9a4
NRL-512 Initial implementation for rejecting HEAD requests
axelkrastek1-nhs 81a286e
NRL-512 All endpoints and integration tests working
axelkrastek1-nhs 872faba
NRL-512 Fix methods for producer and auto deploy
axelkrastek1-nhs 8c024b3
NRL-512 Remove unused step
axelkrastek1-nhs 8a3ea48
NRL-512 An unsupported content-type will respond with 415, rename ter…
axelkrastek1-nhs e959122
NRL-512 Add HEAD requests note to capability statement
axelkrastek1-nhs 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
67 changes: 67 additions & 0 deletions
67
terraform/infrastructure/modules/api_gateway/head_responses.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,67 @@ | ||
| # Define a reusable map of allowed methods for each path | ||
| data "aws_api_gateway_resource" "resource" { | ||
| for_each = var.endpoint_allowed_methods | ||
| rest_api_id = aws_api_gateway_rest_api.api_gateway_rest_api.id | ||
| path = each.key | ||
|
|
||
| depends_on = [aws_api_gateway_rest_api.api_gateway_rest_api] | ||
| } | ||
|
|
||
| # Add HEAD method to each resource with 405 response | ||
| resource "aws_api_gateway_method" "head_method" { | ||
| for_each = var.endpoint_allowed_methods | ||
|
|
||
| rest_api_id = aws_api_gateway_rest_api.api_gateway_rest_api.id | ||
| resource_id = data.aws_api_gateway_resource.resource[each.key].id | ||
| http_method = "HEAD" | ||
| authorization = "NONE" | ||
| } | ||
|
|
||
| resource "aws_api_gateway_integration" "head_integration" { | ||
| for_each = var.endpoint_allowed_methods | ||
|
|
||
| rest_api_id = aws_api_gateway_rest_api.api_gateway_rest_api.id | ||
| resource_id = data.aws_api_gateway_resource.resource[each.key].id | ||
| http_method = aws_api_gateway_method.head_method[each.key].http_method | ||
| type = "MOCK" | ||
| passthrough_behavior = "WHEN_NO_TEMPLATES" | ||
|
|
||
| request_templates = { | ||
| "application/json" = <<-EOF | ||
| { "statusCode": 405 } | ||
| EOF | ||
| "application/json+fhir" = <<-EOF | ||
| { "statusCode": 405 } | ||
| EOF | ||
| "application/fhir+json" = <<-EOF | ||
| { "statusCode": 405 } | ||
| EOF | ||
| } | ||
| } | ||
|
|
||
| resource "aws_api_gateway_method_response" "head_method_response" { | ||
| for_each = var.endpoint_allowed_methods | ||
|
|
||
| rest_api_id = aws_api_gateway_rest_api.api_gateway_rest_api.id | ||
| resource_id = data.aws_api_gateway_resource.resource[each.key].id | ||
| http_method = aws_api_gateway_method.head_method[each.key].http_method | ||
| status_code = "405" | ||
|
|
||
| response_parameters = { | ||
| "method.response.header.Allow" = true | ||
| } | ||
| } | ||
|
|
||
| resource "aws_api_gateway_integration_response" "head_integration_response" { | ||
| for_each = var.endpoint_allowed_methods | ||
|
|
||
| rest_api_id = aws_api_gateway_rest_api.api_gateway_rest_api.id | ||
| resource_id = data.aws_api_gateway_resource.resource[each.key].id | ||
| http_method = aws_api_gateway_method.head_method[each.key].http_method | ||
| status_code = aws_api_gateway_method_response.head_method_response[each.key].status_code | ||
| selection_pattern = "" # default catch-all | ||
|
|
||
| response_parameters = { | ||
| "method.response.header.Allow" = "'${each.value}'" | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -22,3 +22,7 @@ variable "retention" { | |
| default = 90 | ||
| type = number | ||
| } | ||
|
|
||
| variable "endpoint_allowed_methods" { | ||
| type = map(string) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| Feature: Consumer - HEAD Requests | ||
|
|
||
| Scenario Outline: DocumentReference with HEAD fails (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When consumer 'RX898' sends HEAD request to 'DocumentReference' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 405 | ||
| And the response has an empty body | ||
| And the Allow header is 'GET' | ||
| And the Content-Length header is '0' | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/json | | ||
| | application/json+fhir | | ||
| | application/fhir+json | | ||
|
|
||
| Scenario Outline: DocumentReference/{id} with HEAD fails (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When consumer 'RX898' sends HEAD request to 'DocumentReference/random-id' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 405 | ||
| And the response has an empty body | ||
| And the Allow header is 'GET' | ||
| And the Content-Length header is '0' | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/json | | ||
| | application/json+fhir | | ||
| | application/fhir+json | | ||
|
|
||
| Scenario Outline: DocumentReference with HEAD fails with 415 with unsupported (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When consumer 'RX898' sends HEAD request to 'DocumentReference' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 415 | ||
| And the Content-Type header is 'application/json' | ||
| And the Content-Length header is '0' | ||
| And the Allow header is not present | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/notsupported | | ||
| | application/helloworld | | ||
| | application/harold | | ||
|
|
||
| Scenario Outline: DocumentReference/{id} with HEAD fails (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When consumer 'RX898' sends HEAD request to 'DocumentReference/random-id' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 415 | ||
| And the response has an empty body | ||
| And the Content-Type header is 'application/json' | ||
| And the Content-Length header is '0' | ||
| And the Allow header is not present | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/notsupported | | ||
| | application/helloworld | | ||
| | application/harold | |
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,63 @@ | ||
| Feature: Producer - HEAD Requests | ||
|
|
||
| Scenario Outline: DocumentReference with HEAD fails (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When producer 'RX898' sends HEAD request to 'DocumentReference' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 405 | ||
| And the response has an empty body | ||
| And the Allow header is 'GET,POST' | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/json | | ||
| | application/json+fhir | | ||
| | application/fhir+json | | ||
|
|
||
| Scenario Outline: DocumentReference/{id} with HEAD fails (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When producer 'RX898' sends HEAD request to 'DocumentReference/random-id' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 405 | ||
| And the response has an empty body | ||
| And the Allow header is 'GET,PUT,DELETE' | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/json | | ||
| | application/json+fhir | | ||
| | application/fhir+json | | ||
|
|
||
| Scenario Outline: DocumentReference with HEAD fails with 415 with unsupported (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When producer 'RX898' sends HEAD request to 'DocumentReference' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 415 | ||
| And the Content-Type header is 'application/json' | ||
| And the response has an empty body | ||
| And the Allow header is not present | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/notsupported | | ||
| | application/helloworld | | ||
| | application/harold | | ||
|
|
||
| Scenario Outline: DocumentReference/{id} with HEAD fails with 415 with unsupported (Content-Type: <content_type>) | ||
| Given the application 'DataShare' (ID 'z00z-y11y-x22x') is registered to access the API | ||
| When producer 'RX898' sends HEAD request to 'DocumentReference/random-id' endpoint with headers: | ||
| | header | value | | ||
| | Content-Type | <content_type> | | ||
| Then the response status code is 415 | ||
| And the Content-Type header is 'application/json' | ||
| And the response has an empty body | ||
| And the Allow header is not present | ||
|
|
||
| Examples: | ||
| | content_type | | ||
| | application/notsupported | | ||
| | application/helloworld | | ||
| | application/harold | |
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
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.
Uh oh!
There was an error while loading. Please reload this page.