[Zope-Checkins] SVN: Zope/branches/2.10/lib/python/ Backport test of reStructuredText security fixes.

Tres Seaver tseaver at palladion.com
Mon Jul 10 15:57:10 EDT 2006


Log message for revision 69081:
  Backport test of reStructuredText security fixes.

Changed:
  U   Zope/branches/2.10/lib/python/Products/ZReST/tests/test_ZReST.py
  U   Zope/branches/2.10/lib/python/reStructuredText/tests/testReST.py

-=-
Modified: Zope/branches/2.10/lib/python/Products/ZReST/tests/test_ZReST.py
===================================================================
--- Zope/branches/2.10/lib/python/Products/ZReST/tests/test_ZReST.py	2006-07-10 19:56:49 UTC (rev 69080)
+++ Zope/branches/2.10/lib/python/Products/ZReST/tests/test_ZReST.py	2006-07-10 19:57:10 UTC (rev 69081)
@@ -56,14 +56,41 @@
         s = '<h1><a id="hello-world" name="hello-world">Hello World</a></h1>'
         self.assertEqual(s in html, True)
 
-        s = '<h1><a id="von-v-geln-und-fen" name="von-v-geln-und-fen">Von Vögeln und Öfen</a></h1>'
+        s = '<h1><a id="von-v-geln-und-fen" name="von-v-geln-und-fen">'\
+            'Von Vögeln und Öfen</a></h1>'
         self.assertEqual(s in html, True)
 
         # ZReST should render a complete HTML document
         self.assertEqual('<html' in html, True)
         self.assertEqual('<body>' in html, True)
 
+    def test_include_directive_raises(self):
+        resty = self._makeOne()
+        resty.source = 'hello world\n .. include:: /etc/passwd'
+        self.assertRaises(NotImplementedError, resty.render)
 
+    def test_raw_directive_disabled(self):
+
+        EXPECTED = '<h1>HELLO WORLD</h1>'
+
+        resty = self._makeOne()
+        resty.source = '.. raw:: html\n\n  %s\n' % EXPECTED
+        result = resty.render() # don't raise, but don't work either
+        self.failIf(EXPECTED in result)
+
+    def test_raw_directive_file_directive_raises(self):
+
+        resty = self._makeOne()
+        resty.source = '.. raw:: html\n  :file: inclusion.txt'
+        self.assertRaises(NotImplementedError, resty.render)
+
+    def test_raw_directive_url_directive_raises(self):
+
+        resty = self._makeOne()
+        resty.source = '.. raw:: html\n  :url: http://www.zope.org/'
+        self.assertRaises(NotImplementedError, resty.render)
+
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestZReST))

Modified: Zope/branches/2.10/lib/python/reStructuredText/tests/testReST.py
===================================================================
--- Zope/branches/2.10/lib/python/reStructuredText/tests/testReST.py	2006-07-10 19:56:49 UTC (rev 69080)
+++ Zope/branches/2.10/lib/python/reStructuredText/tests/testReST.py	2006-07-10 19:57:10 UTC (rev 69081)
@@ -82,6 +82,32 @@
         self.assertEquals(output, expected) 
 
 
+    def test_include_directive_raises(self):
+        source = 'hello world\n .. include:: /etc/passwd'
+        self.assertRaises(NotImplementedError, HTML, source)
+
+    def test_raw_directive_disabled(self):
+
+        EXPECTED = '<h1>HELLO WORLD</h1>'
+
+        source = '.. raw:: html\n\n  %s\n' % EXPECTED
+        result = HTML(source)       # don't raise, but don't work either
+        self.failIf(EXPECTED in result)
+
+        self.failUnless("&quot;raw&quot; directive disabled" in result)
+        from cgi import escape
+        self.failUnless(escape(EXPECTED) in result)
+
+    def test_raw_directive_file_option_raises(self):
+
+        source = '.. raw:: html\n  :file: inclusion.txt'
+        self.assertRaises(NotImplementedError, HTML, source)
+
+    def test_raw_directive_url_option_raises(self):
+
+        source = '.. raw:: html\n  :url: http://www.zope.org'
+        self.assertRaises(NotImplementedError, HTML, source)
+
 def test_suite():
     from unittest import TestSuite, makeSuite
     return TestSuite((makeSuite(TestReST),))



More information about the Zope-Checkins mailing list