[Checkins] SVN: z3c.securitytool/trunk/src/z3c/securitytool/ Added some more tests for securitytool.py

Daniel Blackburn blackburnd at gmail.com
Tue Jan 29 09:17:09 EST 2008


Log message for revision 83294:
  Added some more tests for securitytool.py

Changed:
  U   z3c.securitytool/trunk/src/z3c/securitytool/README.txt
  U   z3c.securitytool/trunk/src/z3c/securitytool/securitytool.py

-=-
Modified: z3c.securitytool/trunk/src/z3c/securitytool/README.txt
===================================================================
--- z3c.securitytool/trunk/src/z3c/securitytool/README.txt	2008-01-29 14:07:36 UTC (rev 83293)
+++ z3c.securitytool/trunk/src/z3c/securitytool/README.txt	2008-01-29 14:17:07 UTC (rev 83294)
@@ -281,6 +281,11 @@
      set([None])]
 
 
+Following are the helper functions used within the securitytool, These
+contain a set of common funtionality that is used in many places.
+
+
+
 Lets see if the `hasPermissionSetting` method returns True if ther is
 a permission or role and False if there is not.
    >>> from z3c.securitytool.securitytool import *
@@ -300,14 +305,13 @@
      >>> hasPermissionSetting({'permissions':{},'roles':{},
      ...                                 'groups':{'group1':emptySettings,
      ...                                           'group2':fullSettings}})
-     False
+     True
 
-
     >>> class SettingDummy(object):
     ...   def getName(self):
     ...     return 'Allow'
 
-    >>> prinPermMap = ({'principal':'daniel',
+    >>> prinPermMap = ({'principal':'zope.daniel',
     ...                 'permission':'takeOverTheWORLD',
     ...                 'setting':  SettingDummy()})
 
@@ -315,13 +319,14 @@
     ...                 'permission':'takeOverTheWORLD',
     ...                 'setting':  SettingDummy()})
 
-    >>> prinRoleMap = ({'principal':'daniel',
+    >>> prinRoleMap = ({'principal':'zope.daniel',
     ...                 'role':'Janitor',
     ...                 'setting':  SettingDummy()})
 
 
+
 Lets test the method with our new dummy data
-    >>> principalDirectlyProvidesPermission([prinPermMap],'daniel',
+    >>> principalDirectlyProvidesPermission([prinPermMap],'zope.daniel',
     ...                                          'takeOverTheWORLD')
     'Allow'
 
@@ -332,10 +337,12 @@
 And we also need to test the roleProvidesPermission
     >>> principalRoleProvidesPermission([prinRoleMap],
     ...                                 [rolePermMap],
-    ...                                 'daniel',
+    ...                                 'zope.daniel',
     ...                                 'takeOverTheWORLD')
     ('Janitor', 'Allow')
 
+See janitors CAN take over the world!!!!!
+
 And for a negative test
     >>> principalRoleProvidesPermission([prinRoleMap],
     ...                                 [rolePermMap],
@@ -353,6 +360,27 @@
     'Daniel'
 
 
+
+    >>> first.populatePermissionMatrix('takeOverTheWORLD',[prinPermMap])
+    
+
+
+
+Now we test the meat of the SecurityChecker Class
+
+
+    >>> settings = {'principalPermissions': [prinPermMap],
+    ...             'rolePermissions'     : [rolePermMap],
+    ...             'principalRoles'      : [prinRoleMap]}
+
+
+    >>> first._permissionDetails(daniel, 'takeOverTheWORLD',
+    ...                                              [['viewName',settings]])
+
+
+
+
+
 Here we will test with the principal that was populated earlier.
     >>> daniel  = principals.definePrincipal('daniel','daniel','daniel')
     >>> pprint(first.principalPermissions('daniel') )

Modified: z3c.securitytool/trunk/src/z3c/securitytool/securitytool.py
===================================================================
--- z3c.securitytool/trunk/src/z3c/securitytool/securitytool.py	2008-01-29 14:07:36 UTC (rev 83293)
+++ z3c.securitytool/trunk/src/z3c/securitytool/securitytool.py	2008-01-29 14:17:07 UTC (rev 83294)
@@ -57,7 +57,7 @@
         self.viewMatrix = {}
         self.views = {}
         self.permissions = set()
-        #import pdb; pdb.set_trace()
+
         for iface in interfaces:
             for view_reg in getViews(iface, self.skin):
                 viewInstance = self.getView(view_reg, self.skin)
@@ -232,6 +232,7 @@
                              'roles': {},
                              'groups': {}}
         principals = zapi.principals()
+
         for name, setting in settings:
             prinPermMap = setting.get('principalPermissions', ())
             prinRoleMap = setting.get('principalRoles', ())
@@ -241,6 +242,7 @@
             if permSetting:
                 principalSettings['permissions'].append(
                     {'name': renderedName(name), 'setting': permSetting})
+
             role_id, permSetting = principalRoleProvidesPermission(
                 prinRoleMap, rolePermMap, principal.id,read_perm )
             if permSetting:



More information about the Checkins mailing list