[Zope3-checkins] CVS: Zope3/src/zope/app/dublincore/tests -
test_creatorannotator.py:1.7.12.1
Marius Gedminas
marius at pov.lt
Mon Mar 8 13:44:08 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/dublincore/tests
In directory cvs.zope.org:/tmp/cvs-serv14991/src/zope/app/dublincore/tests
Modified Files:
Tag: mgedmin-events2-branch
test_creatorannotator.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/dublincore/tests/test_creatorannotator.py 1.7 => 1.7.12.1 ===
--- Zope3/src/zope/app/dublincore/tests/test_creatorannotator.py:1.7 Wed Jan 14 17:55:22 2004
+++ Zope3/src/zope/app/dublincore/tests/test_creatorannotator.py Mon Mar 8 13:43:37 2004
@@ -27,7 +27,7 @@
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.app.interfaces.security import IPrincipal
from zope.app.interfaces.event import IEvent
-from zope.security.management import noSecurityManager, newSecurityManager
+from zope.security.management import newInteraction, endInteraction
class IDummyContent(Interface):
pass
@@ -70,15 +70,19 @@
def getDescription(self):
return self._description
-class Test(PlacefulSetup, TestCase, CleanUp):
+class DummyRequest:
+
+ def __init__(self, user):
+ self.user = user
+
+
+class TestCreatorAnnotator(PlacefulSetup, TestCase, CleanUp):
def setUp(self):
PlacefulSetup.setUp(self)
ztapi.provideAdapter(IDummyContent, IZopeDublinCore, DummyDCAdapter)
- noSecurityManager()
def tearDown(self):
- noSecurityManager()
PlacefulSetup.tearDown(self)
def test_creatorannotation(self):
@@ -99,37 +103,42 @@
bad_author._description = 'this is a very bad author'
# Check what happens if no user is there
- noSecurityManager()
+ newInteraction(None)
CreatorAnnotator.notify(event)
self.assertEqual(data.creators,())
+ endInteraction()
# Let the bad edit it first
- security = newSecurityManager(bad_author)
+ newInteraction(DummyRequest(bad_author))
CreatorAnnotator.notify(event)
self.failIf(len(data.creators) != 1)
self.failUnless(bad_author.getId() in data.creators)
+ endInteraction()
# Now let the good edit it
- security = newSecurityManager(good_author)
+ newInteraction(DummyRequest(good_author))
CreatorAnnotator.notify(event)
self.failIf(len(data.creators) != 2)
self.failUnless(good_author.getId() in data.creators)
self.failUnless(bad_author.getId() in data.creators)
+ endInteraction()
# Let the bad edit it again
- security = newSecurityManager(bad_author)
+ newInteraction(DummyRequest(bad_author))
CreatorAnnotator.notify(event)
- # Check that the bad author hasn't been added twice.
+ # Check that the bad author hasn't been added twice.
self.failIf(len(data.creators) != 2)
self.failUnless(good_author.getId() in data.creators)
self.failUnless(bad_author.getId() in data.creators)
+ endInteraction()
+
def test_suite():
return TestSuite((
- makeSuite(Test),
+ makeSuite(TestCreatorAnnotator),
))
if __name__=='__main__':
More information about the Zope3-Checkins
mailing list