Ignore:
Timestamp:
17 May 2011, 23:41:15 (14 years ago)
Author:
uli
Message:
  • Remove whitespaces
  • Make authentication tests work again.

Authentication tests now require a complete functional setup, because
we the get_applicant_data() function used by the authentication
plugins now looks up catalogs and catalogs are only filled when real
Applicant objects are added to the ZODB (no FakeApplicants? as we did
yet).

The tests still fail, but this is due to a real bug we have to fix:
get_applicant_data does not lookup the name attribute of
applicants any more, but the access_code attribute. As the authenticator
plugin looks for some applicant stored under a certain name (and not
with a certain access_code attribute) the authentication can succeed
with invalid applicant data.

It's very good, we had these test, because this one was really
difficult to discover. Took me plenty hours to realize what happened
here.

File:
1 edited

Legend:

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

    r6112 r6123  
    3838from waeup.sirp.testing import FunctionalLayer
    3939from waeup.sirp.app import University
     40from waeup.sirp.applicants import  ApplicantsContainer, Applicant
    4041from waeup.sirp.applicants.authentication import (
    4142    ApplicantsAuthenticatorPlugin, WAeUPApplicantCredentialsPlugin,
    4243    ApplicantCredentials, AuthenticatedApplicantPrincipalFactory,
    43     ApplicantPrincipalInfo, ApplicantPrincipal)
     44    ApplicantPrincipalInfo, ApplicantPrincipal,)
    4445
    4546
     
    6667        self['applicants'] = {
    6768            'APP': {
    68                 'APP-12345': FakeApplication('APP-12345'),
    69                 'APP-54321': FakeApplication('APP-54321'),
    70                 'APP-22222': FakeApplication('APP-OTHER'),
     69                'APP-12345': FakeApplication(u'APP-12345'),
     70                'APP-54321': FakeApplication(u'APP-54321'),
     71                'APP-22222': FakeApplication(u'APP-OTHER'),
    7172                'APP-44444': FakeApplication(),
    72                 'APP-55555': FakeApplication('APP-OTHER'),
     73                'APP-55555': FakeApplication(u'APP-OTHER'),
    7374                },
    7475            'JAMB': {
    7576                'JAMB1': FakeApplication(),
    76                 'JAMB2': FakeApplication('APP-12345'),
    77                 'JAMB3': FakeApplication('APP-54321'),
    78                 'JAMB4': FakeApplication('APP-44444'),
     77                'JAMB2': FakeApplication(u'APP-12345'),
     78                'JAMB3': FakeApplication(u'APP-54321'),
     79                'JAMB4': FakeApplication(u'APP-44444'),
    7980                },
    8081            }
     
    9394            }
    9495
    95 class AuthenticatorPluginTest(unittest.TestCase):
     96def FakeSite():
     97    return {
     98        'applicants': {
     99            'APP': {
     100                'APP-12345': FakeApplication(u'APP-12345'),
     101                'APP-54321': FakeApplication(u'APP-54321'),
     102                'APP-22222': FakeApplication(u'APP-OTHER'),
     103                'APP-44444': FakeApplication(),
     104                'APP-55555': FakeApplication(u'APP-OTHER'),
     105                },
     106            'JAMB': {
     107                'JAMB1': FakeApplication(),
     108                'JAMB2': FakeApplication(u'APP-12345'),
     109                'JAMB3': FakeApplication(u'APP-54321'),
     110                'JAMB4': FakeApplication(u'APP-44444'),
     111                },
     112            },
     113        'accesscodes': {
     114            'APP': FakeBatch({
     115                    'APP-12345': FakeAccessCode('APP-12345'),
     116                    'APP-54321': FakeAccessCode('APP-54321', True),
     117                    'APP-11111': FakeAccessCode('APP-11111'),
     118                    'APP-22222': FakeAccessCode('APP-22222'),
     119                    'APP-33333': FakeAccessCode('APP-33333', True),
     120                    'APP-44444': FakeAccessCode('APP-44444', True),
     121                    'APP-55555': FakeAccessCode('APP-55555', True),
     122                    'APP-66666': FakeAccessCode('APP-66666', True, False),
     123                    'APP-77777': FakeAccessCode('APP-77777', False, False),
     124                    })
     125            }
     126        }
     127
     128class AuthenticatorPluginTest(FunctionalTestCase):
     129
     130    layer = FunctionalLayer
     131
     132    def create_applicant(self, cname, aname, ac=None):
     133        # Create an applicant in an applicants container
     134        setSite(self.app)
     135        if not cname in self.app['applicants'].keys():
     136            container = ApplicantsContainer()
     137            self.app['applicants'][cname] = container
     138        applicant = Applicant()
     139        if ac is not None:
     140            applicant.access_code = ac
     141        self.app['applicants'][cname][aname] = applicant
     142        return
    96143
    97144    def setUp(self):
    98         self.app = FakeSite()
    99         self.app.setSiteManager(LocalSiteManager(self.app))
     145        super(AuthenticatorPluginTest, self).setUp()
     146
     147        # Setup a sample site for each test
     148        app = University()
     149        self.dc_root = tempfile.mkdtemp()
     150        app['datacenter'].setStoragePath(self.dc_root)
     151
     152        # Prepopulate the ZODB...
     153        self.getRootFolder()['app'] = app
     154        self.app = self.getRootFolder()['app']
     155
     156        fake_site = FakeSite()
     157        for ckey, fake_container in fake_site['applicants'].items():
     158            for akey, fake_appl in fake_container.items():
     159                self.create_applicant(ckey, akey, fake_appl.access_code)
     160        del self.app['accesscodes']
     161        self.app['accesscodes'] = fake_site['accesscodes']
     162
    100163        self.plugin = ApplicantsAuthenticatorPlugin()
    101         setSite(self.app)
    102164        return
    103165
    104166    def tearDown(self):
    105         clearSite()
     167        super(AuthenticatorPluginTest, self).tearDown()
     168        shutil.rmtree(self.dc_root)
    106169        return
    107170
     
    120183        # Possible cases, where formal correct authentication
    121184        # data is not valid:
     185        # XXX: fails
    122186        result = self.plugin.authenticateCredentials(
    123187            dict(accesscode='APP-22222'))
     
    131195            dict(accesscode='APP-44444'))
    132196        assert result is None
    133        
     197
    134198        result = self.plugin.authenticateCredentials(
    135199            dict(accesscode='APP-55555'))
     
    177241    def get(self, key, default=None):
    178242        return self.__getitem__(key, default)
    179    
     243
    180244    def __getitem__(self, key, default=None):
    181245        return session_data.get(key, default)
     
    317381    # credentials plugin) to be registered with the local PAU. Admins
    318382    # can remove these components on the fly later-on if they wish.
    319    
     383
    320384    layer = FunctionalLayer
    321    
     385
    322386    def setUp(self):
    323387        super(PAUSetupTest, self).setUp()
     
    348412        cred_names = [name for name, plugin in cred_plugins]
    349413        auth_names = [name for name, plugin in auth_plugins]
    350        
     414
    351415        # Make sure our local ApplicantsAuthenticatorPlugin is registered...
    352416        self.assertTrue('applicants' in auth_names)
Note: See TracChangeset for help on using the changeset viewer.