Changeset 14670 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 6 Apr 2017, 12:20:41 (8 years ago)
- 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 645 645 pass 646 646 return 647 648 649 class 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 31 31 from zope.securitypolicy.interfaces import IPrincipalRoleManager 32 32 from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer 33 from waeup.kofa.app import University 33 34 from waeup.kofa.authentication import ( 34 35 UserAuthenticatorPlugin, Account, KofaPrincipalInfo, FailedLoginInfo, 35 36 get_principal_role_manager, UsersPlugin, KofaXMLRPCCredentialsPlugin, 36 setup_authentication )37 setup_authentication, UpdatePAUPlugin) 37 38 from waeup.kofa.interfaces import ( 38 39 IAuthPluginUtility, IUserAccount, IFailedLoginInfo, IKofaPrincipalInfo, … … 368 369 pass 369 370 371 372 def 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 370 382 class UsersPluginTests(unittest.TestCase): 371 383 … … 375 387 self.site['users'] = grok.Container() 376 388 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 = False384 logger.addHandler(handler)385 return logger, stream386 389 387 390 def test_ifaces(self): … … 395 398 # make sure user accounts are updated properly. 396 399 plugin = UsersPlugin() 397 logger, stream = self.get_logger()400 logger, stream = get_logger() 398 401 plugin.update(self.site, 'app', logger) 399 402 stream.seek(0) 400 403 self.assertEqual(stream.read(), '') 401 404 self.site['users']['bob'] = FakeUserAccount() 402 logger, stream = self.get_logger()405 logger, stream = get_logger() 403 406 plugin.update(self.site, 'app', logger) 404 407 stream.seek(0) … … 412 415 self.assertTrue('attribute failed_logins added' in log_content) 413 416 return 417 418 419 class 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.