From 85388cdd88f6d851e34ab6b54c072bdd97e52605 Mon Sep 17 00:00:00 2001 From: Ziad Sawalha Date: Sat, 21 May 2011 02:28:52 -0500 Subject: v1 compatibility and Service/Admin API split --- test/unit/test_authentication.py | 9 +++++++-- test/unit/test_common.py | 37 ++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/unit/test_authentication.py b/test/unit/test_authentication.py index a6531473..2cfd8e31 100644 --- a/test/unit/test_authentication.py +++ b/test/unit/test_authentication.py @@ -55,6 +55,11 @@ class AuthenticationTest(unittest.TestCase): self.assertEqual(200, int(resp['status'])) self.assertEqual('application/xml', utils.content_type(resp)) + def test_a_authorize_legacy(self): + resp, content = utils.get_token_legacy('joeuser', 'secrete') + self.assertEqual(204, int(resp['status'])) + self.assertTrue(resp['x-auth-token']) + def test_a_authorize_user_disabled(self): header = httplib2.Http(".cache") url = '%stoken' % utils.URL @@ -153,7 +158,7 @@ class MultiToken(unittest.TestCase): utils.delete_user('test_tenant2', 'test_user1', self.auth_token) utils.delete_tenant('test_tenant1', self.auth_token) utils.delete_tenant('test_tenant2', self.auth_token) - + """ INVALID TEST - we're changing how we delegate access to second tenant def test_multi_token(self): #get token for user1 with tenant1 @@ -170,7 +175,7 @@ class MultiToken(unittest.TestCase): resp = utils.delete_token(token1, self.auth_token) resp = utils.delete_token(token2, self.auth_token) """ - + def test_unassigned_user(self): resp, content = utils.get_token('test_user2', 'secrete', \ 'test_tenant2') diff --git a/test/unit/test_common.py b/test/unit/test_common.py index 07c46f50..adcf8e8d 100644 --- a/test/unit/test_common.py +++ b/test/unit/test_common.py @@ -24,15 +24,14 @@ sys.path.append(os.path.abspath(os.path.join(os.path.abspath(__file__), '..', '..', '..', '..', 'keystone'))) import unittest - - -URL = 'http://localhost:8080/v2.0/' +URL = 'http://localhost:8081/v2.0/' +URLv1 = 'http://localhost:8081/v1.0/' def get_token(user, pswd, tenant_id, kind=''): header = httplib2.Http(".cache") url = '%stoken' % URL - # to test multi token, removing below code + if not tenant_id: body = {"passwordCredentials": {"username": user, "password": pswd}} @@ -40,7 +39,7 @@ def get_token(user, pswd, tenant_id, kind=''): body = {"passwordCredentials": {"username": user, "password": pswd, "tenantId": tenant_id}} - + resp, content = header.request(url, "POST", body=json.dumps(body), headers={"Content-Type": "application/json"}) @@ -55,6 +54,23 @@ def get_token(user, pswd, tenant_id, kind=''): return (resp, content) +def get_token_legacy(user, pswd, kind=''): + header = httplib2.Http(".cache") + url = URLv1 + resp, content = header.request(url, "GET", '', + headers={"Content-Type": "application/json", + "X-Auth-User": user, + "X-Auth-Key": pswd}) + + if int(resp['status']) == 204: + token = resp['x-auth-token'] + else: + token = None + if kind == 'token': + return token + else: + return (resp, content) + def delete_token(token, auth_token): header = httplib2.Http(".cache") @@ -180,7 +196,8 @@ def get_token_xml(user, pswd, tenant_id, type=''): "ACCEPT": "application/xml"}) if int(resp['status']) == 200: dom = etree.fromstring(content) - root = dom.find("{http://docs.openstack.org/identity/api/v2.0}token") + root = dom.find("{http://docs.openstack.org/" \ + "identity/api/v2.0}token") token_root = root.attrib token = str(token_root['id']) else: @@ -318,6 +335,7 @@ def delete_user_xml(tenantid, userid, auth_token): "ACCEPT": "application/xml"}) return resp + def add_user_json(tenantid, userid, auth_token): header = httplib2.Http(".cache") url = '%stenants/%s/users/%s/add' % (URL, tenantid, userid) @@ -676,7 +694,8 @@ def handle_user_resp(self, content, respvalue, resptype): if respvalue == 200: if resptype == 'application/json': content = json.loads(content) - self.tenant = content['user']['tenantId'] + if 'tenantId' in content['user']: + self.tenant = content['user']['tenantId'] self.userid = content['user']['id'] if resptype == 'application/xml': content = etree.fromstring(content) @@ -686,7 +705,3 @@ def handle_user_resp(self, content, respvalue, resptype): self.fail('Identity Fault') elif respvalue == 503: self.fail('Service Not Available') - - -def content_type(resp): - return resp['content-type'].split(';')[0] -- cgit From 888b18e3f42fd6078fcc9c7079bf058ffad834ff Mon Sep 17 00:00:00 2001 From: Ziad Sawalha Date: Mon, 23 May 2011 02:11:59 -0500 Subject: New model working with echo_client.py --- test/unit/test_common.py | 1 - test/unit/test_exthandler.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/test_common.py b/test/unit/test_common.py index adcf8e8d..800f1a7c 100644 --- a/test/unit/test_common.py +++ b/test/unit/test_common.py @@ -27,7 +27,6 @@ import unittest URL = 'http://localhost:8081/v2.0/' URLv1 = 'http://localhost:8081/v1.0/' - def get_token(user, pswd, tenant_id, kind=''): header = httplib2.Http(".cache") url = '%stoken' % URL diff --git a/test/unit/test_exthandler.py b/test/unit/test_exthandler.py index 5d41aeac..4379e03f 100644 --- a/test/unit/test_exthandler.py +++ b/test/unit/test_exthandler.py @@ -1,3 +1,19 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import sys # Need to access identity module -- cgit