[Checkins] SVN: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py Test ZODBUserManager.updateAllLoginNames.
Maurits van Rees
cvs-admin at zope.org
Fri Jan 18 23:13:28 UTC 2013
Log message for revision 129052:
Test ZODBUserManager.updateAllLoginNames.
Changed:
U Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py
-=-
Modified: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py
===================================================================
--- Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py 2013-01-18 22:03:20 UTC (rev 129051)
+++ Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/plugins/tests/test_ZODBUserManager.py 2013-01-18 23:13:27 UTC (rev 129052)
@@ -36,8 +36,23 @@
return self._id
+class FakePAS(object):
+
+ def _get_login_transform_method(self):
+ return None
+
+ def applyTransform(self, value):
+ return value
+
+
class FakeLowerCasePAS(object):
+ def _get_login_transform_method(self):
+ return self.lower
+
+ def lower(self, value):
+ return value.lower()
+
def applyTransform(self, value):
return value.lower()
@@ -502,6 +517,52 @@
self.assertEqual(user_id, 'user1')
self.assertEqual(login, 'user1 at foobar.com')
+ def test_updateAllLoginNames(self):
+
+ zum = self._makeOne()
+ zum._getPAS = lambda: FakePAS()
+
+ # Create two users and make sure we can authenticate with it
+ zum.addUser( 'User1', 'User1 at Example.Com', 'password' )
+ zum.addUser( 'User2', 'User2 at Example.Com', 'password' )
+ info1 = { 'login' : 'User1 at Example.Com', 'password' : 'password' }
+ info2 = { 'login' : 'User2 at Example.Com', 'password' : 'password' }
+ user_id, login = zum.authenticateCredentials(info1)
+ self.assertEqual(user_id, 'User1')
+ self.assertEqual(login, 'User1 at Example.Com')
+ user_id, login = zum.authenticateCredentials(info2)
+ self.assertEqual(user_id, 'User2')
+ self.assertEqual(login, 'User2 at Example.Com')
+
+ # Give all users a new login, using the applyTransform method
+ # of PAS. There should be no changes.
+ zum.updateAllLoginNames()
+ self.failUnless(zum.authenticateCredentials(info1))
+ self.failUnless(zum.authenticateCredentials(info2))
+
+ # Use a PAS configured to transform login names to lower case.
+ zum._getPAS = lambda: FakeLowerCasePAS()
+
+ # Update all login names
+ zum.updateAllLoginNames()
+
+ # The old mixed case logins no longer work. Note that if you
+ # query PAS (via the validate or _extractUserIds method), PAS
+ # is responsible for transforming the login before passing it
+ # to our plugin.
+ self.failIf(zum.authenticateCredentials(info1))
+ self.failIf(zum.authenticateCredentials(info2))
+
+ # Authentication with all lowercase login works.
+ info1 = { 'login' : 'user1 at example.com', 'password' : 'password' }
+ info2 = { 'login' : 'user2 at example.com', 'password' : 'password' }
+ user_id, login = zum.authenticateCredentials(info1)
+ self.assertEqual(user_id, 'User1')
+ self.assertEqual(login, 'user1 at example.com')
+ user_id, login = zum.authenticateCredentials(info2)
+ self.assertEqual(user_id, 'User2')
+ self.assertEqual(login, 'user2 at example.com')
+
def test_enumerateUsersWithOptionalMangling(self):
zum = self._makeOne()
More information about the checkins
mailing list