Commits

Christian Heimes committed 6c9f83c

prevent web access
test dtd with external ref

  • Participants
  • Parent commits 6cc740b

Comments (0)

Files changed (1)

 
 HERE = os.path.dirname(os.path.abspath(__file__))
 
+# prevent web access
+# based on Debian's rules, Port 9 is discard
+os.environ["http_proxy"] = "http://127.0.9.1:9"
+os.environ["https_proxy"] = os.environ["http_proxy"]
+os.environ["ftp_proxy"] = os.environ["http_proxy"]
+
+
 class BaseTests(unittest.TestCase):
     module = None
 
     else:
         content_binary = True
 
+    dtd_external_ref = False
+
 
     xml_dtd = os.path.join(HERE, "xmltestdata", "dtd.xml")
     xml_external = os.path.join(HERE, "xmltestdata", "external.xml")
         self.assertRaises(EntitiesForbidden, self.parse, self.xml_quadratic)
         self.assertRaises(EntitiesForbidden, self.parse, self.xml_external)
 
-        #self.parse(self.xml_dtd)
         self.assertRaises(EntitiesForbidden, self.parseString,
                           self.get_content(self.xml_bomb))
         self.assertRaises(EntitiesForbidden, self.parseString,
                           self.get_content(self.xml_dtd),
                           forbid_dtd=True)
 
+    def test_dtd_with_external_ref(self):
+        if self.dtd_external_ref:
+            self.assertRaises(ExternalEntitiesForbidden, self.parse, self.xml_dtd)
+        else:
+            self.parse(self.xml_dtd)
+
+
 
 class TestDefusedcElementTree(BaseTests):
     module = cElementTree
     module = ElementTree
 
 
+
 class TestDefusedMinidom(BaseTests):
     module = minidom
 
 class TestDefusedPulldom(BaseTests):
     module = pulldom
 
+    dtd_external_ref = True
     iterparse = None
 
     def parse(self, xmlfile, **kwargs):
         dom = self.module.parseString(xmlstring, **kwargs)
         list(dom)
 
+
 class TestDefusedSax(BaseTests):
     module = sax
 
     content_binary = True
+    dtd_external_ref = True
 
     iterparse = None
 
         def test_entities_forbidden(self):
             self.assertRaises(NotSupportedError, self.parse, self.xml_bomb)
 
+        def test_dtd_with_external_ref(self):
+            self.assertRaises(NotSupportedError, self.parse, self.xml_dtd)
+
 
 def test_main():
     suite = unittest.TestSuite()