Merge "Allow passing None for username in v2.Password"
This commit is contained in:
@@ -95,11 +95,14 @@ class Auth(base.BaseIdentityPlugin):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
_NOT_PASSED = object()
|
||||||
|
|
||||||
|
|
||||||
class Password(Auth):
|
class Password(Auth):
|
||||||
|
|
||||||
@utils.positional(4)
|
@utils.positional(4)
|
||||||
def __init__(self, auth_url, username=None, password=None, user_id=None,
|
def __init__(self, auth_url, username=_NOT_PASSED, password=None,
|
||||||
**kwargs):
|
user_id=_NOT_PASSED, **kwargs):
|
||||||
"""A plugin for authenticating with a username and password.
|
"""A plugin for authenticating with a username and password.
|
||||||
|
|
||||||
A username or user_id must be provided.
|
A username or user_id must be provided.
|
||||||
@@ -113,10 +116,15 @@ class Password(Auth):
|
|||||||
"""
|
"""
|
||||||
super(Password, self).__init__(auth_url, **kwargs)
|
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'
|
msg = 'You need to specify either a username or user_id'
|
||||||
raise TypeError(msg)
|
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.user_id = user_id
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
@@ -100,6 +100,7 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
|
self.assertIsNone(a.user_id)
|
||||||
s = session.Session(a)
|
s = session.Session(a)
|
||||||
s.get_token()
|
s.get_token()
|
||||||
|
|
||||||
@@ -114,6 +115,7 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Password(self.TEST_URL, user_id=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, user_id=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
|
self.assertIsNone(a.username)
|
||||||
s = session.Session(a)
|
s = session.Session(a)
|
||||||
s.get_token()
|
s.get_token()
|
||||||
|
|
||||||
@@ -128,6 +130,7 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS, tenant_id=self.TEST_TENANT_ID)
|
password=self.TEST_PASS, tenant_id=self.TEST_TENANT_ID)
|
||||||
|
self.assertIsNone(a.user_id)
|
||||||
s = session.Session(a)
|
s = session.Session(a)
|
||||||
s.get_token()
|
s.get_token()
|
||||||
|
|
||||||
@@ -141,6 +144,7 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Password(self.TEST_URL, user_id=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, user_id=self.TEST_USER,
|
||||||
password=self.TEST_PASS, tenant_id=self.TEST_TENANT_ID)
|
password=self.TEST_PASS, tenant_id=self.TEST_TENANT_ID)
|
||||||
|
self.assertIsNone(a.username)
|
||||||
s = session.Session(a)
|
s = session.Session(a)
|
||||||
s.get_token()
|
s.get_token()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user