source: main/waeup.sirp/trunk/src/waeup/sirp/tests/test_authentication.py @ 6626

Last change on this file since 6626 was 6617, checked in by uli, 13 years ago

Remove unused helper class.

File size: 2.1 KB
Line 
1import grok
2import unittest
3from zope.component.hooks import setSite, clearSite
4from zope.interface.verify import verifyClass, verifyObject
5from zope.pluggableauth.interfaces import IAuthenticatorPlugin
6from waeup.sirp.testing import FunctionalTestCase, FunctionalLayer
7from waeup.sirp.authentication import (
8    UserAuthenticatorPlugin, Account, PrincipalInfo)
9
10class FakeSite(grok.Site, grok.Container):
11    pass
12
13class UserAuthenticatorPluginTests(FunctionalTestCase):
14    # Must be functional because of various utility lookups and the like
15
16    layer = FunctionalLayer
17
18    def setUp(self):
19        super(UserAuthenticatorPluginTests, self).setUp()
20        self.getRootFolder()['app'] = FakeSite()
21        self.site = self.getRootFolder()['app']
22        self.site['users'] = {'bob': Account('bob', 'secret')}
23        setSite(self.site)
24        return
25
26    def tearDown(self):
27        super(UserAuthenticatorPluginTests, self).tearDown()
28        clearSite(self.site)
29        return
30
31    def test_ifaces(self):
32        # make sure, interfaces requirements are met
33        plugin = UserAuthenticatorPlugin()
34        plugin.__parent__ = None # This attribute is required by iface
35        self.assertTrue(
36            verifyClass(IAuthenticatorPlugin, UserAuthenticatorPlugin))
37        self.assertTrue(verifyObject(IAuthenticatorPlugin, plugin))
38        return
39
40    def test_authenticate_credentials(self):
41        # make sure authentication works as expected
42        plugin = UserAuthenticatorPlugin()
43        result1 = plugin.authenticateCredentials(
44            dict(login='bob', password='secret'))
45        result2 = plugin.authenticateCredentials(
46            dict(login='bob', password='nonsense'))
47        self.assertTrue(isinstance(result1, PrincipalInfo))
48        self.assertTrue(result2 is None)
49        return
50
51    def test_principal_info(self):
52        # make sure we can get a principal info
53        plugin = UserAuthenticatorPlugin()
54        result1 = plugin.principalInfo('bob')
55        result2 = plugin.principalInfo('manfred')
56        self.assertTrue(isinstance(result1, PrincipalInfo))
57        self.assertTrue(result2 is None)
58        return
Note: See TracBrowser for help on using the repository browser.