Skip to content

Commit

Permalink
test/alternator: better tests of oversized requests
Browse files Browse the repository at this point in the history
Like DynamoDB, Alternator rejects requests larger than some fixed maximum
size (16MB). We had a test for this feature - test_too_large_request,
but it was too blunt, and missed two issues:

Refs #8195
Refs #8196

So this patch adds two better tests that reproduce these two issues:

First, test_too_large_request_chunked verifies that an oversized request
is detected even if the body is sent with chunked encoding.

Second, both tests - test_too_large_request_chunked and
test_too_large_request_content_length - verify that the rather limited
(and arguably buggy) Python HTTP client is able to read the 413 status
code - and doesn't report some generic I/O error.

Both tests pass on DynamoDB, but fail on Alternator because of these two
open issues.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20210302154555.1488812-1-nyh@scylladb.com>
  • Loading branch information
nyh authored and psarna committed Mar 2, 2021
1 parent 812bb67 commit bb2ad9d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/alternator/test_manual_requests.py
Expand Up @@ -106,6 +106,38 @@ def test_too_large_request(dynamodb, test_table):
except ClientError:
raise BotoCoreError()

# Tests that a request larger than the 16MB limit is rejected, improving on
# the rather blunt test in test_too_large_request() above. The following two
# tests verify that:
# 1. An over-long request is rejected no matter if it is sent using a
# Content-Length header or chunked encoding (reproduces issue #8196).
# 2. The client should be able to recognize this error as a 413 error, not
# some I/O error like broken pipe (reproduces issue #8195).
@pytest.mark.xfail(reason="issue #8195, #8196")
def test_too_large_request_chunked(dynamodb, test_table):
# To make a request very large, we just stuff it with a lot of spaces :-)
spaces = ' ' * (17 * 1024 * 1024)
req = get_signed_request(dynamodb, 'PutItem',
'{"TableName": "' + test_table.name + '", ' + spaces + '"Item": {"p": {"S": "x"}, "c": {"S": "x"}}}')
def generator(s):
yield s
response = requests.post(req.url, headers=req.headers, data=generator(req.body), verify=False)
# In issue #8196, Alternator did not recognize the request is too long
# because it uses chunked encoding instead of Content-Length, so the
# request succeeded, and the status_code was 200 instead of 413.
assert response.status_code == 413

@pytest.mark.xfail(reason="issue #8195")
def test_too_large_request_content_length(dynamodb, test_table):
spaces = ' ' * (17 * 1024 * 1024)
req = get_signed_request(dynamodb, 'PutItem',
'{"TableName": "' + test_table.name + '", ' + spaces + '"Item": {"p": {"S": "x"}, "c": {"S": "x"}}}')
response = requests.post(req.url, headers=req.headers, data=req.body, verify=False)
# In issue #8195, Alternator closed the connection early, causing the
# library to throw an exception (Broken Pipe) instead noticing the error
# code 413 which the server did send.
assert response.status_code == 413

def test_incorrect_json(dynamodb, test_table):
correct_req = '{"TableName": "' + test_table.name + '", "Item": {"p": {"S": "x"}, "c": {"S": "x"}}}'

Expand Down

0 comments on commit bb2ad9d

Please sign in to comment.