remove X-Auth-Project-Id, re-add auth by token support (most tests pass)

This commit is contained in:
Jesse Andrews
2011-12-18 22:08:26 -08:00
parent 604b748b51
commit d37c20ca72
9 changed files with 21 additions and 36 deletions

View File

@@ -96,6 +96,7 @@ class Client(client.HTTPClient):
tenant_id=self.tenant_id, tenant_id=self.tenant_id,
tenant_name=self.tenant_name, tenant_name=self.tenant_name,
password=self.password, password=self.password,
token=self.auth_token,
return_raw=True) return_raw=True)
self._extract_service_catalog(self.auth_url, raw_token) self._extract_service_catalog(self.auth_url, raw_token)
return True return True

View File

@@ -33,7 +33,6 @@ class ClientTest(utils.TestCase):
def test_get_call(): def test_get_call():
resp, body = cl.get("/hi") resp, body = cl.get("/hi")
headers = {"X-Auth-Token": "token", headers = {"X-Auth-Token": "token",
"X-Auth-Project-Id": "project_id",
"User-Agent": cl.USER_AGENT, "User-Agent": cl.USER_AGENT,
} }
mock_request.assert_called_with("http://127.0.0.1:5000/" mock_request.assert_called_with("http://127.0.0.1:5000/"
@@ -52,7 +51,6 @@ class ClientTest(utils.TestCase):
cl.post("/hi", body=[1, 2, 3]) cl.post("/hi", body=[1, 2, 3])
headers = { headers = {
"X-Auth-Token": "token", "X-Auth-Token": "token",
"X-Auth-Project-Id": "project_id",
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent": cl.USER_AGENT "User-Agent": cl.USER_AGENT
} }

View File

@@ -8,7 +8,7 @@ from keystoneclient.v2_0 import client
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
TEST_TENANT = '1' TEST_TENANT_ID = '1'
TEST_TENANT_NAME = 'aTenant' TEST_TENANT_NAME = 'aTenant'
TEST_TOKEN = 'aToken' TEST_TOKEN = 'aToken'
TEST_USER = 'test' TEST_USER = 'test'
@@ -70,7 +70,7 @@ class TestCase(unittest.TestCase):
httplib2.Http.request = self.mox.CreateMockAnything() httplib2.Http.request = self.mox.CreateMockAnything()
self.client = client.Client(username=self.TEST_USER, self.client = client.Client(username=self.TEST_USER,
token=self.TEST_TOKEN, token=self.TEST_TOKEN,
project_id=self.TEST_TENANT, tenant_name=self.TEST_TENANT_ID,
auth_url=self.TEST_URL, auth_url=self.TEST_URL,
endpoint=self.TEST_URL) endpoint=self.TEST_URL)

View File

@@ -36,7 +36,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"username": self.TEST_USER, "username": self.TEST_USER,
"password": self.TEST_TOKEN, "password": self.TEST_TOKEN,
}, },
"tenantId": self.TEST_TENANT "tenantId": self.TEST_TENANT_ID
} }
} }
self.TEST_REQUEST_HEADERS = { self.TEST_REQUEST_HEADERS = {
@@ -47,7 +47,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
def test_authenticate_failure(self): def test_authenticate_failure(self):
self.TEST_REQUEST_BODY['auth']['passwordCredentials']['password'] = \ self.TEST_REQUEST_BODY['auth']['passwordCredentials']['password'] = \
'bad_key' 'bad_key'
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
resp = httplib2.Response({ resp = httplib2.Response({
"status": 401, "status": 401,
"body": json.dumps({"unauthorized": { "body": json.dumps({"unauthorized": {
@@ -70,11 +69,10 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
with self.assertRaises(exceptions.Unauthorized): with self.assertRaises(exceptions.Unauthorized):
client.Client(username=self.TEST_USER, client.Client(username=self.TEST_USER,
password="bad_key", password="bad_key",
project_id=self.TEST_TENANT, tenant_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL) auth_url=self.TEST_URL)
def test_auth_redirect(self): def test_auth_redirect(self):
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
correct_response = json.dumps(self.TEST_RESPONSE_DICT) correct_response = json.dumps(self.TEST_RESPONSE_DICT)
dict_responses = [ dict_responses = [
{"headers": {'location': self.TEST_ADMIN_URL + "/tokens"}, {"headers": {'location': self.TEST_ADMIN_URL + "/tokens"},
@@ -101,17 +99,16 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cs = client.Client(username=self.TEST_USER, cs = client.Client(username=self.TEST_USER,
password=self.TEST_TOKEN, password=self.TEST_TOKEN,
project_id=self.TEST_TENANT, tenant_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL) auth_url=self.TEST_URL)
self.assertEqual(cs.management_url, self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3] self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["publicURL"]) ['endpoints'][0]["adminURL"])
self.assertEqual(cs.auth_token, self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"]) self.TEST_RESPONSE_DICT["access"]["token"]["id"])
def test_authenticate_success_password_scoped(self): def test_authenticate_success_password_scoped(self):
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT), "body": json.dumps(self.TEST_RESPONSE_DICT),
@@ -126,11 +123,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cs = client.Client(username=self.TEST_USER, cs = client.Client(username=self.TEST_USER,
password=self.TEST_TOKEN, password=self.TEST_TOKEN,
project_id=self.TEST_TENANT, tenant_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL) auth_url=self.TEST_URL)
self.assertEqual(cs.management_url, self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3] self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["publicURL"]) ['endpoints'][0]["adminURL"])
self.assertEqual(cs.auth_token, self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"]) self.TEST_RESPONSE_DICT["access"]["token"]["id"])
@@ -159,7 +156,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
def test_authenticate_success_token_scoped(self): def test_authenticate_success_token_scoped(self):
del self.TEST_REQUEST_BODY['auth']['passwordCredentials'] del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
self.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN} self.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN}
self.TEST_REQUEST_HEADERS['X-Auth-Project-Id'] = '1'
self.TEST_REQUEST_HEADERS['X-Auth-Token'] = self.TEST_TOKEN self.TEST_REQUEST_HEADERS['X-Auth-Token'] = self.TEST_TOKEN
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
@@ -174,11 +170,11 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
cs = client.Client(token=self.TEST_TOKEN, cs = client.Client(token=self.TEST_TOKEN,
project_id=self.TEST_TENANT, tenant_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL) auth_url=self.TEST_URL)
self.assertEqual(cs.management_url, self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3] self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["publicURL"]) ['endpoints'][0]["adminURL"])
self.assertEqual(cs.auth_token, self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"]) self.TEST_RESPONSE_DICT["access"]["token"]["id"])

View File

@@ -10,11 +10,9 @@ from tests import utils
class RoleTests(utils.TestCase): class RoleTests(utils.TestCase):
def setUp(self): def setUp(self):
super(RoleTests, self).setUp() super(RoleTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_ROLES = { self.TEST_ROLES = {

View File

@@ -10,11 +10,9 @@ from tests import utils
class ServiceTests(utils.TestCase): class ServiceTests(utils.TestCase):
def setUp(self): def setUp(self):
super(ServiceTests, self).setUp() super(ServiceTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_SERVICES = {"OS-KSADM:services": { self.TEST_SERVICES = {"OS-KSADM:services": {

View File

@@ -10,11 +10,9 @@ from tests import utils
class TenantTests(utils.TestCase): class TenantTests(utils.TestCase):
def setUp(self): def setUp(self):
super(TenantTests, self).setUp() super(TenantTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_TENANTS = {"tenants": { self.TEST_TENANTS = {"tenants": {

View File

@@ -10,11 +10,9 @@ from tests import utils
class TokenTests(utils.TestCase): class TokenTests(utils.TestCase):
def setUp(self): def setUp(self):
#super(ServiceTests, self).setUp() #super(ServiceTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
''' '''

View File

@@ -10,11 +10,9 @@ from tests import utils
class UserTests(utils.TestCase): class UserTests(utils.TestCase):
def setUp(self): def setUp(self):
super(UserTests, self).setUp() super(UserTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'X-Auth-Project-Id': '1', self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient'}
self.TEST_USERS = { self.TEST_USERS = {