Make user_id a higher priority for v2 auth

Change-Id: I766440d5f8bd60b685f30254acb3987cabd161f0
This commit is contained in:
Terry Howe 2014-10-02 15:41:06 -06:00 committed by Terry Howe
parent 836b9e852d
commit 44c1648758
2 changed files with 27 additions and 3 deletions

View File

@ -100,10 +100,10 @@ class Auth(base.BaseIdentityPlugin):
def get_auth_data(self, headers):
if self.token is None:
auth = {'password': self.password}
if self.user_name:
auth['username'] = self.user_name
elif self.user_id:
if self.user_id:
auth['userId'] = self.user_id
elif self.user_name:
auth['username'] = self.user_name
return {'passwordCredentials': auth}
headers['X-Auth-Token'] = self.token
return {'token': {'id': self.token}}

View File

@ -65,6 +65,30 @@ class TestV2Auth(testtools.TestCase):
self.assertEqual(expected, sot.get_auth_data(headers))
self.assertEqual({'X-Auth-Token': common.TEST_TOKEN}, headers)
def test_user_id(self):
kargs = {
'password': common.TEST_PASS,
'project_id': common.TEST_TENANT_ID,
'project_name': common.TEST_TENANT_NAME,
'trust_id': common.TEST_TRUST_ID,
'user_name': common.TEST_USER,
'user_id': common.TEST_USER_ID,
}
sot = v2.Auth(TEST_URL, **kargs)
self.assertEqual(common.TEST_USER, sot.user_name)
self.assertEqual(common.TEST_USER_ID, sot.user_id)
self.assertEqual(common.TEST_PASS, sot.password)
self.assertEqual(common.TEST_TRUST_ID, sot.trust_id)
self.assertEqual(common.TEST_TENANT_ID, sot.tenant_id)
self.assertEqual(common.TEST_TENANT_NAME, sot.tenant_name)
expected = {'passwordCredentials': {'password': common.TEST_PASS,
'userId': common.TEST_USER_ID}}
headers = {}
self.assertEqual(expected, sot.get_auth_data(headers))
self.assertEqual({}, headers)
def create_mock_transport(self, xresp):
transport = mock.Mock()
transport.post = mock.Mock()