[Checkins] SVN: Products.PluggableAuthService/trunk/ Make ZODBRoleManager.assignRoleToPrincipal raise a more informative error.

Tres Seaver tseaver at palladion.com
Thu Jul 1 18:14:01 EDT 2010


Log message for revision 114081:
  Make ZODBRoleManager.assignRoleToPrincipal raise a more informative error.
  
  Rather than asserting when detecting a duplicate principal.
  
  Fixes https://bugs.launchpad.net/zope-pas/+bug/348795
  

Changed:
  U   Products.PluggableAuthService/trunk/CHANGES.txt
  U   Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/ZODBRoleManager.py
  U   Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py

-=-
Modified: Products.PluggableAuthService/trunk/CHANGES.txt
===================================================================
--- Products.PluggableAuthService/trunk/CHANGES.txt	2010-07-01 22:05:35 UTC (rev 114080)
+++ Products.PluggableAuthService/trunk/CHANGES.txt	2010-07-01 22:14:01 UTC (rev 114081)
@@ -4,6 +4,10 @@
 1.7.1 (unreleased)
 ------------------
 
+- Made ``ZODBRoleManager.assignRoleToPrincipal`` raise and log a more
+  informative error when detecting a duplicate principal.
+  https://bugs.launchpad.net/zope-pas/+bug/348795
+
 - Updated ``DynamicGroupsPlugin.enumerateGroups`` to return an empty sequence
   for an unknown group ID, rather than raising KeyError.
   https://bugs.launchpad.net/zope-pas/+bug/585365

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/ZODBRoleManager.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/ZODBRoleManager.py	2010-07-01 22:05:35 UTC (rev 114080)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/ZODBRoleManager.py	2010-07-01 22:14:01 UTC (rev 114081)
@@ -40,6 +40,9 @@
 
 LOG = logging.getLogger('PluggableAuthService')
 
+class MultiplePrincipalError(Exception):
+    pass
+
 class IZODBRoleManager(Interface):
     """ Marker interface.
     """
@@ -276,9 +279,12 @@
                 info = parent.searchPrincipals( id=k, exact_match=True )
 
                 if len(info) > 1:                    
-                    LOG.error('searchPrincipals() returned more than one result '
-                              'for id=%s' % k)
-                assert len(info) in (0, 1)
+                    message = ("Multiple groups or users exist with the "
+                               "name '%s'. Remove one of the duplicate groups "
+                               "or users." % (k))
+                    LOG.error(message)
+                    raise MultiplePrincipalError(message)
+
                 if len( info ) == 0:
                     title = '<%s: not found>' % k
                 else:

Modified: Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py
===================================================================
--- Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py	2010-07-01 22:05:35 UTC (rev 114080)
+++ Products.PluggableAuthService/trunk/Products/PluggableAuthService/plugins/tests/test_ZODBRoleManager.py	2010-07-01 22:14:01 UTC (rev 114081)
@@ -421,6 +421,26 @@
 
         self.failIf( removed )
 
+    def test_listAssignedPrincipals_duplicate_principals( self ):
+        from Products.PluggableAuthService.plugins.ZODBRoleManager \
+            import MultiplePrincipalError
+        
+        class FauxDuplicatePAS( FauxSmartPAS ):
+            """Returns duplicate user ids when searched."""
+
+            def searchPrincipals( self, **kw ):
+                return [ {'id':'foo', 'title':'User 1'},
+                         {'id':'foo', 'title':'User 2'} ]
+        
+        root = FauxDuplicatePAS()
+        zrm = self._makeOne(id='assign_new').__of__(root)
+        
+        zrm.addRole('test')
+        zrm.assignRoleToPrincipal('test', 'foo')
+        
+        self.assertRaises(MultiplePrincipalError,
+                          zrm.listAssignedPrincipals, 'test' )
+
     def test_updateRole_nonesuch( self ):
 
         from Products.PluggableAuthService.tests.test_PluggableAuthService \



More information about the checkins mailing list