s3api: Make the 'Quiet' key value case insensitive

When deleting multiple objects, S3 allows to enable
a quiet mode with the 'Quiet' key.

At AWS S3, the value of this key is case-insensitive.
- Quiet mode is enabled if the value is 'true'
  (regardless of case).
- Otherwise, in all other cases (even a non-boolean value),
  this mode will be disabled.

Also, some tools (like Minio's python API) send the value 'True'
(and not 'true').

Change-Id: Id9d1da2017b8d13242ae1f410347febb013e9ce1
This commit is contained in:
Aymeric Ducroquetz 2022-03-23 17:48:51 +01:00
parent 0651d8175d
commit fd2dd11562
4 changed files with 23 additions and 24 deletions

View File

@ -1,6 +1,6 @@
start =
element Delete {
element Quiet { xsd:boolean }? &
element Quiet { xsd:string }? &
element Object {
element Key { xsd:string } &
element VersionId { xsd:string }?

View File

@ -81,10 +81,7 @@ class MultiObjectDeleteController(Controller):
elem = fromstring(xml, 'Delete', self.logger)
quiet = elem.find('./Quiet')
if quiet is not None and quiet.text.lower() == 'true':
self.quiet = True
else:
self.quiet = False
self.quiet = quiet is not None and quiet.text.lower() == 'true'
delete_list = list(object_key_iter(elem))
if len(delete_list) > self.conf.max_multi_delete_objects:

View File

@ -5,7 +5,7 @@
<interleave>
<optional>
<element name="Quiet">
<data type="boolean"/>
<data type="string"/>
</element>
</optional>
<oneOrMore>

View File

@ -249,26 +249,28 @@ class TestS3ApiMultiDelete(S3ApiTestCase):
self.swift.register('DELETE', '/v1/AUTH_test/bucket/Key2',
swob.HTTPNotFound, {}, None)
elem = Element('Delete')
SubElement(elem, 'Quiet').text = 'true'
for key in ['Key1', 'Key2']:
obj = SubElement(elem, 'Object')
SubElement(obj, 'Key').text = key
body = tostring(elem, use_s3ns=False)
content_md5 = base64.b64encode(
md5(body, usedforsecurity=False).digest()).strip()
for true_value in ('true', 'True', 'TRUE', 'trUE'):
elem = Element('Delete')
SubElement(elem, 'Quiet').text = true_value
for key in ['Key1', 'Key2']:
obj = SubElement(elem, 'Object')
SubElement(obj, 'Key').text = key
body = tostring(elem, use_s3ns=False)
content_md5 = base64.b64encode(
md5(body, usedforsecurity=False).digest()).strip()
req = Request.blank('/bucket?delete',
environ={'REQUEST_METHOD': 'POST'},
headers={'Authorization': 'AWS test:tester:hmac',
'Date': self.get_date_header(),
'Content-MD5': content_md5},
body=body)
status, headers, body = self.call_s3api(req)
self.assertEqual(status.split()[0], '200')
req = Request.blank('/bucket?delete',
environ={'REQUEST_METHOD': 'POST'},
headers={
'Authorization': 'AWS test:tester:hmac',
'Date': self.get_date_header(),
'Content-MD5': content_md5},
body=body)
status, headers, body = self.call_s3api(req)
self.assertEqual(status.split()[0], '200')
elem = fromstring(body)
self.assertEqual(len(elem.findall('Deleted')), 0)
elem = fromstring(body)
self.assertEqual(len(elem.findall('Deleted')), 0)
@s3acl
def test_object_multi_DELETE_no_key(self):