summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorZack M. Davis <zdavis@swiftstack.com>2015-09-04 14:57:30 -0700
committerZack M. Davis <zdavis@swiftstack.com>2015-09-04 14:57:30 -0700
commit52d39bebc11979fa1be5090ff75466710638e561 (patch)
treef700b14751375eadd84f2688a73f1e930a24930d /tests/unit
parent93666bb84abc1edc36fbb3ef5ec194cf774e4826 (diff)
downloadpython-swiftclient-52d39bebc11979fa1be5090ff75466710638e561.tar.gz
absolute expiry option for tempURL generation
The `tempurl` subcommand's second positional argument is called `seconds` and has heretofore interpreted as the number of seconds for which the tempURL should be valid, counting from the moment of running the command. This is indeed a common, if not the most common, use-case. But some users, occasionally, might want to generate a tempURL that expires at some particular ("absolute") time, rather than a particular amount of time relative to the moment of happening to run the command. (One might make an analogy to the way in which Swift's expiring object support supports an `X-Delete-At` header in addition to `X-Delete-After`—and it's the former that must be regarded as ontologically prior.) Thus, this commit adds an `--absolute` optional argument to the `tempurl` subcommand; if present, the `seconds` argument will be interpreted as a Unix timestamp of when the tempURL should be expire, rather than a duration for which the tempURL should be valid starting from "now". Change-Id: If9ded96f2799800958d5063127f3de812f50ef06
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_shell.py16
-rw-r--r--tests/unit/test_utils.py15
2 files changed, 22 insertions, 9 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index 12ceadb..e2b87d0 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -922,15 +922,21 @@ class TestShell(unittest.TestCase):
self.assertTrue(output.err != '')
self.assertTrue(output.err.startswith('Usage'))
- @mock.patch('swiftclient.shell.generate_temp_url')
+ @mock.patch('swiftclient.shell.generate_temp_url', return_value='')
def test_temp_url(self, temp_url):
argv = ["", "tempurl", "GET", "60", "/v1/AUTH_account/c/o",
- "secret_key"
- ]
- temp_url.return_value = ""
+ "secret_key"]
+ swiftclient.shell.main(argv)
+ temp_url.assert_called_with(
+ '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=False)
+
+ @mock.patch('swiftclient.shell.generate_temp_url', return_value='')
+ def test_absolute_expiry_temp_url(self, temp_url):
+ argv = ["", "tempurl", "GET", "60", "/v1/AUTH_account/c/o",
+ "secret_key", "--absolute"]
swiftclient.shell.main(argv)
temp_url.assert_called_with(
- '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET')
+ '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=True)
@mock.patch('swiftclient.service.Connection')
def test_capabilities(self, connection):
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index ca3531e..7d7f6b6 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -132,11 +132,9 @@ class TestTempURL(testtools.TestCase):
self.key = 'correcthorsebatterystaple'
self.method = 'GET'
- @mock.patch('hmac.HMAC.hexdigest')
- @mock.patch('time.time')
+ @mock.patch('hmac.HMAC.hexdigest', return_value='temp_url_signature')
+ @mock.patch('time.time', return_value=1400000000)
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&'
@@ -145,6 +143,15 @@ class TestTempURL(testtools.TestCase):
self.method)
self.assertEqual(url, expected_url)
+ @mock.patch('hmac.HMAC.hexdigest', return_value="temp_url_signature")
+ def test_generate_absolute_expiry_temp_url(self, hmac_mock):
+ expected_url = ('/v1/AUTH_account/c/o?'
+ 'temp_url_sig=temp_url_signature&'
+ 'temp_url_expires=2146636800')
+ url = u.generate_temp_url(self.url, 2146636800, self.key, self.method,
+ absolute=True)
+ self.assertEqual(url, expected_url)
+
def test_generate_temp_url_bad_seconds(self):
self.assertRaises(TypeError,
u.generate_temp_url,