Skip to content

Commit

Permalink
fix(start-lambda): Remove Content-Type Header check (aws#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmdayn authored and jfuss committed Aug 6, 2018
1 parent 2e9b839 commit b7c3d89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 34 deletions.
4 changes: 0 additions & 4 deletions samcli/local/lambda_service/local_lambda_invoke_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ def validate_request():
LOG.debug("Query parameters are in the request but not supported")
return LambdaErrorResponses.invalid_request_content("Query Parameters are not supported")

if flask_request.content_type and flask_request.content_type.lower() != "application/json":
LOG.debug("%s media type is not supported. Must be application/json", flask_request.content_type)
return LambdaErrorResponses.unsupported_media_type(flask_request.content_type)

request_headers = CaseInsensitiveDict(flask_request.headers)

log_type = request_headers.get('X-Amz-Log-Type', 'None')
Expand Down
23 changes: 10 additions & 13 deletions tests/functional/local/lambda_service/test_local_lambda_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ def test_mock_response_is_returned(self):
self.assertEquals(actual, expected)
self.assertEquals(response.status_code, 200)

def test_binary_octet_stream_format(self):
expected = {"key1": "value1"}

response = requests.post(self.url + '/2015-03-31/functions/HelloWorld/invocations', json={"key1": "value1"}, headers={"Content-Type":"binary/octet-stream"})

actual = response.json()

self.assertEquals(actual, expected)
self.assertEquals(response.status_code, 200)

def test_function_executed_when_no_data_provided(self):
expected = {}

Expand Down Expand Up @@ -273,19 +283,6 @@ def test_invocation_type_dry_run_in_request(self):
self.assertEquals(response.headers.get('Content-Type'), 'application/json')
self.assertEquals(response.headers.get('x-amzn-errortype'), 'NotImplemented')

def test_media_type_is_not_application_json(self):
expected = {"Type": "User",
"Message": 'Unsupported content type: image/gif'}

response = requests.post(self.url + '/2015-03-31/functions/HelloWorld/invocations', headers={'Content-Type':'image/gif'})

actual = response.json()

self.assertEquals(actual, expected)
self.assertEquals(response.status_code, 415)
self.assertEquals(response.headers.get('x-amzn-errortype'), 'UnsupportedMediaType')
self.assertEquals(response.headers.get('Content-Type'), 'application/json')

def test_generic_404_error_when_request_to_nonexisting_endpoint(self):
expected_data = {'Type': 'LocalService', 'Message': 'PathNotFoundException'}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,6 @@ def test_request_with_query_strings(self, flask_request, lambda_error_responses_
lambda_error_responses_mock.invalid_request_content.assert_called_once_with(
"Query Parameters are not supported")

@patch('samcli.local.lambda_service.local_lambda_invoke_service.LambdaErrorResponses')
@patch('samcli.local.lambda_service.local_lambda_invoke_service.request')
def test_request_with_content_type_not_application_json(self, flask_request, lambda_error_responses_mock):
flask_request.get_data.return_value = None
flask_request.headers = {}
flask_request.content_type = 'image/gif'
flask_request.args = {}

lambda_error_responses_mock.unsupported_media_type.return_value = "UnsupportedMediaType"

response = LocalLambdaInvokeService.validate_request()

self.assertEquals(response, "UnsupportedMediaType")

lambda_error_responses_mock.unsupported_media_type.assert_called_once_with(
"image/gif")

@patch('samcli.local.lambda_service.local_lambda_invoke_service.LambdaErrorResponses')
@patch('samcli.local.lambda_service.local_lambda_invoke_service.request')
def test_request_log_type_not_None(self, flask_request, lambda_error_responses_mock):
Expand Down

0 comments on commit b7c3d89

Please sign in to comment.