summaryrefslogtreecommitdiff
path: root/tests/unit/test_utils.py
diff options
context:
space:
mode:
authorChristopher Bartz <bartz@dkrz.de>2016-12-08 13:42:35 +0100
committerChristopher Bartz <bartz@dkrz.de>2017-01-19 16:34:26 +0100
commit3934bd606acc2333ee9ae63a40baa35928ef908d (patch)
tree1181d58436365ce6d9863866c112f78e6677a081 /tests/unit/test_utils.py
parentaea0585ddbc749b6f4d501430d41b671932c11a4 (diff)
downloadpython-swiftclient-3934bd606acc2333ee9ae63a40baa35928ef908d.tar.gz
prefix-based tempurls support
Implements client-side functionality for prefix-based tempurls. Please see: https://review.openstack.org/#/c/274048/ Change-Id: I8d7701daee888ed1120271a96c0660b01543ca2d
Diffstat (limited to 'tests/unit/test_utils.py')
-rw-r--r--tests/unit/test_utils.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 787f645..cbea8d8 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -150,6 +150,35 @@ class TestTempURL(unittest.TestCase):
])
self.assertIsInstance(url, type(self.url))
+ @mock.patch('hmac.HMAC')
+ @mock.patch('time.time', return_value=1400000000)
+ def test_generate_temp_url_prefix(self, time_mock, hmac_mock):
+ hmac_mock().hexdigest.return_value = 'temp_url_signature'
+ prefixes = ['', 'o', 'p0/p1/']
+ for p in prefixes:
+ hmac_mock.reset_mock()
+ path = '/v1/AUTH_account/c/' + p
+ expected_url = path + ('?temp_url_sig=temp_url_signature'
+ '&temp_url_expires=1400003600'
+ '&temp_url_prefix=' + p)
+ expected_body = '\n'.join([
+ self.method,
+ '1400003600',
+ 'prefix:' + path,
+ ]).encode('utf-8')
+ url = u.generate_temp_url(path, self.seconds,
+ self.key, self.method, prefix=True)
+ key = self.key
+ if not isinstance(key, six.binary_type):
+ key = key.encode('utf-8')
+ self.assertEqual(url, expected_url)
+ self.assertEqual(hmac_mock.mock_calls, [
+ mock.call(key, expected_body, sha1),
+ mock.call().hexdigest(),
+ ])
+
+ self.assertIsInstance(url, type(path))
+
def test_generate_temp_url_invalid_path(self):
with self.assertRaises(ValueError) as exc_manager:
u.generate_temp_url(b'/v1/a/c/\xff', self.seconds, self.key,
@@ -221,6 +250,12 @@ class TestTempURL(unittest.TestCase):
self.assertEqual(exc_manager.exception.args[0],
'path must be full path to an object e.g. /v1/a/c/o')
+ with self.assertRaises(ValueError) as exc_manager:
+ u.generate_temp_url('/v1/a/c', 60, self.key, self.method,
+ prefix=True)
+ self.assertEqual(exc_manager.exception.args[0],
+ 'path must at least contain /v1/a/c/')
+
class TestTempURLUnicodePathAndKey(TestTempURL):
url = u'/v1/\u00e4/c/\u00f3'