diff options
author | Jamie Lennox <jamielennox@redhat.com> | 2014-08-26 10:34:05 +1000 |
---|---|---|
committer | Jamie Lennox <jamielennox@redhat.com> | 2014-08-26 10:34:05 +1000 |
commit | 52103dfa2ae0b4eb413a3f9c7a2c1341e95cae0b (patch) | |
tree | 2d4441a824b6dcfe01404e311ba65824440057b9 | |
parent | 62d4c7141b96df60b5fb29ed1525da5513db99dc (diff) | |
download | python-keystoneclient-52103dfa2ae0b4eb413a3f9c7a2c1341e95cae0b.tar.gz |
Allow passing None for username in v2.Password
None must be an acceptable parameter for username in password due to
tests in other libraries, however we should still raise an error if
neither username or user_id is passed. Use and check a sentinel value
instead of None.
Change-Id: Id61cfd1423afa8f9dd964fda278f4fab40887512
Closes-Bug: #1361444
-rw-r--r-- | keystoneclient/auth/identity/v2.py | 14 | ||||
-rw-r--r-- | keystoneclient/tests/auth/test_identity_v2.py | 4 |
2 files changed, 15 insertions, 3 deletions
diff --git a/keystoneclient/auth/identity/v2.py b/keystoneclient/auth/identity/v2.py index 174f899..1668a82 100644 --- a/keystoneclient/auth/identity/v2.py +++ b/keystoneclient/auth/identity/v2.py @@ -95,11 +95,14 @@ class Auth(base.BaseIdentityPlugin): """ +_NOT_PASSED = object() + + class Password(Auth): @utils.positional(4) - def __init__(self, auth_url, username=None, password=None, user_id=None, - **kwargs): + def __init__(self, auth_url, username=_NOT_PASSED, password=None, + user_id=_NOT_PASSED, **kwargs): """A plugin for authenticating with a username and password. A username or user_id must be provided. @@ -113,10 +116,15 @@ class Password(Auth): """ super(Password, self).__init__(auth_url, **kwargs) - if not (user_id or username): + if username is _NOT_PASSED and user_id is _NOT_PASSED: msg = 'You need to specify either a username or user_id' raise TypeError(msg) + if username is _NOT_PASSED: + username = None + if user_id is _NOT_PASSED: + user_id = None + self.user_id = user_id self.username = username self.password = password diff --git a/keystoneclient/tests/auth/test_identity_v2.py b/keystoneclient/tests/auth/test_identity_v2.py index 52e178b..d832f14 100644 --- a/keystoneclient/tests/auth/test_identity_v2.py +++ b/keystoneclient/tests/auth/test_identity_v2.py @@ -100,6 +100,7 @@ class V2IdentityPlugin(utils.TestCase): self.stub_auth(json=self.TEST_RESPONSE_DICT) a = v2.Password(self.TEST_URL, username=self.TEST_USER, password=self.TEST_PASS) + self.assertIsNone(a.user_id) s = session.Session(a) s.get_token() @@ -114,6 +115,7 @@ class V2IdentityPlugin(utils.TestCase): self.stub_auth(json=self.TEST_RESPONSE_DICT) a = v2.Password(self.TEST_URL, user_id=self.TEST_USER, password=self.TEST_PASS) + self.assertIsNone(a.username) s = session.Session(a) s.get_token() @@ -128,6 +130,7 @@ class V2IdentityPlugin(utils.TestCase): self.stub_auth(json=self.TEST_RESPONSE_DICT) a = v2.Password(self.TEST_URL, username=self.TEST_USER, password=self.TEST_PASS, tenant_id=self.TEST_TENANT_ID) + self.assertIsNone(a.user_id) s = session.Session(a) s.get_token() @@ -141,6 +144,7 @@ class V2IdentityPlugin(utils.TestCase): self.stub_auth(json=self.TEST_RESPONSE_DICT) a = v2.Password(self.TEST_URL, user_id=self.TEST_USER, password=self.TEST_PASS, tenant_id=self.TEST_TENANT_ID) + self.assertIsNone(a.username) s = session.Session(a) s.get_token() |