diff options
| author | Yogeshwar Srikrishnan <yoga80@yahoo.com> | 2011-05-23 11:51:01 -0500 |
|---|---|---|
| committer | Yogeshwar Srikrishnan <yoga80@yahoo.com> | 2011-05-23 11:51:01 -0500 |
| commit | 3d855a4cec46ecc8d8b98090de95bab88864a643 (patch) | |
| tree | 00f9698c29278df28856915701aa6c5197a8d7b5 /test | |
| parent | 7170c6219b2c635856218290e5fea779eb595642 (diff) | |
| parent | 7211ce8ecb303c3da561f530df7aaad2ea1d68b4 (diff) | |
Merge remote branch 'khussein/master'
Diffstat (limited to 'test')
| -rw-r--r-- | test/unit/test_authentication.py | 9 | ||||
| -rw-r--r-- | test/unit/test_common.py | 38 | ||||
| -rw-r--r-- | test/unit/test_exthandler.py | 16 |
3 files changed, 49 insertions, 14 deletions
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..800f1a7c 100644 --- a/test/unit/test_common.py +++ b/test/unit/test_common.py @@ -24,15 +24,13 @@ 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 +38,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 +53,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 +195,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 +334,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 +693,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 +704,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] 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 |
