diff options
author | anc <alistair.coles@hp.com> | 2014-05-20 13:35:03 +0100 |
---|---|---|
committer | anc <alistair.coles@hp.com> | 2014-06-05 18:02:52 +0100 |
commit | 916f5cbd61eac86527b7a9b867ea1ddb3c84cdf5 (patch) | |
tree | 5499d9c4101e6650df8063d4c96f28470807bfaf | |
parent | 3d0de79e26e2aa6285742c60aca3c164e9c2fbb9 (diff) | |
download | python-swiftclient-916f5cbd61eac86527b7a9b867ea1ddb3c84cdf5.tar.gz |
Relax requirement for tenant_name in get_auth()
get_auth() in client.py raises an exception if
tenant_name is not included in the os_options
dict. This is overly constrained since tenant_id
is equally sufficient. This patch modifies
get_auth to require either tenant_name
or tenant_id.
Change-Id: Ibbcda1704637eb887efa5895579d260a1e072327
-rw-r--r-- | swiftclient/client.py | 2 | ||||
-rw-r--r-- | tests/unit/test_swiftclient.py | 22 |
2 files changed, 21 insertions, 3 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index f13e829..78e2cfe 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -361,7 +361,7 @@ def get_auth(auth_url, user, key, **kwargs): if kwargs.get('tenant_name'): os_options['tenant_name'] = kwargs['tenant_name'] - if ('tenant_name' not in os_options): + if not (os_options.get('tenant_name') or os_options.get('tenant_id')): raise ClientException('No tenant specified') cacert = kwargs.get('cacert', None) diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py index 283400e..d473765 100644 --- a/tests/unit/test_swiftclient.py +++ b/tests/unit/test_swiftclient.py @@ -285,7 +285,7 @@ class TestGetAuth(MockHttpTest): 'asdf', 'asdf', auth_version='1.0') - def test_auth_v2(self): + def test_auth_v2_with_tenant_name(self): os_options = {'tenant_name': 'asdf'} c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', @@ -294,13 +294,31 @@ class TestGetAuth(MockHttpTest): self.assertTrue(url.startswith("http")) self.assertTrue(token) - def test_auth_v2_no_tenant_name(self): + def test_auth_v2_with_tenant_id(self): + os_options = {'tenant_id': 'asdf'} + c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) + url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', + os_options=os_options, + auth_version="2.0") + self.assertTrue(url.startswith("http")) + self.assertTrue(token) + + def test_auth_v2_no_tenant_name_or_tenant_id(self): c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0({}) self.assertRaises(c.ClientException, c.get_auth, 'http://www.tests.com', 'asdf', 'asdf', os_options={}, auth_version='2.0') + def test_auth_v2_with_tenant_name_none_and_tenant_id_none(self): + os_options = {'tenant_name': None, + 'tenant_id': None} + c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) + self.assertRaises(c.ClientException, c.get_auth, + 'http://www.tests.com', 'asdf', 'asdf', + os_options=os_options, + auth_version='2.0') + def test_auth_v2_with_tenant_user_in_user(self): tenant_option = {'tenant_name': 'foo'} c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option) |