Changeset 14670


Ignore:
Timestamp:
6 Apr 2017, 12:20:41 (8 years ago)
Author:
uli
Message:

Add IKofaPluggable to update local PAU.

The new plugin enables updating of sites that have
yet no XMLRPC authentication enabled.

The plugin can be removed after updating all sites.

New sites (university-instances) do not need this
plugin at all.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/authentication.py

    r14669 r14670  
    645645                    pass
    646646        return
     647
     648
     649class UpdatePAUPlugin(grok.GlobalUtility):
     650    """A plugin that updates a local PAU.
     651
     652    We insert an 'xmlrpc-credentials' PAU-plugin into a sites PAU if it is not
     653    present already. There must be 'credentials' plugin registered already.
     654
     655    XXX: This Plugin fixes a shortcoming of waeup.kofa 1.5. Sites created or
     656         updated afterwards do not need this plugin and it should be removed.
     657    """
     658    grok.implements(IKofaPluggable)
     659    grok.name('site-pluggable-auth')
     660
     661    def setup(self, site, name, logger):
     662        return
     663
     664    def update(self, site, name, logger):
     665        pau = site.getSiteManager()['PluggableAuthentication']
     666        if 'xmlrpc-credentials' in pau.credentialsPlugins:
     667            return
     668        plugins = list(pau.credentialsPlugins)
     669        plugins.insert(plugins.index('credentials'), 'xmlrpc-credentials')
     670        pau.credentialsPlugins = tuple(plugins)
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_authentication.py

    r14668 r14670  
    3131from zope.securitypolicy.interfaces import IPrincipalRoleManager
    3232from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer
     33from waeup.kofa.app import University
    3334from waeup.kofa.authentication import (
    3435    UserAuthenticatorPlugin, Account, KofaPrincipalInfo, FailedLoginInfo,
    3536    get_principal_role_manager, UsersPlugin, KofaXMLRPCCredentialsPlugin,
    36     setup_authentication)
     37    setup_authentication, UpdatePAUPlugin)
    3738from waeup.kofa.interfaces import (
    3839    IAuthPluginUtility, IUserAccount, IFailedLoginInfo, IKofaPrincipalInfo,
     
    368369    pass
    369370
     371
     372def get_logger():
     373    logger = logging.getLogger('waeup.test')
     374    stream = StringIO()
     375    handler = logging.StreamHandler(stream)
     376    logger.setLevel(logging.DEBUG)
     377    logger.propagate = False
     378    logger.addHandler(handler)
     379    return logger, stream
     380
     381
    370382class UsersPluginTests(unittest.TestCase):
    371383
     
    375387        self.site['users'] = grok.Container()
    376388        return
    377 
    378     def get_logger(self):
    379         logger = logging.getLogger('waeup.test')
    380         stream = StringIO()
    381         handler = logging.StreamHandler(stream)
    382         logger.setLevel(logging.DEBUG)
    383         logger.propagate = False
    384         logger.addHandler(handler)
    385         return logger, stream
    386389
    387390    def test_ifaces(self):
     
    395398        # make sure user accounts are updated properly.
    396399        plugin = UsersPlugin()
    397         logger, stream = self.get_logger()
     400        logger, stream = get_logger()
    398401        plugin.update(self.site, 'app', logger)
    399402        stream.seek(0)
    400403        self.assertEqual(stream.read(), '')
    401404        self.site['users']['bob'] = FakeUserAccount()
    402         logger, stream = self.get_logger()
     405        logger, stream = get_logger()
    403406        plugin.update(self.site, 'app', logger)
    404407        stream.seek(0)
     
    412415        self.assertTrue('attribute failed_logins added' in log_content)
    413416        return
     417
     418
     419class TestUpdatePAUPlugin(FunctionalTestCase):
     420
     421    layer = FunctionalLayer
     422
     423    def setUp(self):
     424        super(TestUpdatePAUPlugin, self).setUp()
     425        self.getRootFolder()['app'] = University()
     426        self.site = self.getRootFolder()['app']
     427
     428    def tearDown(self):
     429        clearSite()
     430        super(TestUpdatePAUPlugin, self).tearDown()
     431
     432    def get_pau(self):
     433        # the PAU is registered as a local utility in local site manager.
     434        # the name is derived from class name.
     435        pau = self.site.getSiteManager()['PluggableAuthentication']
     436        assert pau is not None
     437        return pau
     438
     439    def test_update_outdated(self):
     440        # we can update outdated sites.
     441        plugin = UpdatePAUPlugin()
     442        logger, stream = get_logger()
     443        pau = self.get_pau()
     444        pau.credentialsPlugins = ('foo', 'credentials', 'bar')
     445        plugin.update(self.site, 'xmlrpc-credentials', logger)
     446        assert 'xmlrpc-credentials' in pau.credentialsPlugins
     447        assert pau.credentialsPlugins.index('xmlrpc-credentials') == 1
     448
     449    def test_update_uptodate(self):
     450        # we cope with already updated sites.
     451        plugin = UpdatePAUPlugin()
     452        logger, stream = get_logger()
     453        pau = self.get_pau()
     454        pau.credentialsPlugins = ('foo', 'xmlrpc-credentials', 'bar')
     455        plugin.update(self.site, 'xmlrpc-credentials', logger)
     456        assert pau.credentialsPlugins.count('xmlrpc-credentials') == 1
Note: See TracChangeset for help on using the changeset viewer.