def test_arn_partition_rewriting_in_response_without_region_and_with_default_region( encoding, switch_region): with switch_region("us-gov-east-1"): listener = ArnPartitionRewriteListener() response = Response() response._content = encoding( json.dumps( {"some-data-with-arn": "arn:aws:iam::123456789012:ArnInData"})) response._status_code = 200 response.headers = { "some-header-with-arn": "arn:aws:iam::123456789012:ArnInHeader" } result = listener.return_response(method="POST", path="/", data="ignored", headers={}, response=response) assert result.status_code == response.status_code assert result.headers == { "some-header-with-arn": "arn:aws-us-gov:iam::123456789012:ArnInHeader" } assert result.content == encoding( json.dumps({ "some-data-with-arn": "arn:aws-us-gov:iam::123456789012:ArnInData" }))
def test_arn_partition_rewriting_in_response(encoding): listener = ArnPartitionRewriteListener() response = Response() response._content = encoding( json.dumps( {"some-data-with-arn": "arn:aws:apigateway:us-gov-west-1::/restapis/arn-in-body/*"} ) ) response._status_code = 200 response.headers = { "some-header-with-arn": "arn:aws:apigateway:us-gov-west-1::/restapis/arn-in-header/*" } result = listener.return_response( method="POST", path="/", data="ignored", headers={}, response=response ) assert result.status_code == response.status_code assert result.headers == { "some-header-with-arn": "arn:aws-us-gov:apigateway:us-gov-west-1::/restapis/arn-in-header/*" } assert result.content == encoding( json.dumps( { "some-data-with-arn": "arn:aws-us-gov:apigateway:us-gov-west-1::/restapis/arn-in-body/*" } ) )
def test_no_arn_partition_rewriting_in_internal_response(): """Partitions should not be rewritten for _responses_ of _internal_ requests.""" listener = ArnPartitionRewriteListener() response = Response() body_content = json.dumps({ "some-data-with-arn": "arn:aws:apigateway:us-gov-west-1::/restapis/arn-in-body/*" }) response._content = body_content response._status_code = 200 response_header_content = { "some-header-with-arn": "arn:aws:apigateway:us-gov-west-1::/restapis/arn-in-header/*" } response.headers = response_header_content # mimic an internal request request_headers = mock_aws_request_headers( region_name="us-gov-west-1", access_key=INTERNAL_AWS_ACCESS_KEY_ID) result = listener.return_response(method="POST", path="/", data="ignored", headers=request_headers, response=response) assert result is None