Merge pull request #452 from iandees/add_sqs_max_size
Check SQS message size
This commit is contained in:
commit
a8115a4510
@ -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 = """<PurgeQueueResponse>
|
||||
</RequestId>
|
||||
</ResponseMetadata>
|
||||
</PurgeQueueResponse>"""
|
||||
|
||||
ERROR_TOO_LONG_RESPONSE = """<ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
|
||||
<Error>
|
||||
<Type>Sender</Type>
|
||||
<Code>InvalidParameterValue</Code>
|
||||
<Message>One or more parameters are invalid. Reason: Message must be shorter than 262144 bytes.</Message>
|
||||
<Detail/>
|
||||
</Error>
|
||||
<RequestId>6fde8d1e-52cd-4581-8cd9-c512f4c64223</RequestId>
|
||||
</ErrorResponse>"""
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user