tests running through, still failing

This commit is contained in:
termie 2011-10-11 15:57:07 -07:00
parent a200e5007e
commit 35ec297406
9 changed files with 76 additions and 47 deletions

View File

@ -1,12 +1,14 @@
class DictKvs(dict):
def set(self, key, value):
return self[key] = value
self[key] = value
INMEMDB = DictKvs()
class KvsIdentity(object):
def __init__(self, db=None):
def __init__(self, options, db=None):
if db is None:
db = DictKvs()
db = INMEMDB
self.db = db
# Public Interface
@ -22,9 +24,12 @@ class KvsIdentity(object):
# Private CRUD for testing
def _create_user(self, id, user):
self.db.set('user-%s' % id, user)
return user
def _create_tenant(self, id, tenant):
self.db.set('tenant-%s' % id, tenant)
return tenant
def _create_token(self, id, token):
self.db.set('token-%s' % id, token)
return token

View File

@ -4,20 +4,14 @@
# backends will make use of them to return something that conforms to their apis
import hflags as flags
from keystonelight import utils
FLAGS = flags.FLAGS
flags.DEFINE_string('identity_driver',
'keystonelight.backends.pam.PamIdentity',
'identity driver to handle identity requests')
class Manager(object):
def __init__(self):
self.driver = utils.import_object(FLAGS.identity_driver)
def __init__(self, options):
self.driver = utils.import_object(options['identity_driver'],
options=options)
self.options = options
def authenticate(self, context, **kwargs):
"""Passthru authentication to the identity driver.

View File

@ -4,6 +4,7 @@
import logging
from keystonelight import service
from keystonelight import wsgi
def _token_to_keystone(token):
return {'id': token,
@ -28,7 +29,6 @@ class KeystoneIdentityController(service.IdentityController):
for x in tenants]}}
class KeystoneTokenController(service.TokenController):
def validate_token(self, context, token_id):
token = super(KeystoneTokenController, self).validate_token(
@ -49,3 +49,4 @@ class KeystoneTokenController(service.TokenController):
'roleRefs': roles,
'username': token['user']['name'],
'tenantId': token['tenant']['id']}}}

View File

@ -5,7 +5,6 @@
import json
import logging
import hflags as flags
import routes
import webob.dec
import webob.exc
@ -16,17 +15,6 @@ from keystonelight import utils
from keystonelight import wsgi
FLAGS = flags.FLAGS
# TODO(termie): these should probably be paste configs instead
flags.DEFINE_string('token_controller',
'keystonelight.service.TokenController',
'token controller')
flags.DEFINE_string('identity_controller',
'keystonelight.service.IdentityController',
'identity controller')
class BaseApplication(wsgi.Application):
@webob.dec.wsgify
def __call__(self, req):
@ -123,8 +111,9 @@ class JsonBodyMiddleware(wsgi.Middleware):
class TokenController(BaseApplication):
"""Validate and pass through calls to TokenManager."""
def __init__(self):
self.token_api = token.Manager()
def __init__(self, options):
self.token_api = token.Manager(options=options)
self.options = options
def validate_token(self, context, token_id):
token_info = self.token_api.validate_token(context, token_id)
@ -140,9 +129,10 @@ class IdentityController(BaseApplication):
a specific driver.
"""
def __init__(self):
self.identity_api = identity.Manager()
self.token_api = token.Manager()
def __init__(self, options):
self.identity_api = identity.Manager(options=options)
self.token_api = token.Manager(options=options)
self.options = options
def authenticate(self, context, **kwargs):
tenant, user, extras = self.identity_api.authenticate(context, **kwargs)
@ -163,27 +153,34 @@ class IdentityController(BaseApplication):
class Router(wsgi.Router):
def __init__(self):
token_controller = utils.import_object(FLAGS.token_controller)
identity_controller = utils.import_object(FLAGS.identity_controller)
def __init__(self, options):
self.options = options
token_controller = utils.import_object(
options['token_controller'],
options=options)
identity_controller = utils.import_object(
options['identity_controller'],
options=options)
mapper = routes.Mapper()
mapper.connect('/v2.0/tokens', controller=identity_controller,
action='authenticate')
mapper.connect('/v2.0/tokens/{token_id}', controller=token_controller,
action='revoke_token',
conditions=dict(method=['DELETE']))
mapper.connect("/v2.0/tenants", controller=identity_controller,
action="get_tenants", conditions=dict(method=["GET"]))
super(Router, self).__init__(mapper)
class AdminRouter(wsgi.Router):
def __init__(self):
token_controller = utils.import_object(FLAGS.token_controller)
identity_controller = utils.import_object(FLAGS.identity_controller)
def __init__(self, options):
self.options = options
token_controller = utils.import_object(
options['token_controller'],
options=options)
identity_controller = utils.import_object(
options['identity_controller'],
options=options)
mapper = routes.Mapper()
mapper.connect('/v2.0/tokens', controller=identity_controller,
@ -195,3 +192,10 @@ class AdminRouter(wsgi.Router):
action='revoke_token',
conditions=dict(method=['DELETE']))
super(AdminRouter, self).__init__(mapper)
def identity_app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)
return Router(conf)

View File

@ -1,15 +1,19 @@
import os
import unittest
from paste import deploy
from keystonelight import wsgi
ROOTDIR = os.path.dirname(os.path.dirname(__file__))
VENDOR = os.path.join(ROOTDIR, 'vendor')
TESTSDIR = os.path.join(ROOTDIR, 'tests')
class TestClient(object):
def __init__(self, endpoint=None, token=None):
self.endpoint = None
def __init__(self, app=None, token=None):
self.app = app
self.token = token
def request(self, method, path, headers=None, body=None):
@ -21,7 +25,7 @@ class TestClient(object):
req.headers[k] = v
if req.body:
req.body = body
return req.get_response(self.endpoint)
return req.get_response(self.app)
def get(self, path, headers=None):
return self.request('GET', path=path, headers=headers)
@ -34,6 +38,14 @@ class TestClient(object):
class TestCase(unittest.TestCase):
def loadapp(self, config):
if not config.startswith('config:'):
config = 'config:%s.conf' % os.path.join(TESTSDIR, config)
return deploy.loadapp(config)
def client(self, app, *args, **kw):
return TestClient(app, *args, **kw)
def assertDictEquals(self, expected, actual):
for k in expected:
self.assertTrue(k in actual,

View File

@ -9,6 +9,9 @@ from keystonelight import identity
STORE = {}
class Manager(object):
def __init__(self, options):
self.options = options
def create_token(self, context, data):
token = uuid.uuid4().hex
STORE[token] = data

View File

@ -33,14 +33,14 @@ def import_class(import_str):
raise
def import_object(import_str):
def import_object(import_str, *args, **kw):
"""Returns an object including a module or module and class."""
try:
__import__(import_str)
return sys.modules[import_str]
except ImportError:
cls = import_class(import_str)
return cls()
return cls(*args, **kw)
# From python 2.7
def check_output(*popenargs, **kwargs):

View File

@ -0,0 +1,5 @@
[app:main]
token_controller = keystonelight.keystone_compat.KeystoneTokenController
identity_controller = keystonelight.keystone_compat.KeystoneIdentityController
identity_driver = keystonelight.backends.kvs.KvsIdentity
paste.app_factory = keystonelight.service:identity_app_factory

View File

@ -73,18 +73,23 @@ class HeadCompatTestCase(CompatTestCase):
def setUp(self):
revdir = checkout_samples('HEAD')
self.sampledir = os.path.join(revdir, SAMPLE_DIR)
self.app = self.loadapp('keystone_compat_HEAD')
self.backend = utils.import_object(
self.app.options['identity_driver'], options=self.app.options)
super(HeadCompatTestCase, self).setUp()
def test_tenants_for_token_unscoped(self):
# get_tenants_for_token
client = self.api.client(token=self.token_foo_unscoped['id'])
client = self.client(self.app, token=self.token_foo_unscoped['id'])
resp = client.get('/v2.0/tenants')
data = json.loads(resp.body)
self.assertDictEquals(self.tenants_for_token, data)
def test_tenants_for_token_scoped(self):
# get_tenants_for_token
client = self.api.client(token=self.token_foo_scoped['id'])
client = self.client(self.app, token=self.token_foo_scoped['id'])
resp = client.get('/v2.0/tenants')
data = json.loads(resp.body)
self.assertDictEquals(self.tenants_for_token, data)