Merge "s3api: Make grentee types case insensitive"

This commit is contained in:
Zuul 2022-06-21 19:21:48 +00:00 committed by Gerrit Code Review
commit 7d57539e91
2 changed files with 17 additions and 5 deletions

View File

@ -182,18 +182,19 @@ class Grantee(object):
"""
Convert a grantee string in the HTTP header to an Grantee instance.
"""
type, value = grantee.split('=', 1)
grantee_type, value = grantee.split('=', 1)
grantee_type = grantee_type.lower()
value = value.strip('"\'')
if type == 'id':
if grantee_type == 'id':
return User(value)
elif type == 'emailAddress':
elif grantee_type == 'emailaddress':
raise S3NotImplemented()
elif type == 'uri':
elif grantee_type == 'uri':
# return a subclass instance of Group class
subclass = get_group_subclass_from_uri(value)
return subclass()
else:
raise InvalidArgument(type, value,
raise InvalidArgument(grantee_type, value,
'Argument format not recognized')

View File

@ -379,6 +379,17 @@ class TestS3ApiS3Acl(S3ApiTestCase):
status, headers, body = self.call_s3api(req)
self.assertEqual(status.split()[0], '200')
def test_grant_all_users_with_uppercase_type(self):
req = Request.blank('/bucket/object?acl',
environ={'REQUEST_METHOD': 'PUT'},
headers={'Authorization': 'AWS test:tester:hmac',
'Date': self.get_date_header(),
'x-amz-grant-read':
'URI="http://acs.amazonaws.com/groups/'
'global/AllUsers"'})
status, headers, body = self.call_s3api(req)
self.assertEqual(status.split()[0], '200')
def test_grant_invalid_uri(self):
req = Request.blank('/bucket/object?acl',
environ={'REQUEST_METHOD': 'PUT'},