Ejemplo n.º 1
0
 def test_context_hook_after_miss_context(self):
     headers = fake_headers(admin=True)
     reqstate = FakeRequestState(headers=headers)
     reqstate.request.context = {}
     context_hook = hooks.ContextHook(None)
     context_hook.after(reqstate)
     self.assertNotIn('Openstack-Request-Id', reqstate.response.headers)
Ejemplo n.º 2
0
def setup_app(pecan_config=None, extra_hooks=None):
    if not pecan_config:
        pecan_config = get_pecan_config()
    pecan.configuration.set_config(dict(pecan_config), overwrite=True)

    gmr_opts.set_defaults(cfg.CONF)
    gmr.TextGuruMeditation.setup_autorun(version, conf=cfg.CONF)

    app_hooks = [hooks.ConfigHook(),
                 hooks.DBHook(),
                 hooks.EngineAPIHook(),
                 hooks.ContextHook(pecan_config.app.acl_public_routes),
                 hooks.NoExceptionTracebackHook(),
                 hooks.PublicUrlHook()]
    if extra_hooks:
        app_hooks.extend(extra_hooks)

    app = pecan.make_app(
        pecan_config.app.root,
        static_root=pecan_config.app.static_root,
        debug=False,
        force_canonical=getattr(pecan_config.app, 'force_canonical', True),
        hooks=app_hooks,
        wrap_app=middleware.ParsableErrorMiddleware,
    )

    app = auth_token.AuthTokenMiddleware(
        app, dict(cfg.CONF),
        public_api_routes=pecan_config.app.acl_public_routes)

    return app
Ejemplo n.º 3
0
 def test_context_hook_after_add_request_id(self, mock_ctx):
     headers = fake_headers(admin=True)
     reqstate = FakeRequestState(headers=headers)
     reqstate.set_context()
     reqstate.request.context.request_id = 'fake-id'
     context_hook = hooks.ContextHook(None)
     context_hook.after(reqstate)
     self.assertIn('Openstack-Request-Id', reqstate.response.headers)
     self.assertEqual('fake-id',
                      reqstate.response.headers['Openstack-Request-Id'])
Ejemplo n.º 4
0
 def test_context_hook(self, mock_ctx):
     headers = fake_headers(admin=True)
     reqstate = FakeRequestState(headers=headers)
     context_hook = hooks.ContextHook(None)
     context_hook.before(reqstate)
     mock_ctx.assert_called_with(auth_token=headers['X-Auth-Token'],
                                 user=headers['X-User-Id'],
                                 user_name=headers['X-User-Name'],
                                 tenant=headers['X-Project-Id'],
                                 project_name=headers['X-Project-Name'],
                                 domain=headers['X-User-Domain-Id'],
                                 domain_name=headers['X-User-Domain-Name'],
                                 is_admin=True,
                                 roles=headers['X-Roles'].split(','))
Ejemplo n.º 5
0
 def test_context_hook_public_api(self,
                                  mock_policy,
                                  mock_ctx,
                                  is_admin=True):
     headers = fake_headers(admin=True)
     env = {'is_public_api': True}
     reqstate = FakeRequestState(headers=headers, environ=env)
     context_hook = hooks.ContextHook(None)
     mock_policy.return_value = is_admin
     context_hook.before(reqstate)
     mock_ctx.assert_called_with(auth_token=headers['X-Auth-Token'],
                                 user=headers['X-User-Id'],
                                 user_name=headers['X-User-Name'],
                                 tenant=headers['X-Project-Id'],
                                 project_name=headers['X-Project-Name'],
                                 domain=headers['X-User-Domain-Id'],
                                 domain_name=headers['X-User-Domain-Name'],
                                 is_admin=True,
                                 roles=headers['X-Roles'].split(','))