summaryrefslogtreecommitdiff
path: root/tests
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
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')
-rw-r--r--tests/unit/test_shell.py11
-rw-r--r--tests/unit/test_utils.py39
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index 0c28297..33cc91a 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -22,6 +22,7 @@ import six
import swiftclient
import swiftclient.shell
+import swiftclient.utils
if six.PY2:
@@ -328,6 +329,16 @@ class TestShell(unittest.TestCase):
'Content-Type': 'text/plain',
'X-Object-Meta-Color': 'Blue'})
+ @mock.patch('swiftclient.shell.generate_temp_url')
+ def test_temp_url(self, temp_url):
+ argv = ["", "tempurl", "GET", "60", "/v1/AUTH_account/c/o",
+ "secret_key"
+ ]
+ temp_url.return_value = ""
+ swiftclient.shell.main(argv)
+ temp_url.assert_called_with(
+ '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET')
+
@mock.patch('swiftclient.shell.Connection')
def test_capabilities(self, connection):
argv = ["", "capabilities"]
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):