diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index abae83fed..d1ba5b6dd 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -11,6 +11,7 @@ from .exceptions import ( ) MAXIMUM_VISIBILTY_TIMEOUT = 43200 +MAXIMUM_MESSAGE_LENGTH = 262144 # 256 KiB DEFAULT_RECEIVED_MESSAGES = 1 SQS_REGION_REGEX = r'://(.+?)\.queue\.amazonaws\.com' @@ -106,6 +107,9 @@ class SQSResponse(BaseResponse): message = self.querystring.get("MessageBody")[0] delay_seconds = self.querystring.get('DelaySeconds') + if len(message) > MAXIMUM_MESSAGE_LENGTH: + return ERROR_TOO_LONG_RESPONSE, dict(status=400) + if delay_seconds: delay_seconds = int(delay_seconds[0]) else: @@ -417,3 +421,13 @@ PURGE_QUEUE_RESPONSE = """ """ + +ERROR_TOO_LONG_RESPONSE = """ + + Sender + InvalidParameterValue + One or more parameters are invalid. Reason: Message must be shorter than 262144 bytes. + + + 6fde8d1e-52cd-4581-8cd9-c512f4c64223 +""" diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index a23545dcc..1e300fa57 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -170,6 +170,18 @@ def test_send_message_with_delay(): queue.count().should.equal(0) +@mock_sqs +def test_send_large_message_fails(): + conn = boto.connect_sqs('the_key', 'the_secret') + queue = conn.create_queue("test-queue", visibility_timeout=60) + queue.set_message_class(RawMessage) + + body_one = 'test message' * 200000 + huge_message = queue.new_message(body_one) + + queue.write.when.called_with(huge_message).should.throw(SQSError) + + @mock_sqs def test_message_becomes_inflight_when_received(): conn = boto.connect_sqs('the_key', 'the_secret')