Tres Seaver
2010-10-01 d7f61380bb37d911239adf667ce0dd7d773b5ca3
Fix examples, tests which used the deprecated plugins.
3 files modified
57 ■■■■ changed files
repoze/who/middleware.py 34 ●●●● patch | view | raw | blame | history
repoze/who/tests/test_config.py 18 ●●●●● patch | view | raw | blame | history
repoze/who/tests/test_middleware.py 5 ●●●● patch | view | raw | blame | history
repoze/who/middleware.py
@@ -174,13 +174,13 @@
def make_test_middleware(app, global_conf):
    """ Functionally equivalent to
    [plugin:form]
    use = repoze.who.plugins.form.FormPlugin
    rememberer_name = cookie
    login_form_qs=__do_login
    [plugin:redirector]
    use = repoze.who.plugins.redirector.RedirectorPlugin
    login_url = /login.html
    [plugin:cookie]
    use = repoze.who.plugins.cookie:InsecureCookiePlugin
    [plugin:auth_tkt]
    use = repoze.who.plugins.auth_tkt:AuthTktCookiePlugin
    secret = SEEKRIT
    cookie_name = oatmeal
    [plugin:basicauth]
@@ -197,18 +197,18 @@
    challenge_decider = repoze.who.classifiers:default_challenge_decider
    [identifiers]
    plugins = form:browser cookie basicauth
    plugins = authtkt basicauth
    [authenticators]
    plugins = htpasswd
    plugins = authtkt htpasswd
    [challengers]
    plugins = form:browser basicauth
    plugins = redirector:browser basicauth
    """
    # be able to test without a config file
    from repoze.who.plugins.basicauth import BasicAuthPlugin
    from repoze.who.plugins.auth_tkt import AuthTktCookiePlugin
    from repoze.who.plugins.form import FormPlugin
    from repoze.who.plugins.redirector import RedirectorPlugin
    from repoze.who.plugins.htpasswd import HTPasswdPlugin
    io = StringIO()
    for name, password in [ ('admin', 'admin'), ('chris', 'chris') ]:
@@ -219,12 +219,14 @@
    htpasswd = HTPasswdPlugin(io, cleartext_check)
    basicauth = BasicAuthPlugin('repoze.who')
    auth_tkt = AuthTktCookiePlugin('secret', 'auth_tkt')
    form = FormPlugin('__do_login', rememberer_name='auth_tkt')
    form.classifications = { IIdentifier:['browser'],
                             IChallenger:['browser'] } # only for browser
    identifiers = [('form', form),('auth_tkt',auth_tkt),('basicauth',basicauth)]
    redirector = RedirectorPlugin('/login.html')
    redirector.classifications = {IChallenger: ['browser']} # only for browser
    identifiers = [('auth_tkt', auth_tkt),
                   ('basicauth', basicauth),
                  ]
    authenticators = [('htpasswd', htpasswd)]
    challengers = [('form',form), ('basicauth',basicauth)]
    challengers = [('redirector', redirector),
                   ('basicauth', basicauth)]
    mdproviders = []
    from repoze.who.classifiers import default_request_classifier
    from repoze.who.classifiers import default_challenge_decider
@@ -244,5 +246,3 @@
        log_level = logging.DEBUG
        )
    return middleware
repoze/who/tests/test_config.py
@@ -377,7 +377,7 @@
        middleware = factory(app, global_conf, config_file=path,
                             log_file='STDOUT', log_level='debug')
        api_factory = middleware.api_factory
        self.assertEqual(len(api_factory.identifiers), 3)
        self.assertEqual(len(api_factory.identifiers), 2)
        self.assertEqual(len(api_factory.authenticators), 1)
        self.assertEqual(len(api_factory.challengers), 2)
        self.assertEqual(len(api_factory.mdproviders), 0)
@@ -438,7 +438,7 @@
        path = self._getTempfile(SAMPLE_CONFIG)
        global_conf = {'here': '/'}
        api_factory = factory(global_conf, config_file=path)
        self.assertEqual(len(api_factory.identifiers), 3)
        self.assertEqual(len(api_factory.identifiers), 2)
        self.assertEqual(len(api_factory.authenticators), 1)
        self.assertEqual(len(api_factory.challengers), 2)
        self.assertEqual(len(api_factory.mdproviders), 0)
@@ -451,7 +451,7 @@
        global_conf = {'here': '/'}
        api_factory = factory(global_conf, config_file=path,
                              remote_user_key = 'X-OTHER-USER')
        self.assertEqual(len(api_factory.identifiers), 3)
        self.assertEqual(len(api_factory.identifiers), 2)
        self.assertEqual(len(api_factory.authenticators), 1)
        self.assertEqual(len(api_factory.challengers), 2)
        self.assertEqual(len(api_factory.mdproviders), 0)
@@ -463,17 +463,16 @@
        global_conf = {'here': '/'}
        logger = object()
        api_factory = factory(global_conf, config_file=path, logger=logger)
        self.assertEqual(len(api_factory.identifiers), 3)
        self.assertEqual(len(api_factory.identifiers), 2)
        self.assertEqual(len(api_factory.authenticators), 1)
        self.assertEqual(len(api_factory.challengers), 2)
        self.assertEqual(len(api_factory.mdproviders), 0)
        self.failUnless(api_factory.logger is logger)
SAMPLE_CONFIG = """\
[plugin:form]
use = repoze.who.plugins.form:make_plugin
login_form_qs = __do_login
rememberer_name = auth_tkt
[plugin:redirector]
use = repoze.who.plugins.redirector:make_plugin
login_url = /login.html
[plugin:auth_tkt]
use = repoze.who.plugins.auth_tkt:make_plugin
@@ -497,7 +496,6 @@
[identifiers]
plugins =
    form;browser
    auth_tkt
    basicauth
@@ -506,7 +504,7 @@
[challengers]
plugins =
    form;browser
    redirector;browser
    basicauth
[mdproviders]
repoze/who/tests/test_middleware.py
@@ -506,15 +506,12 @@
        return make_test_middleware
    def test_it_no_WHO_LOG_in_environ(self):
        from repoze.who.interfaces import IIdentifier
        from repoze.who.interfaces import IAuthenticator
        from repoze.who.interfaces import IChallenger
        app = DummyApp()
        factory = self._getFactory()
        global_conf = {'here': '/'}
        middleware = factory(app, global_conf)
        api_factory = middleware.api_factory
        self.assertEqual(len(api_factory.identifiers), 3)
        self.assertEqual(len(api_factory.identifiers), 2)
        self.assertEqual(len(api_factory.authenticators), 1)
        self.assertEqual(len(api_factory.challengers), 2)
        self.assertEqual(len(api_factory.mdproviders), 0)