Fix 500 error when no DisplayName in request body.

The original data of body from client to set acl like below:

<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Owner>
    <ID>test:tester</ID>
    <DisplayName>test:tester</DisplayName>
  </Owner>
  <AccessControlList>
    ...
  </AccessControlList>
</AccessControlPolicy>

If the attribute "<DisplayName>" isn't exist, proxy will return
500 Internal Server Error.

Change-Id: Ia02af110109d5ecbcda05f707707b30e604af8f0
Closes-Bug: #1400367
This commit is contained in:
Charles Hsu
2014-12-09 11:14:25 +08:00
parent 8e1e7152f9
commit 1717bfc9cc
2 changed files with 21 additions and 1 deletions

View File

@@ -412,7 +412,11 @@ class ACL(object):
Convert an ElementTree to an ACL instance
"""
id = elem.find('./Owner/ID').text
name = elem.find('./Owner/DisplayName').text
try:
name = elem.find('./Owner/DisplayName').text
except AttributeError:
name = id
grants = [Grant.from_elem(e)
for e in elem.findall('./AccessControlList/Grant')]
return cls(Owner(id, name), grants)

View File

@@ -182,6 +182,22 @@ class TestSwift3Subresource(unittest.TestCase):
self.assertFalse(self.check_permission(acl, 'test:tester2',
'WRITE_ACP'))
def test_acl_from_elem_by_id_only(self):
elem = ACLPrivate(Owner(id='test:tester',
name='test:tester')).elem()
elem.find('./Owner').remove(elem.find('./Owner/DisplayName'))
acl = ACL.from_elem(elem)
self.assertTrue(self.check_permission(acl, 'test:tester', 'READ'))
self.assertTrue(self.check_permission(acl, 'test:tester', 'WRITE'))
self.assertTrue(self.check_permission(acl, 'test:tester', 'READ_ACP'))
self.assertTrue(self.check_permission(acl, 'test:tester', 'WRITE_ACP'))
self.assertFalse(self.check_permission(acl, 'test:tester2', 'READ'))
self.assertFalse(self.check_permission(acl, 'test:tester2', 'WRITE'))
self.assertFalse(self.check_permission(acl, 'test:tester2',
'READ_ACP'))
self.assertFalse(self.check_permission(acl, 'test:tester2',
'WRITE_ACP'))
def test_decode_acl_container(self):
access_control_policy = \
{'Owner': 'test:tester',