Create a V3 Token Generator
A token generator that can be used by other clients to generate consistent tokens in there test code. Change-Id: I05d2632b4c8290c2b1015996769340f0bea16f93 blueprint: share-tokens
This commit is contained in:
@@ -23,5 +23,6 @@ testing.
|
||||
|
||||
from keystoneclient.fixture.exception import FixtureValidationError # noqa
|
||||
from keystoneclient.fixture.v2 import Token as V2Token # noqa
|
||||
from keystoneclient.fixture.v3 import Token as V3Token # noqa
|
||||
|
||||
__all__ = ['V2Token', 'FixtureValidationError']
|
||||
__all__ = ['V2Token', 'V3Token', 'FixtureValidationError']
|
||||
|
304
keystoneclient/fixture/v3.py
Normal file
304
keystoneclient/fixture/v3.py
Normal file
@@ -0,0 +1,304 @@
|
||||
# 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 datetime
|
||||
import uuid
|
||||
|
||||
from keystoneclient.fixture import exception
|
||||
from keystoneclient.openstack.common import timeutils
|
||||
|
||||
|
||||
class _Service(dict):
|
||||
"""One of the services that exist in the catalog.
|
||||
|
||||
You use this by adding a service to a token which returns an instance of
|
||||
this object and then you can add_endpoints to the service.
|
||||
"""
|
||||
|
||||
def add_endpoint(self, interface, url, region=None):
|
||||
data = {'interface': interface,
|
||||
'url': url,
|
||||
'region': region}
|
||||
self.setdefault('endpoints', []).append(data)
|
||||
return data
|
||||
|
||||
def add_standard_endpoints(self, public=None, admin=None, internal=None,
|
||||
region=None):
|
||||
ret = []
|
||||
|
||||
if public:
|
||||
ret.append(self.add_endpoint('public', public, region=region))
|
||||
if admin:
|
||||
ret.append(self.add_endpoint('admin', admin, region=region))
|
||||
if internal:
|
||||
ret.append(self.add_endpoint('internal', internal, region=region))
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
class Token(dict):
|
||||
"""A V3 Keystone token that can be used for testing.
|
||||
|
||||
This object is designed to allow clients to generate a correct V3 token for
|
||||
use in there test code. It should prevent clients from having to know the
|
||||
correct token format and allow them to test the portions of token handling
|
||||
that matter to them and not copy and paste sample.
|
||||
"""
|
||||
|
||||
def __init__(self, expires=None, user_id=None, user_name=None,
|
||||
user_domain_id=None, user_domain_name=None, methods=None,
|
||||
project_id=None, project_name=None, project_domain_id=None,
|
||||
project_domain_name=None, domain_id=None, domain_name=None,
|
||||
trust_id=None, trust_impersonation=None, trustee_user_id=None,
|
||||
trustor_user_id=None):
|
||||
super(Token, self).__init__()
|
||||
|
||||
self.user_id = user_id or uuid.uuid4().hex
|
||||
self.user_name = user_name or uuid.uuid4().hex
|
||||
self.user_domain_id = user_domain_id or uuid.uuid4().hex
|
||||
self.user_domain_name = user_domain_name or uuid.uuid4().hex
|
||||
|
||||
if not methods:
|
||||
methods = ['password']
|
||||
self.methods.extend(methods)
|
||||
|
||||
if not expires:
|
||||
expires = timeutils.utcnow() + datetime.timedelta(hours=1)
|
||||
|
||||
try:
|
||||
self.expires = expires
|
||||
except (TypeError, AttributeError):
|
||||
# expires should be able to be passed as a string so ignore
|
||||
self.expires_str = expires
|
||||
|
||||
if (project_id or project_name or
|
||||
project_domain_id or project_domain_name):
|
||||
self.set_project_scope(id=project_id,
|
||||
name=project_name,
|
||||
domain_id=project_domain_id,
|
||||
domain_name=project_domain_name)
|
||||
|
||||
if domain_id or domain_name:
|
||||
self.set_domain_scope(id=domain_id, name=domain_name)
|
||||
|
||||
if (trust_id or (trust_impersonation is not None) or
|
||||
trustee_user_id or trustor_user_id):
|
||||
self.set_trust_scope(id=trust_id,
|
||||
impersonation=trust_impersonation,
|
||||
trustee_user_id=trustee_user_id,
|
||||
trustor_user_id=trustor_user_id)
|
||||
|
||||
@property
|
||||
def root(self):
|
||||
return self.setdefault('token', {})
|
||||
|
||||
@property
|
||||
def expires_str(self):
|
||||
return self.root.get('expires_at')
|
||||
|
||||
@expires_str.setter
|
||||
def expires_str(self, value):
|
||||
self.root['expires_at'] = value
|
||||
|
||||
@property
|
||||
def expires(self):
|
||||
return timeutils.parse_isotime(self.expires_str)
|
||||
|
||||
@expires.setter
|
||||
def expires(self, value):
|
||||
self.expires_str = timeutils.isotime(value)
|
||||
|
||||
@property
|
||||
def _user(self):
|
||||
return self.root.setdefault('user', {})
|
||||
|
||||
@property
|
||||
def user_id(self):
|
||||
return self._user.get('id')
|
||||
|
||||
@user_id.setter
|
||||
def user_id(self, value):
|
||||
self._user['id'] = value
|
||||
|
||||
@property
|
||||
def user_name(self):
|
||||
return self._user.get('name')
|
||||
|
||||
@user_name.setter
|
||||
def user_name(self, value):
|
||||
self._user['name'] = value
|
||||
|
||||
@property
|
||||
def _user_domain(self):
|
||||
return self._user.setdefault('domain', {})
|
||||
|
||||
@property
|
||||
def user_domain_id(self):
|
||||
return self._user_domain.get('id')
|
||||
|
||||
@user_domain_id.setter
|
||||
def user_domain_id(self, value):
|
||||
self._user_domain['id'] = value
|
||||
|
||||
@property
|
||||
def user_domain_name(self):
|
||||
return self._user_domain.get('name')
|
||||
|
||||
@user_domain_name.setter
|
||||
def user_domain_name(self, value):
|
||||
self._user_domain['name'] = value
|
||||
|
||||
@property
|
||||
def methods(self):
|
||||
return self.root.setdefault('methods', [])
|
||||
|
||||
@property
|
||||
def project_id(self):
|
||||
return self.root.get('project', {}).get('id')
|
||||
|
||||
@project_id.setter
|
||||
def project_id(self, value):
|
||||
self.root.setdefault('project', {})['id'] = value
|
||||
|
||||
@property
|
||||
def project_name(self):
|
||||
return self.root.get('project', {}).get('name')
|
||||
|
||||
@project_name.setter
|
||||
def project_name(self, value):
|
||||
self.root.setdefault('project', {})['name'] = value
|
||||
|
||||
@property
|
||||
def project_domain_id(self):
|
||||
return self.root.get('project', {}).get('domain', {}).get('id')
|
||||
|
||||
@project_domain_id.setter
|
||||
def project_domain_id(self, value):
|
||||
project = self.root.setdefault('project', {})
|
||||
project.setdefault('domain', {})['id'] = value
|
||||
|
||||
@property
|
||||
def project_domain_name(self):
|
||||
return self.root.get('project', {}).get('project', {}).get('name')
|
||||
|
||||
@project_domain_name.setter
|
||||
def project_domain_name(self, value):
|
||||
project = self.root.setdefault('project', {})
|
||||
project.setdefault('domain', {})['name'] = value
|
||||
|
||||
@property
|
||||
def domain_id(self):
|
||||
return self.root.get('domain', {}).get('id')
|
||||
|
||||
@domain_id.setter
|
||||
def domain_id(self, value):
|
||||
self.root.setdefault('domain', {})['id'] = value
|
||||
|
||||
@property
|
||||
def domain_name(self):
|
||||
return self.root.get('domain', {}).get('name')
|
||||
|
||||
@domain_name.setter
|
||||
def domain_name(self, value):
|
||||
self.root.setdefault('domain', {})['name'] = value
|
||||
|
||||
@property
|
||||
def trust_id(self):
|
||||
return self.root.get('OS-TRUST:trust', {}).get('id')
|
||||
|
||||
@trust_id.setter
|
||||
def trust_id(self, value):
|
||||
self.root.setdefault('OS-TRUST:trust', {})['id'] = value
|
||||
|
||||
@property
|
||||
def trust_impersonation(self):
|
||||
return self.root.get('OS-TRUST:trust', {}).get('impersonation')
|
||||
|
||||
@trust_impersonation.setter
|
||||
def trust_impersonation(self, value):
|
||||
self.root.setdefault('OS-TRUST:trust', {})['impersonation'] = value
|
||||
|
||||
@property
|
||||
def trustee_user_id(self):
|
||||
trust = self.root.get('OS-TRUST:trust', {})
|
||||
return trust.get('trustee_user', {}).get('id')
|
||||
|
||||
@trustee_user_id.setter
|
||||
def trustee_user_id(self, value):
|
||||
trust = self.root.setdefault('OS-TRUST:trust', {})
|
||||
trust.setdefault('trustee_user', {})['id'] = value
|
||||
|
||||
@property
|
||||
def trustor_user_id(self):
|
||||
trust = self.root.get('OS-TRUST:trust', {})
|
||||
return trust.get('trustor_user', {}).get('id')
|
||||
|
||||
@trustor_user_id.setter
|
||||
def trustor_user_id(self, value):
|
||||
trust = self.root.setdefault('OS-TRUST:trust', {})
|
||||
trust.setdefault('trustor_user', {})['id'] = value
|
||||
|
||||
def validate(self):
|
||||
project = self.root.get('project')
|
||||
domain = self.root.get('domain')
|
||||
trust = self.root.get('OS-TRUST:trust')
|
||||
catalog = self.root.get('catalog')
|
||||
roles = self.root.get('roles')
|
||||
scoped = project or domain or trust
|
||||
|
||||
if sum((bool(project), bool(domain), bool(trust))) > 1:
|
||||
msg = 'You cannot scope to multiple targets'
|
||||
raise exception.FixtureValidationError(msg)
|
||||
|
||||
if catalog and not scoped:
|
||||
msg = 'You cannot have a service catalog on an unscoped token'
|
||||
raise exception.FixtureValidationError(msg)
|
||||
|
||||
if scoped and not self.user.get('roles'):
|
||||
msg = 'You must have roles on a token to scope it'
|
||||
raise exception.FixtureValidationError(msg)
|
||||
|
||||
if bool(scoped) != bool(roles):
|
||||
msg = 'You must be scoped to have roles and vice-versa'
|
||||
raise exception.FixtureValidationError(msg)
|
||||
|
||||
def add_role(self, name=None, id=None):
|
||||
roles = self.root.setdefault('roles', [])
|
||||
data = {'id': id or uuid.uuid4().hex,
|
||||
'name': name or uuid.uuid4().hex}
|
||||
roles.append(data)
|
||||
return data
|
||||
|
||||
def add_service(self, type, name=None):
|
||||
service = _Service(type=type)
|
||||
if name:
|
||||
service['name'] = name
|
||||
self.root.setdefault('catalog', []).append(service)
|
||||
return service
|
||||
|
||||
def set_project_scope(self, id=None, name=None, domain_id=None,
|
||||
domain_name=None):
|
||||
self.project_id = id or uuid.uuid4().hex
|
||||
self.project_name = name or uuid.uuid4().hex
|
||||
self.project_domain_id = domain_id or uuid.uuid4().hex
|
||||
self.project_domain_name = domain_name or uuid.uuid4().hex
|
||||
|
||||
def set_domain_scope(self, id=None, name=None):
|
||||
self.domain_id = id or uuid.uuid4().hex
|
||||
self.domain_name = name or uuid.uuid4().hex
|
||||
|
||||
def set_trust_scope(self, id=None, impersonation=False,
|
||||
trustee_user_id=None, trustor_user_id=None):
|
||||
self.trust_id = id or uuid.uuid4().hex
|
||||
self.trust_impersonation = impersonation
|
||||
self.trustee_user_id = trustee_user_id or uuid.uuid4().hex
|
||||
self.trustor_user_id = trustor_user_id or uuid.uuid4().hex
|
@@ -12,266 +12,112 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from keystoneclient import fixture
|
||||
|
||||
UNSCOPED_TOKEN = {
|
||||
'token': {
|
||||
'methods': [
|
||||
'password'
|
||||
],
|
||||
'catalog': {},
|
||||
'expires_at': '2010-11-01T03:32:15-05:00',
|
||||
'user': {
|
||||
'domain': {
|
||||
'id': '4e6893b7ba0b4006840c3845660b86ed',
|
||||
'name': 'exampledomain'
|
||||
},
|
||||
'id': 'c4da488862bd435c9e6c0275a0d0e49a',
|
||||
'name': 'exampleuser',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DOMAIN_SCOPED_TOKEN = {
|
||||
'token': {
|
||||
'methods': [
|
||||
'password'
|
||||
],
|
||||
'catalog': [{
|
||||
'endpoints': [{
|
||||
'url':
|
||||
'http://public.com:8776/v1/None',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url':
|
||||
'http://internal:8776/v1/None',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url':
|
||||
'http://admin:8776/v1/None',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'volume'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://public.com:9292/v1',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://internal:9292/v1',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://admin:9292/v1',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'image'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url':
|
||||
'http://public.com:8774/v1.1/None',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url':
|
||||
'http://internal:8774/v1.1/None',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url':
|
||||
'http://admin:8774/v1.1/None',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'compute'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://public.com:8773/services/Cloud',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://internal:8773/services/Cloud',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://admin:8773/services/Admin',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'ec2'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://public.com:5000/v3',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://internal:5000/v3',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://admin:35357/v3',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'identity'
|
||||
}],
|
||||
'expires_at': '2010-11-01T03:32:15-05:00',
|
||||
'user': {
|
||||
'domain': {
|
||||
'id': '4e6893b7ba0b4006840c3845660b86ed',
|
||||
'name': 'exampledomain'
|
||||
},
|
||||
'id': 'c4da488862bd435c9e6c0275a0d0e49a',
|
||||
'name': 'exampleuser',
|
||||
},
|
||||
'roles': [
|
||||
{
|
||||
"id": "76e72a",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/roles/76e72a"
|
||||
},
|
||||
"name": "admin"
|
||||
},
|
||||
{
|
||||
"id": "f4f392",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/roles/f4f392"
|
||||
},
|
||||
"name": "member"
|
||||
}
|
||||
],
|
||||
'domain': {
|
||||
'id': '8e9283b7ba0b1038840c3842058b86ab',
|
||||
'name': 'anotherdomain'
|
||||
},
|
||||
}
|
||||
}
|
||||
def unscoped_token():
|
||||
return fixture.V3Token(user_id='c4da488862bd435c9e6c0275a0d0e49a',
|
||||
user_name='exampleuser',
|
||||
user_domain_id='4e6893b7ba0b4006840c3845660b86ed',
|
||||
user_domain_name='exampledomain',
|
||||
expires='2010-11-01T03:32:15-05:00')
|
||||
|
||||
|
||||
def domain_scoped_token():
|
||||
f = fixture.V3Token(user_id='c4da488862bd435c9e6c0275a0d0e49a',
|
||||
user_name='exampleuser',
|
||||
user_domain_id='4e6893b7ba0b4006840c3845660b86ed',
|
||||
user_domain_name='exampledomain',
|
||||
expires='2010-11-01T03:32:15-05:00',
|
||||
domain_id='8e9283b7ba0b1038840c3842058b86ab',
|
||||
domain_name='anotherdomain')
|
||||
|
||||
f.add_role(id='76e72a', name='admin')
|
||||
f.add_role(id='f4f392', name='member')
|
||||
region = 'RegionOne'
|
||||
|
||||
s = f.add_service('volume')
|
||||
s.add_standard_endpoints(public='http://public.com:8776/v1/None',
|
||||
internal='http://internal.com:8776/v1/None',
|
||||
admin='http://admin.com:8776/v1/None',
|
||||
region=region)
|
||||
|
||||
s = f.add_service('image')
|
||||
s.add_standard_endpoints(public='http://public.com:9292/v1',
|
||||
internal='http://internal:9292/v1',
|
||||
admin='http://admin:9292/v1',
|
||||
region=region)
|
||||
|
||||
s = f.add_service('compute')
|
||||
s.add_standard_endpoints(public='http://public.com:8774/v1.1/None',
|
||||
internal='http://internal:8774/v1.1/None',
|
||||
admin='http://admin:8774/v1.1/None',
|
||||
region=region)
|
||||
|
||||
s = f.add_service('ec2')
|
||||
s.add_standard_endpoints(public='http://public.com:8773/services/Cloud',
|
||||
internal='http://internal:8773/services/Cloud',
|
||||
admin='http://admin:8773/services/Admin',
|
||||
region=region)
|
||||
|
||||
s = f.add_service('identity')
|
||||
s.add_standard_endpoints(public='http://public.com:5000/v3',
|
||||
internal='http://internal:5000/v3',
|
||||
admin='http://admin:35357/v3',
|
||||
region=region)
|
||||
|
||||
return f
|
||||
|
||||
|
||||
def project_scoped_token():
|
||||
f = fixture.V3Token(user_id='c4da488862bd435c9e6c0275a0d0e49a',
|
||||
user_name='exampleuser',
|
||||
user_domain_id='4e6893b7ba0b4006840c3845660b86ed',
|
||||
user_domain_name='exampledomain',
|
||||
expires='2010-11-01T03:32:15-05:00',
|
||||
project_id='225da22d3ce34b15877ea70b2a575f58',
|
||||
project_name='exampleproject',
|
||||
project_domain_id='4e6893b7ba0b4006840c3845660b86ed',
|
||||
project_domain_name='exampledomain')
|
||||
|
||||
f.add_role(id='76e72a', name='admin')
|
||||
f.add_role(id='f4f392', name='member')
|
||||
|
||||
region = 'RegionOne'
|
||||
tenant = '225da22d3ce34b15877ea70b2a575f58'
|
||||
|
||||
s = f.add_service('volume')
|
||||
s.add_standard_endpoints(public='http://public.com:8776/v1/%s' % tenant,
|
||||
internal='http://internal:8776/v1/%s' % tenant,
|
||||
admin='http://admin:8776/v1/%s' % tenant,
|
||||
region=region)
|
||||
|
||||
s = f.add_service('image')
|
||||
s.add_standard_endpoints(public='http://public.com:9292/v1',
|
||||
internal='http://internal:9292/v1',
|
||||
admin='http://admin:9292/v1',
|
||||
region=region)
|
||||
|
||||
s = f.add_service('compute')
|
||||
s.add_standard_endpoints(public='http://public.com:8774/v2/%s' % tenant,
|
||||
internal='http://internal:8774/v2/%s' % tenant,
|
||||
admin='http://admin:8774/v2/%s' % tenant,
|
||||
region=region)
|
||||
|
||||
s = f.add_service('ec2')
|
||||
s.add_standard_endpoints(public='http://public.com:8773/services/Cloud',
|
||||
internal='http://internal:8773/services/Cloud',
|
||||
admin='http://admin:8773/services/Admin',
|
||||
region=region)
|
||||
|
||||
s = f.add_service('identity')
|
||||
s.add_standard_endpoints(public='http://public.com:5000/v3',
|
||||
internal='http://internal:5000/v3',
|
||||
admin='http://admin:35357/v3',
|
||||
region=region)
|
||||
|
||||
return f
|
||||
|
||||
PROJECT_SCOPED_TOKEN = {
|
||||
'token': {
|
||||
'methods': [
|
||||
'password'
|
||||
],
|
||||
'catalog': [{
|
||||
'endpoints': [{
|
||||
'url':
|
||||
'http://public.com:8776/v1/225da22d3ce34b15877ea70b2a575f58',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url':
|
||||
'http://internal:8776/v1/225da22d3ce34b15877ea70b2a575f58',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url':
|
||||
'http://admin:8776/v1/225da22d3ce34b15877ea70b2a575f58',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'volume'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://public.com:9292/v1',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://internal:9292/v1',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://admin:9292/v1',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'image'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url':
|
||||
'http://public.com:8774/v2/225da22d3ce34b15877ea70b2a575f58',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url':
|
||||
'http://internal:8774/v2/225da22d3ce34b15877ea70b2a575f58',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url':
|
||||
'http://admin:8774/v2/225da22d3ce34b15877ea70b2a575f58',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'compute'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://public.com:8773/services/Cloud',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://internal:8773/services/Cloud',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://admin:8773/services/Admin',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'ec2'
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://public.com:5000/v3',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://internal:5000/v3',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://admin:35357/v3',
|
||||
'region': 'RegionOne',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'identity'
|
||||
}],
|
||||
'expires_at': '2010-11-01T03:32:15-05:00',
|
||||
'user': {
|
||||
'domain': {
|
||||
'id': '4e6893b7ba0b4006840c3845660b86ed',
|
||||
'name': 'exampledomain'
|
||||
},
|
||||
'id': 'c4da488862bd435c9e6c0275a0d0e49a',
|
||||
'name': 'exampleuser',
|
||||
},
|
||||
'roles': [
|
||||
{
|
||||
"id": "76e72a",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/roles/76e72a"
|
||||
},
|
||||
"name": "admin"
|
||||
},
|
||||
{
|
||||
"id": "f4f392",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/roles/f4f392"
|
||||
},
|
||||
"name": "member"
|
||||
}
|
||||
],
|
||||
'project': {
|
||||
'domain': {
|
||||
'id': '4e6893b7ba0b4006840c3845660b86ed',
|
||||
'name': 'exampledomain'
|
||||
},
|
||||
'id': '225da22d3ce34b15877ea70b2a575f58',
|
||||
'name': 'exampleproject',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
AUTH_SUBJECT_TOKEN = '3e2813b7ba0b4006840c3825860b86ed'
|
||||
|
||||
@@ -279,142 +125,58 @@ AUTH_RESPONSE_HEADERS = {
|
||||
'X-Subject-Token': AUTH_SUBJECT_TOKEN
|
||||
}
|
||||
|
||||
AUTH_RESPONSE_BODY = {
|
||||
'token': {
|
||||
'methods': [
|
||||
'password'
|
||||
],
|
||||
'expires_at': '2010-11-01T03:32:15-05:00',
|
||||
'project': {
|
||||
'domain': {
|
||||
'id': '123',
|
||||
'name': 'aDomain'
|
||||
},
|
||||
'id': '345',
|
||||
'name': 'aTenant'
|
||||
},
|
||||
'user': {
|
||||
'domain': {
|
||||
'id': '1',
|
||||
'name': 'aDomain'
|
||||
},
|
||||
'id': '567',
|
||||
'name': 'test',
|
||||
'roles': [
|
||||
{
|
||||
"id": "76e72a",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/roles/76e72a"
|
||||
},
|
||||
"name": "admin"
|
||||
},
|
||||
{
|
||||
"id": "f4f392",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/roles/f4f392"
|
||||
},
|
||||
"name": "member"
|
||||
}
|
||||
],
|
||||
},
|
||||
'issued_at': '2010-10-31T03:32:15-05:00',
|
||||
'catalog': [{
|
||||
'endpoints': [{
|
||||
'url': 'https://compute.north.host/novapi/public',
|
||||
'region': 'North',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'https://compute.north.host/novapi/internal',
|
||||
'region': 'North',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'https://compute.north.host/novapi/admin',
|
||||
'region': 'North',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'compute',
|
||||
'name': 'nova',
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://swift.north.host/swiftapi/public',
|
||||
'region': 'South',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://swift.north.host/swiftapi/internal',
|
||||
'region': 'South',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://swift.north.host/swiftapi/admin',
|
||||
'region': 'South',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'object-store',
|
||||
'name': 'swift',
|
||||
}, {
|
||||
'endpoints': [{
|
||||
'url': 'http://glance.north.host/glanceapi/public',
|
||||
'region': 'North',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://glance.north.host/glanceapi/internal',
|
||||
'region': 'North',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://glance.north.host/glanceapi/admin',
|
||||
'region': 'North',
|
||||
'interface': 'admin'
|
||||
}, {
|
||||
'url': 'http://glance.south.host/glanceapi/public',
|
||||
'region': 'South',
|
||||
'interface': 'public'
|
||||
}, {
|
||||
'url': 'http://glance.south.host/glanceapi/internal',
|
||||
'region': 'South',
|
||||
'interface': 'internal'
|
||||
}, {
|
||||
'url': 'http://glance.south.host/glanceapi/admin',
|
||||
'region': 'South',
|
||||
'interface': 'admin'
|
||||
}],
|
||||
'type': 'image',
|
||||
'name': 'glance',
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
TRUST_TOKEN = {
|
||||
'token': {
|
||||
'methods': [
|
||||
'password'
|
||||
],
|
||||
'catalog': {},
|
||||
'expires_at': '2010-11-01T03:32:15-05:00',
|
||||
"OS-TRUST:trust": {
|
||||
"id": "fe0aef",
|
||||
"impersonation": False,
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/trusts/fe0aef"
|
||||
},
|
||||
"trustee_user": {
|
||||
"id": "0ca8f6",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/users/0ca8f6"
|
||||
}
|
||||
},
|
||||
"trustor_user": {
|
||||
"id": "bd263c",
|
||||
"links": {
|
||||
"self": "http://identity:35357/v3/users/bd263c"
|
||||
}
|
||||
}
|
||||
},
|
||||
'user': {
|
||||
'domain': {
|
||||
'id': '4e6893b7ba0b4006840c3845660b86ed',
|
||||
'name': 'exampledomain'
|
||||
},
|
||||
'id': '0ca8f6',
|
||||
'name': 'exampleuser',
|
||||
}
|
||||
}
|
||||
}
|
||||
def auth_response_body():
|
||||
f = fixture.V3Token(user_id='567',
|
||||
user_name='test',
|
||||
user_domain_id='1',
|
||||
user_domain_name='aDomain',
|
||||
expires='2010-11-01T03:32:15-05:00',
|
||||
project_domain_id='123',
|
||||
project_domain_name='aDomain',
|
||||
project_id='345',
|
||||
project_name='aTenant')
|
||||
|
||||
f.add_role(id='76e72a', name='admin')
|
||||
f.add_role(id='f4f392', name='member')
|
||||
|
||||
s = f.add_service('compute', name='nova')
|
||||
s.add_standard_endpoints(
|
||||
public='https://compute.north.host/novapi/public',
|
||||
internal='https://compute.north.host/novapi/internal',
|
||||
admin='https://compute.north.host/novapi/admin',
|
||||
region='North')
|
||||
|
||||
s = f.add_service('object-store', name='swift')
|
||||
s.add_standard_endpoints(
|
||||
public='http://swift.north.host/swiftapi/public',
|
||||
internal='http://swift.north.host/swiftapi/internal',
|
||||
admin='http://swift.north.host/swiftapi/admin',
|
||||
region='South')
|
||||
|
||||
s = f.add_service('image', name='glance')
|
||||
s.add_standard_endpoints(
|
||||
public='http://glance.north.host/glanceapi/public',
|
||||
internal='http://glance.north.host/glanceapi/internal',
|
||||
admin='http://glance.north.host/glanceapi/admin',
|
||||
region='North')
|
||||
|
||||
s.add_standard_endpoints(
|
||||
public='http://glance.south.host/glanceapi/public',
|
||||
internal='http://glance.south.host/glanceapi/internal',
|
||||
admin='http://glance.south.host/glanceapi/admin',
|
||||
region='South')
|
||||
|
||||
return f
|
||||
|
||||
|
||||
def trust_token():
|
||||
return fixture.V3Token(user_id='0ca8f6',
|
||||
user_name='exampleuser',
|
||||
user_domain_id='4e6893b7ba0b4006840c3845660b86ed',
|
||||
user_domain_name='exampledomain',
|
||||
expires='2010-11-01T03:32:15-05:00',
|
||||
trust_id='fe0aef',
|
||||
trust_impersonation=False,
|
||||
trustee_user_id='0ca8f6',
|
||||
trustor_user_id='bd263c')
|
||||
|
@@ -21,9 +21,9 @@ from keystoneclient.tests.v3 import utils
|
||||
TOKEN_RESPONSE = utils.TestResponse({
|
||||
"headers": client_fixtures.AUTH_RESPONSE_HEADERS
|
||||
})
|
||||
UNSCOPED_TOKEN = client_fixtures.UNSCOPED_TOKEN
|
||||
DOMAIN_SCOPED_TOKEN = client_fixtures.DOMAIN_SCOPED_TOKEN
|
||||
PROJECT_SCOPED_TOKEN = client_fixtures.PROJECT_SCOPED_TOKEN
|
||||
UNSCOPED_TOKEN = client_fixtures.unscoped_token()
|
||||
DOMAIN_SCOPED_TOKEN = client_fixtures.domain_scoped_token()
|
||||
PROJECT_SCOPED_TOKEN = client_fixtures.project_scoped_token()
|
||||
|
||||
|
||||
class AccessInfoTest(utils.TestCase):
|
||||
@@ -33,8 +33,7 @@ class AccessInfoTest(utils.TestCase):
|
||||
|
||||
self.assertTrue(auth_ref)
|
||||
self.assertIn('methods', auth_ref)
|
||||
self.assertIn('catalog', auth_ref)
|
||||
self.assertFalse(auth_ref['catalog'])
|
||||
self.assertNotIn('catalog', auth_ref)
|
||||
|
||||
self.assertEqual(auth_ref.auth_token,
|
||||
'3e2813b7ba0b4006840c3825860b86ed')
|
||||
|
@@ -25,7 +25,7 @@ class KeystoneClientTest(utils.TestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_unscoped_init(self):
|
||||
self.stub_auth(json=client_fixtures.UNSCOPED_TOKEN)
|
||||
self.stub_auth(json=client_fixtures.unscoped_token())
|
||||
|
||||
c = client.Client(user_domain_name='exampledomain',
|
||||
username='exampleuser',
|
||||
@@ -39,7 +39,7 @@ class KeystoneClientTest(utils.TestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_domain_scoped_init(self):
|
||||
self.stub_auth(json=client_fixtures.DOMAIN_SCOPED_TOKEN)
|
||||
self.stub_auth(json=client_fixtures.domain_scoped_token())
|
||||
|
||||
c = client.Client(user_id='c4da488862bd435c9e6c0275a0d0e49a',
|
||||
password='password',
|
||||
@@ -55,7 +55,7 @@ class KeystoneClientTest(utils.TestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_project_scoped_init(self):
|
||||
self.stub_auth(json=client_fixtures.PROJECT_SCOPED_TOKEN),
|
||||
self.stub_auth(json=client_fixtures.project_scoped_token()),
|
||||
|
||||
c = client.Client(user_id='c4da488862bd435c9e6c0275a0d0e49a',
|
||||
password='password',
|
||||
@@ -72,7 +72,7 @@ class KeystoneClientTest(utils.TestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_auth_ref_load(self):
|
||||
self.stub_auth(json=client_fixtures.PROJECT_SCOPED_TOKEN)
|
||||
self.stub_auth(json=client_fixtures.project_scoped_token())
|
||||
|
||||
c = client.Client(user_id='c4da488862bd435c9e6c0275a0d0e49a',
|
||||
password='password',
|
||||
@@ -92,8 +92,8 @@ class KeystoneClientTest(utils.TestCase):
|
||||
def test_auth_ref_load_with_overridden_arguments(self):
|
||||
new_auth_url = 'https://newkeystone.com/v3'
|
||||
|
||||
self.stub_auth(json=client_fixtures.PROJECT_SCOPED_TOKEN)
|
||||
self.stub_auth(json=client_fixtures.PROJECT_SCOPED_TOKEN,
|
||||
self.stub_auth(json=client_fixtures.project_scoped_token())
|
||||
self.stub_auth(json=client_fixtures.project_scoped_token(),
|
||||
base_url=new_auth_url)
|
||||
|
||||
c = client.Client(user_id='c4da488862bd435c9e6c0275a0d0e49a',
|
||||
@@ -114,7 +114,7 @@ class KeystoneClientTest(utils.TestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_trust_init(self):
|
||||
self.stub_auth(json=client_fixtures.TRUST_TOKEN)
|
||||
self.stub_auth(json=client_fixtures.trust_token())
|
||||
|
||||
c = client.Client(user_domain_name='exampledomain',
|
||||
username='exampleuser',
|
||||
@@ -169,12 +169,12 @@ class KeystoneClientTest(utils.TestCase):
|
||||
|
||||
@httpretty.activate
|
||||
def test_management_url_is_updated_with_project(self):
|
||||
self._management_url_is_updated(client_fixtures.PROJECT_SCOPED_TOKEN,
|
||||
self._management_url_is_updated(client_fixtures.project_scoped_token(),
|
||||
project_name='exampleproject')
|
||||
|
||||
@httpretty.activate
|
||||
def test_management_url_is_updated_with_domain(self):
|
||||
self._management_url_is_updated(client_fixtures.DOMAIN_SCOPED_TOKEN,
|
||||
self._management_url_is_updated(client_fixtures.domain_scoped_token(),
|
||||
domain_name='exampledomain')
|
||||
|
||||
@httpretty.activate
|
||||
@@ -182,7 +182,7 @@ class KeystoneClientTest(utils.TestCase):
|
||||
# NOTE(jamielennox): this is deprecated behaviour that should be
|
||||
# removed ASAP, however must remain compatible.
|
||||
|
||||
self.stub_auth(json=client_fixtures.AUTH_RESPONSE_BODY)
|
||||
self.stub_auth(json=client_fixtures.auth_response_body())
|
||||
|
||||
cl = client.Client(username='exampleuser',
|
||||
password='password',
|
||||
|
@@ -10,8 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
|
||||
from keystoneclient import access
|
||||
from keystoneclient import exceptions
|
||||
from keystoneclient.tests.v3 import client_fixtures
|
||||
@@ -21,8 +19,7 @@ from keystoneclient.tests.v3 import utils
|
||||
class ServiceCatalogTest(utils.TestCase):
|
||||
def setUp(self):
|
||||
super(ServiceCatalogTest, self).setUp()
|
||||
self.AUTH_RESPONSE_BODY = copy.deepcopy(
|
||||
client_fixtures.AUTH_RESPONSE_BODY)
|
||||
self.AUTH_RESPONSE_BODY = client_fixtures.auth_response_body()
|
||||
self.RESPONSE = utils.TestResponse({
|
||||
"headers": client_fixtures.AUTH_RESPONSE_HEADERS
|
||||
})
|
||||
@@ -202,7 +199,7 @@ class ServiceCatalogTest(utils.TestCase):
|
||||
def test_service_catalog_without_name(self):
|
||||
pr_auth_ref = access.AccessInfo.factory(
|
||||
resp=None,
|
||||
body=client_fixtures.PROJECT_SCOPED_TOKEN)
|
||||
body=client_fixtures.project_scoped_token())
|
||||
pr_sc = pr_auth_ref.service_catalog
|
||||
|
||||
# this will work because there are no service names on that token
|
||||
|
Reference in New Issue
Block a user