[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate/tests - testBasicTemplate.py:1.1.2.2 testHTMLTests.py:1.1.2.7 test_binding.py:1.1.2.4 util.py:1.1.2.6

Shane Hathaway shane@cvs.zope.org
Thu, 28 Feb 2002 11:44:37 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/PageTemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv16025/PageTemplate/tests

Modified Files:
      Tag: Zope-3x-branch
	testBasicTemplate.py testHTMLTests.py test_binding.py util.py 
Log Message:
Enabled Zope security in TALES expressions and switched to the permissive
security policy for page template tests unrelated to security.


=== Zope3/lib/python/Zope/PageTemplate/tests/testBasicTemplate.py 1.1.2.1 => 1.1.2.2 ===
    def setUp(self):
       self.t = ZPT()
+      self._oldPolicy = util.getDefaultPolicy()
+      util.setPermissive()
+
+   def tearDown(self):
+      util.restoreDefaultPolicy(self._oldPolicy)
 
    def check_if_in_var(self):
       """DTML test 1: if, in, and var:
@@ -42,7 +47,6 @@
       And thats da trooth.
       </body></html>
       """
-
       tal = util.read_input('DTML1.html')
       self.t.write(tal)
 
@@ -86,6 +90,7 @@
         And I\'m 100% sure!
         </body></html>
       """
+      util.setPermissive()
 
       tal = util.read_input('DTML3.html')
       self.t.write(tal)


=== Zope3/lib/python/Zope/PageTemplate/tests/testHTMLTests.py 1.1.2.6 => 1.1.2.7 ===
       f.laf = ZPT()
       f.t = ZPT()
+      self._oldPolicy = util.getDefaultPolicy()
+
+   def tearDown(self):
+      util.restoreDefaultPolicy(self._oldPolicy)
 
    def getProducts(self):
       return [
@@ -41,6 +45,7 @@
       util.check_html(expect, laf())
 
    def check2(self):
+      util.setPermissive()
       self.folder.laf.write(util.read_input('TeeShopLAF.html'))
 
       t = self.folder.t.__get__(self.folder)
@@ -51,6 +56,7 @@
       
 
    def check3(self):
+      util.setPermissive()
       self.folder.laf.write(util.read_input('TeeShopLAF.html'))
 
       t = self.folder.t.__get__(self.folder)
@@ -60,6 +66,7 @@
       util.check_html(expect, out)
 
    def checkSimpleLoop(self):
+      util.setPermissive()
       t = self.folder.t.__get__(self.folder)
       t.write(util.read_input('Loop1.html'))
       expect = util.read_output('Loop1.html')
@@ -109,6 +116,7 @@
       util.check_html(expect, out)
       
    def checkPathAlt(self):
+      util.setPermissive()
       t = self.folder.t.__get__(self.folder)
       t.write(util.read_input('CheckPathAlt.html'))
       expect = util.read_output('CheckPathAlt.html')


=== Zope3/lib/python/Zope/PageTemplate/tests/test_binding.py 1.1.2.3 => 1.1.2.4 ===
 import unittest
 
+from Zope.PageTemplate.tests import util
 from Zope.PageTemplate.tests.testpackage.content import Content, PTComponent
 
 
 class BindingTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self._oldPolicy = util.getDefaultPolicy()
+        util.setPermissive()
+
+    def tearDown(self):
+        util.restoreDefaultPolicy(self._oldPolicy)
 
     def test_binding(self):
         comp = PTComponent(Content())


=== Zope3/lib/python/Zope/PageTemplate/tests/util.py 1.1.2.5 => 1.1.2.6 ===
     filename = os.path.join(output_dir, filename)
     return open(filename, 'r').read()
+
+try:
+    # Use Zope security.
+    import Zope.App.Security.SecurityManager
+    from Zope.App.Security.SecurityManager import setSecurityPolicy
+    from Zope.App.Security.SecurityManagement import noSecurityManager
+    from Zope.App.Security.SimpleSecurityPolicies import \
+         PermissiveSecurityPolicy
+
+    def getDefaultPolicy():
+        return Zope.App.Security.SecurityManager._defaultPolicy
+
+    def setPermissive():
+        setSecurityPolicy(PermissiveSecurityPolicy())
+        noSecurityManager()
+
+    def restoreDefaultPolicy(p):
+        setSecurityPolicy(p)
+        noSecurityManager()
+
+except ImportError:
+    # No Zope security.
+    def getDefaultPolicy():
+        return None
+
+    def setPermissive():
+        pass
+
+    def restoreDefaultPolicy(p):
+        pass
+