Back to index

plone3  3.1.7
testRestrictedAcquisition.py
Go to the documentation of this file.
00001 #
00002 # This test module demonstrates a problem caused by the removal of
00003 # a few lines of code from cAccessControl.c and ImplPython.c
00004 # See: http://mail.zope.org/pipermail/zope-checkins/2004-August/028152.html
00005 #
00006 # If an object with setDefaultAccess('deny') is used as the context for
00007 # a PythonScript, the script can no longer aquire tools from the portal
00008 # root. Rolling back the abovementioned checkin restores functionality.
00009 #
00010 
00011 from Products.CMFPlone.tests import PloneTestCase
00012 
00013 PloneTestCase.installProduct('PythonScripts')
00014 
00015 
00016 from Globals import InitializeClass
00017 from AccessControl import ClassSecurityInfo
00018 from OFS.SimpleItem import SimpleItem
00019 
00020 
00021 class AllowedItem(SimpleItem):
00022     id = 'allowed'
00023     security = ClassSecurityInfo()
00024     security.setDefaultAccess('allow')
00025 
00026 InitializeClass(AllowedItem)
00027 
00028 class DeniedItem(SimpleItem):
00029     id = 'denied'
00030     security = ClassSecurityInfo()
00031     security.setDefaultAccess('deny')
00032 
00033 InitializeClass(DeniedItem)
00034 
00035 
00036 class BrokenAcquisitionTest(PloneTestCase.PloneTestCase):
00037 
00038     def afterSetUp(self):
00039         self.folder = self.portal
00040         self.folder._setObject('allowed', AllowedItem())
00041         self.folder._setObject('denied', DeniedItem())
00042 
00043     def _makePS(self, context, id, params, body):
00044         factory = context.manage_addProduct['PythonScripts']
00045         factory.manage_addPythonScript(id)
00046         ps = context[id]
00047         ps.ZPythonScript_edit(params, body)
00048 
00049     def testAcquisitionAllowed(self):
00050         self._makePS(self.folder, 'ps', '', 'print context.portal_membership')
00051         self.folder.allowed.ps()
00052 
00053     def testAcquisitionDenied(self):
00054         # This test fails in Zope 2.7.3
00055         # Also see http://zope.org/Collectors/CMF/259
00056         self._makePS(self.folder, 'ps', '', 'print context.portal_membership')
00057         self.folder.denied.ps()
00058 
00059 
00060 def test_suite():
00061     from unittest import TestSuite, makeSuite
00062     suite = TestSuite()
00063     suite.addTest(makeSuite(BrokenAcquisitionTest))
00064     return suite