Browse Source

account-server: Correctly handle containers starting with delimiter

Related-Change: I27701a31bfa22842c272b7781738e8c546b82cbc
Related-Change: If912f71d8b0d03369680374e8233da85d8d38f85
Change-Id: I0c850b8ae40d1ab477d0f5d18f92579c457da54e
Related-Bug: 1475018
changes/65/700965/1
Tim Burke 6 months ago
parent
commit
d1d0b706e4
2 changed files with 52 additions and 1 deletions
  1. +1
    -1
      swift/account/backend.py
  2. +51
    -0
      test/unit/account/test_server.py

+ 1
- 1
swift/account/backend.py View File

@@ -455,7 +455,7 @@ class AccountBroker(DatabaseBroker):
curs.close()
return results
end = name.find(delimiter, len(prefix))
if end > 0:
if end >= 0:
if reverse:
end_marker = name[:end + len(delimiter)]
else:


+ 51
- 0
test/unit/account/test_server.py View File

@@ -1648,6 +1648,57 @@ class TestAccountController(unittest.TestCase):
listing.append(node2.firstChild.nodeValue)
self.assertEqual(listing, ['sub.1.0', 'sub.1.1', 'sub.1.2'])

def test_GET_leading_delimiter(self):
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '0'})
resp = req.get_response(self.controller)
for first in range(3):
req = Request.blank(
'/sda1/p/a/.sub.%s' % first,
environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0',
'X-Object-Count': '0',
'X-Bytes-Used': '0',
'X-Timestamp': normalize_timestamp(0)})
req.get_response(self.controller)
for second in range(3):
req = Request.blank(
'/sda1/p/a/.sub.%s.%s' % (first, second),
environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0',
'X-Object-Count': '0',
'X-Bytes-Used': '0',
'X-Timestamp': normalize_timestamp(0)})
req.get_response(self.controller)
req = Request.blank('/sda1/p/a?delimiter=.',
environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 200)
self.assertEqual(resp.body.strip().split(b'\n'),
[b'.'])
req = Request.blank('/sda1/p/a?prefix=.&delimiter=.',
environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 200)
self.assertEqual(resp.body.strip().split(b'\n'),
[b'.sub.'])
req = Request.blank('/sda1/p/a?prefix=.sub.&delimiter=.',
environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 200)
self.assertEqual(
resp.body.strip().split(b'\n'),
[b'.sub.0', b'.sub.0.', b'.sub.1', b'.sub.1.',
b'.sub.2', b'.sub.2.'])
req = Request.blank('/sda1/p/a?prefix=.sub.1.&delimiter=.',
environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller)
self.assertEqual(resp.status_int, 200)
self.assertEqual(resp.body.strip().split(b'\n'),
[b'.sub.1.0', b'.sub.1.1', b'.sub.1.2'])

def test_GET_multichar_delimiter(self):
self.maxDiff = None
req = Request.blank('/sda1/p/a', method='PUT', headers={


Loading…
Cancel
Save