Commit b39cee0e authored by Jérome Perrin's avatar Jérome Perrin Committed by Arnaud Fontaine

testRestrictedPythonSecurity: target Zope4

parent eb8d1ee1
...@@ -839,68 +839,70 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase): ...@@ -839,68 +839,70 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
return ip_interface(u'2a01:cb14:818:0:7312:e251:f251:ffbe').with_prefixlen return ip_interface(u'2a01:cb14:818:0:7312:e251:f251:ffbe').with_prefixlen
''') ''')
def add_tests(suite, module):
if hasattr(module, 'test_suite'):
return suite.addTest(module.test_suite())
for obj in vars(module).values():
if isinstance(obj, type) and issubclass(obj, unittest.TestCase):
suite.addTest(unittest.makeSuite(obj))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestRestrictedPythonSecurity)) suite.addTest(unittest.makeSuite(TestRestrictedPythonSecurity))
# Also run original tests of RestrictedPython, to confirm that our patches did not break # Also run original tests of RestrictedPython, to confirm that our patches did not break
# original functionality # original functionality
import RestrictedPython.tests.testCompile try:
suite.addTest(RestrictedPython.tests.testCompile.test_suite()) import RestrictedPython.tests
import RestrictedPython.tests.testUtiliities except ImportError:
suite.addTest(RestrictedPython.tests.testUtiliities.test_suite()) # https://github.com/zopefoundation/RestrictedPython/issues/231
import RestrictedPython.tests.testREADME pass
suite.addTest(RestrictedPython.tests.testREADME.test_suite()) else:
import RestrictedPython.tests.testRestrictions import RestrictedPython.tests.testCompile
suite.addTest(RestrictedPython.tests.testRestrictions.test_suite()) add_tests(suite, RestrictedPython.tests.testCompile)
import RestrictedPython.tests.testUtiliities
add_tests(suite, RestrictedPython.tests.testUtiliities)
import RestrictedPython.tests.testREADME
add_tests(suite, RestrictedPython.tests.testREADME)
import RestrictedPython.tests.testRestrictions
add_tests(suite, RestrictedPython.tests.testRestrictions)
import AccessControl.tests.test_requestmethod import AccessControl.tests.test_requestmethod
suite.addTest(AccessControl.tests.test_requestmethod.test_suite()) add_tests(suite, AccessControl.tests.test_requestmethod)
import AccessControl.tests.test_safeiter import AccessControl.tests.test_safeiter
suite.addTest(AccessControl.tests.test_safeiter.test_suite()) add_tests(suite, AccessControl.tests.test_safeiter)
import AccessControl.tests.test_tainted import AccessControl.tests.test_tainted
suite.addTest(AccessControl.tests.test_tainted.test_suite()) add_tests(suite, AccessControl.tests.test_tainted)
import AccessControl.tests.test_formatter import AccessControl.tests.test_safe_formatter
suite.addTest(unittest.makeSuite(AccessControl.tests.test_formatter.FormatterTest)) add_tests(suite, AccessControl.tests.test_safe_formatter)
import AccessControl.tests.test_userfolder import AccessControl.tests.test_userfolder
suite.addTest(AccessControl.tests.test_userfolder.test_suite()) add_tests(suite, AccessControl.tests.test_userfolder)
import AccessControl.tests.test_users import AccessControl.tests.test_users
suite.addTest(AccessControl.tests.test_users.test_suite()) add_tests(suite, AccessControl.tests.test_users)
import AccessControl.tests.testClassSecurityInfo import AccessControl.tests.testClassSecurityInfo
suite.addTest(AccessControl.tests.testClassSecurityInfo.test_suite()) add_tests(suite, AccessControl.tests.testClassSecurityInfo)
import AccessControl.tests.testImplementation import AccessControl.tests.testImplementation
suite.addTest(AccessControl.tests.testImplementation.test_suite()) add_tests(suite, AccessControl.tests.testImplementation)
import AccessControl.tests.testModuleSecurity import AccessControl.tests.testModuleSecurity
# we allow part of os module, so adjust this test for another not allowed module # we allow part of os module, so adjust this test for another not allowed module
def test_unprotected_module(self): def test_unprotected_module(self):
self.assertUnauth('subprocess', ()) self.assertUnauth('subprocess', ())
AccessControl.tests.testModuleSecurity.ModuleSecurityTests.test_unprotected_module = test_unprotected_module AccessControl.tests.testModuleSecurity.ModuleSecurityTests.test_unprotected_module = test_unprotected_module
suite.addTest(AccessControl.tests.testModuleSecurity.test_suite()) add_tests(suite, AccessControl.tests.testModuleSecurity)
import AccessControl.tests.testOwned import AccessControl.tests.testOwned
suite.addTest(AccessControl.tests.testOwned.test_suite()) add_tests(suite, AccessControl.tests.testOwned)
import AccessControl.tests.testPasswordDigest
# Disable crypt scheme, we don't want to use CRYPT and it fails on debian 11.
# This is also disabled in github.com/zopefoundation/AuthEncoding commit
# fbbdcf3 (Allow the CRYPT test to fail as it is the case on GHA., 2021-04-08)
import AccessControl.AuthEncoding
def setUp(self):
self._original_AuthEncoding_schemes = AccessControl.AuthEncoding._schemes[::]
AccessControl.AuthEncoding._schemes = [s for s in AccessControl.AuthEncoding._schemes if s[0] != 'CRYPT']
AccessControl.tests.testPasswordDigest.PasswordDigestTests.setUp = setUp
def tearDown(self):
AccessControl.AuthEncoding._schemes = self._original_AuthEncoding_schemes
AccessControl.tests.testPasswordDigest.PasswordDigestTests.tearDown = tearDown
suite.addTest(AccessControl.tests.testPasswordDigest.test_suite())
import AccessControl.tests.testPermissionMapping import AccessControl.tests.testPermissionMapping
suite.addTest(AccessControl.tests.testPermissionMapping.test_suite()) add_tests(suite, AccessControl.tests.testPermissionMapping)
import AccessControl.tests.testPermissionRole import AccessControl.tests.testPermissionRole
suite.addTest(AccessControl.tests.testPermissionRole.test_suite()) add_tests(suite, AccessControl.tests.testPermissionRole)
import AccessControl.tests.testRole import AccessControl.tests.testRole
suite.addTest(AccessControl.tests.testRole.test_suite()) add_tests(suite, AccessControl.tests.testRole)
import AccessControl.tests.testSecurityManager import AccessControl.tests.testSecurityManager
suite.addTest(AccessControl.tests.testSecurityManager.test_suite()) add_tests(suite, AccessControl.tests.testSecurityManager)
import AccessControl.tests.testZCML import AccessControl.tests.testZCML
suite.addTest(AccessControl.tests.testZCML.test_suite()) add_tests(suite, AccessControl.tests.testZCML)
import AccessControl.tests.testZopeGuards import AccessControl.tests.testZopeGuards
# patch so that AccessControl.tests.testZopeGuards.TestActualPython.testPython # patch so that AccessControl.tests.testZopeGuards.TestActualPython.testPython
...@@ -927,9 +929,9 @@ def test_suite(): ...@@ -927,9 +929,9 @@ def test_suite():
return TestActualPython_compile(self, outfile.name) return TestActualPython_compile(self, outfile.name)
return TestActualPython_compile(self, fname) return TestActualPython_compile(self, fname)
AccessControl.tests.testZopeGuards.TestActualPython._compile = _compile AccessControl.tests.testZopeGuards.TestActualPython._compile = _compile
suite.addTest(AccessControl.tests.testZopeGuards.test_suite()) add_tests(suite, AccessControl.tests.testZopeGuards)
import AccessControl.tests.testZopeSecurityPolicy import AccessControl.tests.testZopeSecurityPolicy
suite.addTest(AccessControl.tests.testZopeSecurityPolicy.test_suite()) add_tests(suite, AccessControl.tests.testZopeSecurityPolicy)
return suite return suite
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment