diff --git a/keystonemiddleware/auth_token/__init__.py b/keystonemiddleware/auth_token/__init__.py index 66837c4c..d09f91b6 100644 --- a/keystonemiddleware/auth_token/__init__.py +++ b/keystonemiddleware/auth_token/__init__.py @@ -648,7 +648,10 @@ class AuthProtocol(_BaseAuthProtocol): else: default_config_files = None - self._local_oslo_config = cfg.ConfigOpts() + # For unit tests, support passing in a ConfigOpts in + # oslo_config_config. + self._local_oslo_config = conf.get('oslo_config_config', + cfg.ConfigOpts()) self._local_oslo_config( {}, project=conf['oslo_config_project'], default_config_files=default_config_files, diff --git a/keystonemiddleware/tests/unit/auth_token/base.py b/keystonemiddleware/tests/unit/auth_token/base.py index 94c84d4b..d76572a8 100644 --- a/keystonemiddleware/tests/unit/auth_token/base.py +++ b/keystonemiddleware/tests/unit/auth_token/base.py @@ -13,6 +13,7 @@ import logging import fixtures +from oslo_config import cfg from oslo_config import fixture as cfg_fixture from requests_mock.contrib import fixture as rm_fixture import six @@ -28,29 +29,36 @@ class BaseAuthTokenTestCase(utils.BaseTestCase): super(BaseAuthTokenTestCase, self).setUp() self.requests_mock = self.useFixture(rm_fixture.Fixture()) self.logger = fixtures.FakeLogger(level=logging.DEBUG) - self.cfg = self.useFixture(cfg_fixture.Config()) + self.cfg = self.useFixture(cfg_fixture.Config(conf=cfg.ConfigOpts())) - @classmethod - def create_middleware(cls, cb, conf=None): + def create_middleware(self, cb, conf=None, use_global_conf=False): @webob.dec.wsgify def _do_cb(req): return cb(req) - return auth_token.AuthProtocol(_do_cb, conf or {}) + if use_global_conf: + opts = conf or {} + else: + opts = { + 'oslo_config_project': 'keystonemiddleware', + 'oslo_config_config': self.cfg.conf, + } + opts.update(conf or {}) - @classmethod - def create_simple_middleware(cls, + return auth_token.AuthProtocol(_do_cb, opts) + + def create_simple_middleware(self, status='200 OK', body='', headers=None, - conf=None): + **kwargs): def cb(req): resp = webob.Response(body, status) resp.headers.update(headers or {}) return resp - return cls.create_middleware(cb, conf) + return self.create_middleware(cb, **kwargs) @classmethod def call(cls, middleware, method='GET', path='/', headers=None): diff --git a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py index ab12a6b5..bb572aa3 100644 --- a/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py +++ b/keystonemiddleware/tests/unit/auth_token/test_auth_token_middleware.py @@ -2371,6 +2371,9 @@ class AuthProtocolLoadingTests(BaseAuthTokenMiddlewareTest): project_id = uuid.uuid4().hex + # Register the authentication options + auth.register_conf_options(self.cfg.conf, group=_base.AUTHTOKEN_GROUP) + # configure the authentication options self.cfg.config(auth_plugin='password', username='testuser', @@ -2391,6 +2394,7 @@ class AuthProtocolLoadingTests(BaseAuthTokenMiddlewareTest): return app._identity_server._adapter.auth def test_invalid_plugin_fails_to_initialize(self): + auth.register_conf_options(self.cfg.conf, group=_base.AUTHTOKEN_GROUP) self.cfg.config(auth_plugin=uuid.uuid4().hex, group=_base.AUTHTOKEN_GROUP) @@ -2406,6 +2410,9 @@ class AuthProtocolLoadingTests(BaseAuthTokenMiddlewareTest): username = 'testuser' password = 'testpass' + # Register the authentication options + auth.register_conf_options(self.cfg.conf, group=_base.AUTHTOKEN_GROUP) + # configure the authentication options self.cfg.config(auth_plugin='password', password=password, @@ -2438,6 +2445,9 @@ class AuthProtocolLoadingTests(BaseAuthTokenMiddlewareTest): opts = auth.get_plugin_options('password') self.cfg.register_opts(opts, group=section) + # Register the authentication options + auth.register_conf_options(self.cfg.conf, group=_base.AUTHTOKEN_GROUP) + # configure the authentication options self.cfg.config(auth_section=section, group=_base.AUTHTOKEN_GROUP) self.cfg.config(auth_plugin='password', @@ -2477,6 +2487,9 @@ class TestAuthPluginUserAgentGeneration(BaseAuthTokenMiddlewareTest): opts = auth.get_plugin_options('password') self.cfg.register_opts(opts, group=self.section) + # Register the authentication options + auth.register_conf_options(self.cfg.conf, group=_base.AUTHTOKEN_GROUP) + # configure the authentication options self.cfg.config(auth_section=self.section, group=_base.AUTHTOKEN_GROUP) self.cfg.config(auth_plugin='password', @@ -2520,7 +2533,8 @@ class TestAuthPluginUserAgentGeneration(BaseAuthTokenMiddlewareTest): body = uuid.uuid4().hex with mock.patch('keystonemiddleware.auth_token.pkg_resources', new=fake_pkg_resources): - return self.create_simple_middleware(body=body, conf=conf) + return self.create_simple_middleware(body=body, conf=conf, + use_global_conf=True) def _assert_user_agent(self, app, project, ksm_version): sess = app._identity_server._adapter.session diff --git a/keystonemiddleware/tests/unit/auth_token/test_user_auth_plugin.py b/keystonemiddleware/tests/unit/auth_token/test_user_auth_plugin.py index 83da69bd..52d29737 100644 --- a/keystonemiddleware/tests/unit/auth_token/test_user_auth_plugin.py +++ b/keystonemiddleware/tests/unit/auth_token/test_user_auth_plugin.py @@ -15,6 +15,7 @@ import uuid from keystoneclient import auth from keystoneclient import fixture +from keystonemiddleware.auth_token import _base from keystonemiddleware.tests.unit.auth_token import base # NOTE(jamielennox): just some sample values that we can use for testing @@ -31,6 +32,11 @@ class BaseUserPluginTests(object): opts = auth.get_plugin_class(auth_plugin).get_options() self.cfg.register_opts(opts, group=group) + # Since these tests cfg.config() themselves rather than waiting for + # auth_token to do it on __init__ we need to register the base auth + # options (e.g., auth_plugin) + auth.register_conf_options(self.cfg.conf, group=_base.AUTHTOKEN_GROUP) + self.cfg.config(group=group, auth_plugin=auth_plugin, **kwargs)