summaryrefslogtreecommitdiff
path: root/tests/unit/utils.py
diff options
context:
space:
mode:
authorAlistair Coles <alistair.coles@hp.com>2014-09-22 11:52:44 +0100
committerAlistair Coles <alistair.coles@hp.com>2014-09-24 18:19:12 +0100
commitf90d7f28e504be045e59b395aee0abc057417f8f (patch)
tree0c6e81ec791dcc5e9f80070717fcfbe78854c449 /tests/unit/utils.py
parent8f1b394325804c23ac18e7f9da6cb56a3b95eed2 (diff)
downloadpython-swiftclient-f90d7f28e504be045e59b395aee0abc057417f8f.tar.gz
Fix bug with some OS options not being passed to client
Fixes a regression that is preventing swiftclient from authenticating using keystone v3 options. swiftclient/shell.py processes the dict of command line options to set up a child dict ('os_options') of keystone auth specific options (line 960). The processing includes stripping --os- prefixes from the command line options before adding keys to os_options. A recent patch https://review.openstack.org/#/c/85453/ introduced a duplication of this option processing in service.py (line 79) which replaces the os_options created in shell.py, but omits keystone v3 related options. Consequently the keystone v3 options are not being passed to the client get_auth() method. This patch adds the keystone v3 related options to the option processing in service.py. For pragmatic reasons (i.e. fixing the bug quickly) the option processing code has not been removed from parse_args in shell.py. It is likely that the code in parse_args is now redundant, but all code paths between parse_args and process_options should be inspected and test coverage added before removing that code. Unit tests have been added in test_shell.py to verify that command line options are correctly passed to the client get_auth method. The MockHttpTest class is re-used in test_shell.py, so it is moved from test_swiftclient.py to tests/unit/utils.py Closes-bug: #1372465 Change-Id: I4fed013cdb8936509609d06093337cc147ade0d6
Diffstat (limited to 'tests/unit/utils.py')
-rw-r--r--tests/unit/utils.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/utils.py b/tests/unit/utils.py
index cb671cf..09b31c1 100644
--- a/tests/unit/utils.py
+++ b/tests/unit/utils.py
@@ -14,6 +14,9 @@
# limitations under the License.
from requests import RequestException
from time import sleep
+import testtools
+from six.moves import reload_module
+from swiftclient import client as c
def fake_get_auth_keystone(os_options, exc=None, **kwargs):
@@ -156,3 +159,54 @@ def fake_http_connect(*code_iter, **kwargs):
return fake_conn
return connect
+
+
+class MockHttpTest(testtools.TestCase):
+
+ def setUp(self):
+ super(MockHttpTest, self).setUp()
+
+ def fake_http_connection(*args, **kwargs):
+ _orig_http_connection = c.http_connection
+ return_read = kwargs.get('return_read')
+ query_string = kwargs.get('query_string')
+ storage_url = kwargs.get('storage_url')
+ auth_token = kwargs.get('auth_token')
+
+ def wrapper(url, proxy=None, cacert=None, insecure=False,
+ ssl_compression=True):
+ if storage_url:
+ self.assertEqual(storage_url, url)
+
+ parsed, _conn = _orig_http_connection(url, proxy=proxy)
+ conn = fake_http_connect(*args, **kwargs)()
+
+ def request(method, url, *args, **kwargs):
+ if auth_token:
+ headers = args[1]
+ self.assertTrue('X-Auth-Token' in headers)
+ actual_token = headers.get('X-Auth-Token')
+ self.assertEqual(auth_token, actual_token)
+ if query_string:
+ self.assertTrue(url.endswith('?' + query_string))
+ if url.endswith('invalid_cert') and not insecure:
+ from swiftclient import client as c
+ raise c.ClientException("invalid_certificate")
+ return
+ conn.request = request
+
+ conn.has_been_read = False
+ _orig_read = conn.read
+
+ def read(*args, **kwargs):
+ conn.has_been_read = True
+ return _orig_read(*args, **kwargs)
+ conn.read = return_read or read
+
+ return parsed, conn
+ return wrapper
+ self.fake_http_connection = fake_http_connection
+
+ def tearDown(self):
+ super(MockHttpTest, self).tearDown()
+ reload_module(c)