[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_contentdirective.py:1.11.18.1 test_factory.py:1.8.18.1 test_servicedirective.py:1.11.18.1

Marius Gedminas marius at pov.lt
Mon Mar 8 13:44:07 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/component/tests
In directory cvs.zope.org:/tmp/cvs-serv14991/src/zope/app/component/tests

Modified Files:
      Tag: mgedmin-events2-branch
	test_contentdirective.py test_factory.py 
	test_servicedirective.py 
Log Message:
Replaced security managers and security contexts with interactions.  There is
at most one active interaction per thread, accessible with getInteraction().
Code that used getSecurityManager to get the authenticated principal should now
use the current interaction.  Note that the interaction contains an iterable of
principals instead of just one principal.  Code that used a security manager to
implement user logins should now use newInteraction/ endInteraction pair.  Code
that used a security manager to check whether the authenticated user has a
permission to do something should now ask the security policy directly (there's
a new global function getSecurityPolicy).

Interactions are tied with security policies: ISecurityPolicy has a method
used to create a new interaction for a given request.  This is not necessarily
the best idea, perhaps a global hook (setInteractionFactory) would be better.

Things not done yet:
 - Not all places in the code are ready to cope with more than one principal.
 - The README in zope.security and the sandbox security example need to be
   updated.
 - There was an idea of using a notification method in IInteraction that would
   let it customize the handling of local authentication during traversal.
   It could be e.g. afterLocalAuthentication(old_principal, new_principal, site)
   Currently the ZopePublication code just does
     interaction.remove(old_principal)
     interaction.add(new_principal)
   when request.user is changed during traversal.
 - The interaction API could be polished a bit (perhaps the request argument
   to newInteraction should be optional, perhaps there should be an alternative
   principals argument to newInteraction, perhaps endInteraction should not
   raise an exception when it is called outside of an active interaction).
 - It is not clearly cut when security checks should use the global interaction
   and when they should use the interaction of the security proxy.  Perhaps
   use the global one if interaction stored in the proxy is None?
 - It is not defined explicitly where the interaction argument can safely be
   None (as an argument to ProxyFactory, as an argument to security checkers,
   etc.).
 - Some places that construct security proxies pass None to ProxyFactory.
   Perhaps they should use the current interaction instead.  Or maybe not.





=== Zope3/src/zope/app/component/tests/test_contentdirective.py 1.11 => 1.11.18.1 ===
--- Zope3/src/zope/app/component/tests/test_contentdirective.py:1.11	Thu Nov 27 08:59:17 2003
+++ Zope3/src/zope/app/component/tests/test_contentdirective.py	Mon Mar  8 13:43:36 2004
@@ -25,7 +25,8 @@
 from zope.component.exceptions import ComponentLookupError
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.management import newSecurityManager, system_user
+from zope.security.management import system_user
+from zope.security.management import newInteraction, getInteraction
 from zope.security.proxy import Proxy
 from zope.app.security.exceptions import UndefinedPermissionError
 from zope.component import getService
@@ -49,7 +50,8 @@
 class TestContentDirective(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         super(TestContentDirective, self).setUp()
-        newSecurityManager(system_user)
+        newInteraction(None)
+        getInteraction().add(system_user)
         XMLConfig('meta.zcml', zope.app.component)()
         XMLConfig('meta.zcml', zope.app.security)()
 
@@ -136,7 +138,8 @@
 class TestFactorySubdirective(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         super(TestFactorySubdirective, self).setUp()
-        newSecurityManager(system_user)
+        newInteraction(None)
+        getInteraction().add(system_user)
         XMLConfig('meta.zcml', zope.app.component)()
         XMLConfig('meta.zcml', zope.app.security)()
 


=== Zope3/src/zope/app/component/tests/test_factory.py 1.8 => 1.8.18.1 ===
--- Zope3/src/zope/app/component/tests/test_factory.py:1.8	Thu Nov 27 08:59:17 2003
+++ Zope3/src/zope/app/component/tests/test_factory.py	Mon Mar  8 13:43:36 2004
@@ -20,7 +20,8 @@
 from zope.configuration.xmlconfig import XMLConfig
 from zope.app.services.servicenames import Factories
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.management import newSecurityManager, system_user
+from zope.security.management import system_user
+from zope.security.management import newInteraction, getInteraction
 
 import zope.configuration
 import zope.app.security
@@ -39,7 +40,8 @@
 class Test(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         super(Test, self).setUp()
-        newSecurityManager(system_user)
+        newInteraction(None)
+        getInteraction().add(system_user)
         XMLConfig('meta.zcml', zope.app.component)()
         XMLConfig('meta.zcml', zope.app.security)()
 


=== Zope3/src/zope/app/component/tests/test_servicedirective.py 1.11 => 1.11.18.1 ===
--- Zope3/src/zope/app/component/tests/test_servicedirective.py:1.11	Thu Nov 27 08:59:17 2003
+++ Zope3/src/zope/app/component/tests/test_servicedirective.py	Mon Mar  8 13:43:36 2004
@@ -177,11 +177,13 @@
 
 
         # Need to "log someone in" to turn on checks
-        from zope.security.management import newSecurityManager
-        newSecurityManager('someuser')
+        from zope.security.management import newInteraction, getInteraction
+        newInteraction(None)
+        getInteraction().add('someuser')
 
         service = getService(None, "Foo")
-        service = ProxyFactory(service) # simulate untrusted code!
+        # simulate untrusted code!
+        service = ProxyFactory(service, interaction=getInteraction())
 
         self.assertRaises(Unauthorized, getattr, service, 'foo')
         self.assertRaises(Unauthorized, getattr, service, 'foobar')




More information about the Zope3-Checkins mailing list