summaryrefslogtreecommitdiff
path: root/tests/unit/test_utils.py
diff options
context:
space:
mode:
authorJosh Gachnang <josh@pcsforeducation.com>2014-06-25 13:28:42 -0700
committerJosh Gachnang <josh@pcsforeducation.com>2014-07-11 13:05:22 -0700
commitdef0e0a6435deee5c55b7859e1b132590ea0860c (patch)
treeb4c458bab09104a47925edde2d794e6a5ebc48ea /tests/unit/test_utils.py
parent3d0de79e26e2aa6285742c60aca3c164e9c2fbb9 (diff)
downloadpython-swiftclient-def0e0a6435deee5c55b7859e1b132590ea0860c.tar.gz
Adding Swift Temporary URL support
Temporary URLs allow a user to sign an object URL with a shared secret to so that the object can be downloaded without auth for a specified amount of time. http://docs.openstack.org/trunk/config-reference/content/object-storage-tempurl.html Change-Id: Ife0b6c98c975e074d4dad0a31145573b784747c5
Diffstat (limited to 'tests/unit/test_utils.py')
-rw-r--r--tests/unit/test_utils.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index d9d74c5..f072aed 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -15,6 +15,7 @@
import testtools
+import mock
import six
import tempfile
@@ -122,6 +123,44 @@ class TestPrtBytes(testtools.TestCase):
self.assertEqual('1024Y', u.prt_bytes(bytes_, True).lstrip())
+class TestTempURL(testtools.TestCase):
+
+ def setUp(self):
+ super(TestTempURL, self).setUp()
+ self.url = '/v1/AUTH_account/c/o'
+ self.seconds = 3600
+ self.key = 'correcthorsebatterystaple'
+ self.method = 'GET'
+
+ @mock.patch('hmac.HMAC.hexdigest')
+ @mock.patch('time.time')
+ def test_generate_temp_url(self, time_mock, hmac_mock):
+ time_mock.return_value = 1400000000
+ hmac_mock.return_value = 'temp_url_signature'
+ expected_url = (
+ '/v1/AUTH_account/c/o?'
+ 'temp_url_sig=temp_url_signature&'
+ 'temp_url_expires=1400003600')
+ url = u.generate_temp_url(self.url, self.seconds, self.key,
+ self.method)
+ self.assertEqual(url, expected_url)
+
+ def test_generate_temp_url_bad_seconds(self):
+ self.assertRaises(TypeError,
+ u.generate_temp_url,
+ self.url,
+ 'not_an_int',
+ self.key,
+ self.method)
+
+ self.assertRaises(ValueError,
+ u.generate_temp_url,
+ self.url,
+ -1,
+ self.key,
+ self.method)
+
+
class TestLengthWrapper(testtools.TestCase):
def test_stringio(self):