s3api: Make quota-exceeded errors more obvious

Change-Id: Ia8db40227343e9c4555267c62072a1c9bfc28c66
Closes-Bug: #1893811
This commit is contained in:
Tim Burke 2020-09-01 12:43:03 -07:00
parent 4fefdf4d83
commit f8a9a6e116
2 changed files with 27 additions and 0 deletions

View File

@ -1380,6 +1380,8 @@ class S3Request(swob.Request):
error_codes[sw_resp.status_int] # pylint: disable-msg=E1101
if isinstance(err_resp, tuple):
raise err_resp[0](*err_resp[1:])
elif b'quota' in err_msg:
raise err_resp(err_msg)
else:
raise err_resp()

View File

@ -600,6 +600,31 @@ class TestS3ApiObj(S3ApiTestCase):
# Check that s3api converts a Content-MD5 header into an etag.
self.assertEqual(headers['etag'], etag)
@s3acl
def test_object_PUT_quota_exceeded(self):
etag = self.response_headers['etag']
content_md5 = binascii.b2a_base64(binascii.a2b_hex(etag)).strip()
if not six.PY2:
content_md5 = content_md5.decode('ascii')
self.swift.register(
'PUT', '/v1/AUTH_test/bucket/object',
swob.HTTPRequestEntityTooLarge, {}, 'Upload exceeds quota.')
req = Request.blank(
'/bucket/object',
environ={'REQUEST_METHOD': 'PUT'},
headers={'Authorization': 'AWS test:tester:hmac',
'x-amz-storage-class': 'STANDARD',
'Content-MD5': content_md5,
'Date': self.get_date_header()},
body=self.object_body)
req.date = datetime.now()
req.content_type = 'text/plain'
status, headers, body = self.call_s3api(req)
self.assertEqual(status.split()[0], '400')
self.assertIn(b'<Code>EntityTooLarge</Code>', body)
self.assertIn(b'<Message>Upload exceeds quota.</Message', body)
@s3acl
def test_object_PUT_v4(self):
body_sha = hashlib.sha256(self.object_body).hexdigest()