Index: main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_authentication.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_authentication.py	(revision 6668)
+++ main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_authentication.py	(revision 6680)
@@ -21,4 +21,5 @@
 ##
 import unittest
+from zope.authentication.interfaces import IAuthentication
 from zope.component import provideUtility, queryUtility, getGlobalSiteManager
 from zope.interface.verify import verifyClass, verifyObject
@@ -26,4 +27,7 @@
 from zope.password.interfaces import IPasswordManager
 from zope.pluggableauth import PluggableAuthentication
+from zope.securitypolicy.role import Role
+from zope.securitypolicy.interfaces import IRole, Allow
+from waeup.sirp.authentication import get_principal_role_manager
 from waeup.sirp.interfaces import IAuthPluginUtility, IUserAccount
 from waeup.sirp.students.authentication import (
@@ -62,4 +66,9 @@
     password = None
 
+
+class MinimalPAU(PluggableAuthentication):
+    def getPrincipal(self, id):
+        return 'faked principal'
+
 class StudentAccountTests(unittest.TestCase):
 
@@ -67,4 +76,13 @@
         self.fake_stud = FakeStudent()
         self.account = StudentAccount(self.fake_stud)
+
+        # We provide a minimal PAU
+        pau = MinimalPAU()
+        provideUtility(pau, IAuthentication)
+
+        # We register a role
+        test_role = Role('waeup.test.Role', 'Testing Role')
+        provideUtility(test_role, IRole, name='waeup.test.Role')
+
         # We have to setup a password manager utility manually as we
         # have no functional test. In functional tests this would
@@ -76,10 +94,18 @@
 
     def tearDown(self):
-        # Clear up the SSHA utility
-        ssha_manager = queryUtility(
-            IPasswordManager, name='SSHA', default=None)
-        if ssha_manager is not None:
-            gsm = getGlobalSiteManager()
-            gsm.unregisterUtility(ssha_manager)
+        self.account.roles = [] # make sure roles are reset
+        gsm = getGlobalSiteManager()
+        to_clean = []
+        # Clear up utilities registered in setUp
+        to_clean.append(
+            (IPasswordManager, queryUtility(
+                    IPasswordManager, name='SSHA', default=None)))
+        to_clean.append(
+            (IAuthentication, queryUtility(IAuthentication, default=None)))
+        to_clean.append(
+            (IRole, queryUtility(IRole, name='test.Role', default=None)))
+        for iface, elem in to_clean:
+            if elem is not None:
+                gsm.unregisterUtility(elem, iface)
         return
 
@@ -95,4 +121,6 @@
         # we do not store plaintext passwords
         self.assertTrue(self.fake_stud.password != 'secret')
+        # passwords are stored as unicode
+        self.assertTrue(isinstance(self.fake_stud.password, unicode))
         return
 
@@ -107,2 +135,19 @@
         self.assertEqual(result3, True)
         return
+
+    def test_role_set(self):
+        # make sure we can set roles for principals denoted by account
+        prm = get_principal_role_manager()
+        self.assertEqual(prm.getPrincipalsAndRoles(), [])
+        self.account.roles = ['waeup.test.Role']
+        self.assertEqual(
+            prm.getPrincipalsAndRoles(),
+            [('waeup.test.Role', 'test_stud', Allow)])
+        return
+
+    def test_role_get(self):
+        # make sure we can get roles set for an account
+        self.assertEqual(self.account.roles, [])
+        self.account.roles = ['waeup.test.Role',] # set a role
+        self.assertEqual(self.account.roles, ['waeup.test.Role'])
+        return
