Changeset 5897


Ignore:
Timestamp:
30 Mar 2011, 14:33:03 (14 years ago)
Author:
uli
Message:

Make sure applicants auth components are registered on University
creation.

The applicants package defines two plugins for the
PluggableAuthenticationUtility? (PAU): an authenticator plugin and a
credentials plugin. While the credentials plugin knows, where to look
in a posted form for credentials (accesscode or PIN), the
authenticator plugin knows how to check these credentials against
local access codes. Both plugins have to be registered with the PAU of
any University instance to become active (admins can also use the ZMI
to register/unregister auth components). This is not done
automatically yet while it should. The test currently fails and we
have to fix that behaviour, before tests will pass again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_authentication.py

    r5817 r5897  
    2121##
    2222import grok
     23import shutil
     24import tempfile
    2325import unittest
    24 from zope.component import provideAdapter
     26from zope.app.testing.functional import FunctionalTestCase
     27from zope.authentication.interfaces import IAuthentication
     28from zope.component import provideAdapter, getUtility
    2529from zope.component.hooks import setSite, clearSite
    2630from zope.interface import verify
     
    3034from zope.session.interfaces import ISession
    3135from zope.site import LocalSiteManager
     36from zope.testbrowser.testing import Browser
    3237from zope.testing import cleanup
     38from waeup.sirp.testing import FunctionalLayer
     39from waeup.sirp.app import University
    3340from waeup.sirp.applicants.authentication import (
    3441    ApplicantsAuthenticatorPlugin, WAeUPApplicantCredentialsPlugin,
    3542    ApplicantCredentials, AuthenticatedApplicantPrincipalFactory,
    3643    ApplicantPrincipalInfo, ApplicantPrincipal)
     44
    3745
    3846class FakeBatch(dict):
     
    289297        self.assertEqual(principal.id, 'APP-1-1234567890')
    290298        return
     299
     300class PAUSetupTest(FunctionalTestCase):
     301    # Check correct setup of authentication components in the
     302    # applicants subpackage.
     303
     304    # When a university is created, we want by default have our local
     305    # authentication components (an authenticator plugin and a
     306    # credentials plugin) to be registered with the local PAU. Admins
     307    # can remove these components on the fly later-on if they wish.
     308   
     309    layer = FunctionalLayer
     310   
     311    def setUp(self):
     312        super(PAUSetupTest, self).setUp()
     313
     314        # Setup a sample site for each test
     315        app = University()
     316        self.dc_root = tempfile.mkdtemp()
     317        app['datacenter'].setStoragePath(self.dc_root)
     318
     319        # Prepopulate the ZODB...
     320        self.getRootFolder()['app'] = app
     321        self.app = self.getRootFolder()['app']
     322        self.browser = Browser()
     323        self.browser.handleErrors = False
     324
     325    def tearDown(self):
     326        super(PAUSetupTest, self).tearDown()
     327        shutil.rmtree(self.dc_root)
     328
     329    def test_extra_auth_plugins_installed(self):
     330        # Check whether the auth plugins defined in here are setup
     331        # automatically when a university is created
     332
     333        # Get the PAU responsible for the local site ('app')
     334        pau = getUtility(IAuthentication, context=self.app)
     335        cred_plugins = pau.getCredentialsPlugins()
     336        auth_plugins = pau.getAuthenticatorPlugins()
     337        cred_names = [name for name, plugin in cred_plugins]
     338        auth_names = [name for name, plugin in auth_plugins]
    291339       
     340        # Make sure our local ApplicantsAuthenticatorPlugin is registered...
     341        self.assertTrue('applicants' in auth_names)
     342        # Make sure our local WAeUPApplicantCredentialsPlugin is registered...
     343        self.assertTrue('applicant_credentials' in cred_names)
     344        return
     345
    292346def test_suite():
    293347    suite = unittest.TestSuite()
     
    295349        AuthenticatorPluginTest, CredentialsPluginTest,
    296350        ApplicantCredentialsTest, PrincipalFactoryTest,
     351        PAUSetupTest,
    297352        ]:
    298353        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
Note: See TracChangeset for help on using the changeset viewer.