diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-09-14 20:45:43 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-09-14 20:45:43 +0000 |
commit | cacb3a3a1501a930a05b8494d6d1215fe96cf7af (patch) | |
tree | a7676ec77635b1bff0e7e2858dd6e048d3ee66d2 /tests | |
parent | 5eb0f3debc320340965460c04a1d6ca4f9c423a3 (diff) | |
parent | 4c955751d340a8f71a2eebdb3c58d90b36874a66 (diff) | |
download | python-swiftclient-cacb3a3a1501a930a05b8494d6d1215fe96cf7af.tar.gz |
Merge "Make tempurl command check for valid object path"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_shell.py | 16 | ||||
-rw-r--r-- | tests/unit/test_utils.py | 26 |
2 files changed, 40 insertions, 2 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 40881c2..3f077dc 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -1402,7 +1402,7 @@ class TestShell(unittest.TestCase): "secret_key"] swiftclient.shell.main(argv) temp_url.assert_called_with( - '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=False) + '/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): @@ -1410,7 +1410,7 @@ class TestShell(unittest.TestCase): "secret_key", "--absolute"] swiftclient.shell.main(argv) temp_url.assert_called_with( - '/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=True) + '/v1/AUTH_account/c/o', "60", 'secret_key', 'GET', absolute=True) def test_temp_url_output(self): argv = ["", "tempurl", "GET", "60", "/v1/a/c/o", @@ -1428,6 +1428,18 @@ class TestShell(unittest.TestCase): expected = "http://saio:8080%s" % expected self.assertEqual(expected, output.out) + def test_temp_url_error_output(self): + expected = 'path must be full path to an object e.g. /v1/a/c/o\n' + for bad_path in ('/v1/a/c', 'v1/a/c/o', '/v1/a/c/', '/v1/a//o', + 'http://saio/v1/a/c', 'http://v1/a/c/o'): + argv = ["", "tempurl", "GET", "60", bad_path, + "secret_key", "--absolute"] + with CaptureOutput(suppress_systemexit=True) as output: + swiftclient.shell.main(argv) + self.assertEqual(expected, output.err, + 'Expected %r but got %r for path %r' % + (expected, output.err, bad_path)) + @mock.patch('swiftclient.service.Connection') def test_capabilities(self, connection): argv = ["", "capabilities"] diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 949c3e1..d2f6494 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -180,6 +180,32 @@ class TestTempURL(unittest.TestCase): self.assertEqual(exc_manager.exception.args[0], 'seconds must be a positive integer') + def test_generate_temp_url_bad_path(self): + with self.assertRaises(ValueError) as exc_manager: + u.generate_temp_url('/v1/a/c', 60, self.key, self.method) + 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/o', 60, self.key, self.method) + 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('blah/v1/a/c/o', 60, self.key, self.method) + 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//c/o', 60, self.key, self.method) + 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) + self.assertEqual(exc_manager.exception.args[0], + 'path must be full path to an object e.g. /v1/a/c/o') + class TestTempURLUnicodePathAndKey(TestTempURL): url = u'/v1/\u00e4/c/\u00f3' |