Now that you have repoze.who working, it’s time to change its setup slightly in order for us to skip authentication while testing protected areas.
The way to change it depends on the way you configure repoze.who:
If the PasteDeploy factory for your application looks like this:
from repoze.who.middleware import PluggableAuthenticationMiddleware
def make_application(global_config, **local_conf):
# (...)
app = PluggableAuthenticationMiddleware(
app,
identifiers,
authenticators,
challengers,
mdproviders,
classifier,
challenge_decider)
# (...)
return app
You should replace repoze.who.middleware.PluggableAuthenticationMiddleware with repoze.who.plugins.testutil.make_middleware():
from repoze.who.plugins.testutil import make_middleware
def make_application(global_config, **local_conf):
# (...)
app = make_middleware(
local_conf.get('skip_authentication'),
app,
identifiers,
authenticators,
challengers,
mdproviders,
classifier,
challenge_decider)
# (...)
return app
Attention
Note that repoze.who.plugins.testutil.make_middleware() receives one more argument, before app.
If you’re using repoze.what using a code snippet like the one below,
from repoze.what.middleware import setup_auth
def make_application(global_config, **local_conf):
# (...)
app = setup_auth(
app,
groups,
permissions,
identifiers=identifiers,
authenticators=authenticators,
challengers=challengers)
# (...)
Then you should add the skip_authentication keyword argument to setup_auth():
from repoze.what.middleware import setup_auth
def make_application(global_config, **local_conf):
# (...)
app = setup_auth(
app,
groups,
permissions,
identifiers=identifiers,
authenticators=authenticators,
challengers=challengers,
skip_authentication=local_conf.get('skip_authentication'))
# (...)
That’s it.
If the PasteDeploy factory for your application looks like this:
from repoze.who.config import make_middleware_with_config
def make_application(global_config, **local_conf):
# (...)
app = make_middleware_with_config(
app,
global_conf,
local_conf['who.config_file'],
local_conf['who.log_file'],
local_conf['who.log_level'])
# (...)
return app
You should replace repoze.who.config.make_middleware_with_config with repoze.who.plugins.testutil.make_middleware_with_config():
from repoze.who.plugins.testutil import make_middleware_with_config
def make_application(global_config, **local_conf):
# (...)
app = make_middleware_with_config(
app,
global_conf,
local_conf['who.config_file'],
local_conf['who.log_file'],
local_conf['who.log_level'],
skip_authentication=local_conf.get('skip_authentication'))
# (...)
return app
Attention
Note that repoze.who.plugins.testutil.make_middleware_with_config() receives one more argument: skip_authentication.
Tip
You may want to run your application now to check that, so far, nothing seems to have changed.