PluggableAuthenticationMiddleware proxy to forge authentication, without bypassing identification.
Setup authentication in an easy to forge way.
All the arguments received will be passed as is to repoze.who.middleware.PluggableAuthenticationMiddleware, with one instance of AuthenticationForgerPlugin in:
Internally, it will also set remote_user_key to 'repoze.who.testutil.userid', so that you can use the standard 'REMOTE_USER' in your tests.
The metadata providers won’t be modified.
Return the requested authentication middleware.
Parameters: |
|
---|
args and kwargs are the positional and named arguments, respectively, to be passed to the relevant authentication middleware.
Proxy repoze.who.config.make_middleware_with_config() to skip authentication when required.
If skip_authentication evaluates to True, then the returned middleware will be an instance of AuthenticationForgerMiddleware.
repoze.who plugin to forge authentication easily and bypass repoze.who challenges.
This plugin enables you to write identifier and challenger-independent tests. As a result, your protected areas will be easier to test:
To forge authentication, without bypassing identification (i.e., running MD providers), you can use the following WebTest-powered test:
def test_authorization_granted(self):
'''The right subject must get what she requested'''
environ = {'REMOTE_USER': 'manager'}
resp = self.app.get('/admin/', extra_environ=environ, status=200)
assert 'some text' in resp.body
As you can see, this is an identifier-independent way to forge authentication.
To check that authorization was denied, in a challenger-independent way, you can use:
def test_authorization_denied_anonymous(self):
'''Anonymous users must get a 401 page'''
self.app.get('/admin/', status=401)
def test_authorization_denied_authenticated(self):
'''Authenticated users must get a 403 page'''
environ = {'REMOTE_USER': 'editor'}
self.app.get('/admin/', extra_environ=environ, status=403)
Parameters: |
|
---|
Pre-authenticate using the user Id found in the relevant environ item, if any.
The user Id. found will be put into identity['fake-userid'], for authenticate().
Do nothing
Do nothing
Turn the value in identity['fake-userid'] into the remote user’s name.
Finally, it removes identity['fake-userid'] so that it won’t reach the WSGI application.
Return a 401 page unconditionally.