From 55ab08a5fadda87ffc904d9fe0ba1d1e09612ae3 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Thu, 2 Jan 2020 16:21:19 -0800 Subject: [PATCH] account-server: Add test for leading delimiter Related-Change: I27701a31bfa22842c272b7781738e8c546b82cbc Related-Change: If912f71d8b0d03369680374e8233da85d8d38f85 Change-Id: I0c850b8ae40d1ab477d0f5d18f92579c457da54e Related-Bug: 1475018 --- test/unit/account/test_server.py | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index c1168a852f..d25d494598 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -1710,6 +1710,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={