- Timestamp:
- 8 Mar 2011, 02:32:23 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_authentication.py
r5762 r5817 23 23 import unittest 24 24 from zope.component import provideAdapter 25 from zope.component.hooks import setSite 25 from zope.component.hooks import setSite, clearSite 26 26 from zope.interface import verify 27 27 from zope.pluggableauth.interfaces import IAuthenticatedPrincipalFactory 28 28 from zope.publisher.browser import TestRequest 29 29 from zope.publisher.interfaces import IRequest 30 from zope.session.session import RAMSessionDataContainer31 30 from zope.session.interfaces import ISession 32 31 from zope.site import LocalSiteManager 33 from zope.site.folder import Folder34 from zope.site.testing import siteSetUp, siteTearDown35 32 from zope.testing import cleanup 36 33 from waeup.sirp.applicants.authentication import ( … … 38 35 ApplicantCredentials, AuthenticatedApplicantPrincipalFactory, 39 36 ApplicantPrincipalInfo, ApplicantPrincipal) 40 from waeup.sirp.applicants.interfaces import(41 IJAMBApplicantSessionCredentials,)42 37 43 38 class FakeBatch(dict): … … 60 55 def __init__(self): 61 56 super(FakeSite, self).__init__() 62 self['applications'] = { 63 'APP-12345': FakeApplication('APP-12345'), 64 'APP-54321': FakeApplication('APP-54321'), 65 'APP-22222': FakeApplication('APP-OTHER'), 66 'APP-44444': FakeApplication(), 67 'APP-55555': FakeApplication('APP-OTHER'), 68 'JAMB1': FakeApplication(), 69 'JAMB2': FakeApplication('APP-12345'), 70 'JAMB3': FakeApplication('APP-54321'), 71 'JAMB4': FakeApplication('APP-44444'), 57 self['applicants'] = { 58 'APP': { 59 'APP-12345': FakeApplication('APP-12345'), 60 'APP-54321': FakeApplication('APP-54321'), 61 'APP-22222': FakeApplication('APP-OTHER'), 62 'APP-44444': FakeApplication(), 63 'APP-55555': FakeApplication('APP-OTHER'), 64 }, 65 'JAMB': { 66 'JAMB1': FakeApplication(), 67 'JAMB2': FakeApplication('APP-12345'), 68 'JAMB3': FakeApplication('APP-54321'), 69 'JAMB4': FakeApplication('APP-44444'), 70 }, 72 71 } 73 72 self['accesscodes'] = { … … 86 85 87 86 def setUp(self): 88 self.root = Folder() 89 siteSetUp(self.root) 90 self.app = FakeSite() #grok.Application() 91 self.root['app'] = self.app 87 self.app = FakeSite() 92 88 self.app.setSiteManager(LocalSiteManager(self.app)) 93 89 self.plugin = ApplicantsAuthenticatorPlugin() … … 96 92 97 93 def tearDown(self): 98 siteTearDown()94 clearSite() 99 95 return 100 96 … … 108 104 109 105 result = self.plugin.authenticateCredentials( 110 dict(jambregno=None, foo='blah')) 111 assert result is None 112 113 result = self.plugin.authenticateCredentials( 114 dict(accesscode=None, jambregno=None)) 115 assert result is None 116 117 result = self.plugin.authenticateCredentials( 118 dict(accesscode='Nonsense', jambregno='Nonsense')) 119 assert result is None 120 121 # The nine possible cases, where formal correct authentication 106 dict(accesscode='Nonsense',)) 107 assert result is None 108 109 # Possible cases, where formal correct authentication 122 110 # data is not valid: 123 111 result = self.plugin.authenticateCredentials( … … 136 124 dict(accesscode='APP-55555')) 137 125 assert result is None 138 139 result = self.plugin.authenticateCredentials(140 dict(accesscode='APP-12345', jambregno='JAMB-NOT-EXISTENT'))141 assert result is None142 143 result = self.plugin.authenticateCredentials(144 dict(accesscode='APP-12345', jambregno='JAMB3'))145 assert result is None146 147 result = self.plugin.authenticateCredentials(148 dict(accesscode='APP-54321', jambregno='JAMB-NOT-EXISTENT'))149 assert result is None150 151 result = self.plugin.authenticateCredentials(152 dict(accesscode='APP-54321', jambregno='JAMB1'))153 assert result is None154 155 result = self.plugin.authenticateCredentials(156 dict(accesscode='APP-54321', jambregno='JAMB2'))157 assert result is None158 159 126 return 160 127 … … 174 141 result = self.plugin.authenticateCredentials( 175 142 dict(accesscode='APP-54321')) 176 assert result is not None177 178 result = self.plugin.authenticateCredentials(179 dict(accesscode='APP-12345', jambregno='JAMB1'))180 181 result = self.plugin.authenticateCredentials(182 dict(accesscode='APP-12345', jambregno='JAMB2'))183 assert result is not None184 185 result = self.plugin.authenticateCredentials(186 dict(accesscode='APP-54321', jambregno='JAMB3'))187 143 assert result is not None 188 144 … … 245 201 'form.ac_series': '1', 246 202 'form.ac_number': '1234567890', 247 'form.jamb_reg_no': 'JAMB_NUMBER',203 #'form.jamb_reg_no': 'JAMB_NUMBER', 248 204 }) 249 205 result = self.plugin.extractCredentials(request) 250 self.assertEqual(result, {'jambregno': 'JAMB_NUMBER', 251 'accesscode': 'APP-1-1234567890'}) 206 self.assertEqual(result, {'accesscode': 'APP-1-1234567890'}) 252 207 return 253 208
Note: See TracChangeset for help on using the changeset viewer.