You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2014/02/04 22:42:20 UTC

svn commit: r1564518 - /xerces/java/branches/xml-schema-1.1-dev/tests/jaxp/JAXPSecureProcessingTest.java

Author: mrglavas
Date: Tue Feb  4 21:42:20 2014
New Revision: 1564518

URL: http://svn.apache.org/r1564518
Log:
The EntityResolver should be invoked when jdk.xml.resolveExternalEntities is set to true and should not be invoked when the property has been set to false. Enhancing the tests to check for this expected behaviour.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/tests/jaxp/JAXPSecureProcessingTest.java

Modified: xerces/java/branches/xml-schema-1.1-dev/tests/jaxp/JAXPSecureProcessingTest.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/tests/jaxp/JAXPSecureProcessingTest.java?rev=1564518&r1=1564517&r2=1564518&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/tests/jaxp/JAXPSecureProcessingTest.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/tests/jaxp/JAXPSecureProcessingTest.java Tue Feb  4 21:42:20 2014
@@ -33,6 +33,8 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
@@ -388,6 +390,13 @@ public class JAXPSecureProcessingTest ex
     public void testSAXEnableExternalEntityResolution() throws Exception {
         System.setProperty(RESOLVE_EXTERNAL_ENTITIES_PROPERTY_NAME, "true");
         XMLReader reader = newSecureXMLReader();
+        reader.setEntityResolver(new EntityResolver() {
+            public InputSource resolveEntity(String publicId, String systemId)
+                    throws SAXException, IOException {
+                assertEquals("xerces:///x:/this/does/not/exist.xml", systemId);
+                return null;
+            }
+        });
         try {
             reader.parse(new InputData("badExternalEntity.xml"));
             fail("Expected IOException");
@@ -398,6 +407,13 @@ public class JAXPSecureProcessingTest ex
     public void testDOMEnableExternalEntityResolution() throws Exception {
         System.setProperty(RESOLVE_EXTERNAL_ENTITIES_PROPERTY_NAME, "true");
         DocumentBuilder reader = newSecureDocumentBuilder();
+        reader.setEntityResolver(new EntityResolver() {
+            public InputSource resolveEntity(String publicId, String systemId)
+                    throws SAXException, IOException {
+                assertEquals("xerces:///x:/this/does/not/exist.xml", systemId);
+                return null;
+            }
+        });
         try {
             reader.parse(new InputData("badExternalEntity.xml"));
             fail("Expected IOException");
@@ -408,6 +424,13 @@ public class JAXPSecureProcessingTest ex
     public void testSAXDisableExternalEntityResolution() throws Exception {
         System.setProperty(RESOLVE_EXTERNAL_ENTITIES_PROPERTY_NAME, "false");
         XMLReader reader = newSecureXMLReader();
+        reader.setEntityResolver(new EntityResolver() {
+            public InputSource resolveEntity(String publicId, String systemId)
+                    throws SAXException, IOException {
+                fail("resolveEntity call not expected.");
+                return null;
+            }
+        });
         reader.setContentHandler(new ContentHandler() {
             final int START_DOCUMENT = 0;
             final int START_ELEMENT = 1;
@@ -466,6 +489,13 @@ public class JAXPSecureProcessingTest ex
     public void testDOMDisableExternalEntityResolution() throws Exception {
         System.setProperty(RESOLVE_EXTERNAL_ENTITIES_PROPERTY_NAME, "false");
         DocumentBuilder reader = newSecureDocumentBuilder();
+        reader.setEntityResolver(new EntityResolver() {
+            public InputSource resolveEntity(String publicId, String systemId)
+                    throws SAXException, IOException {
+                fail("resolveEntity call not expected.");
+                return null;
+            }
+        });
         Document doc = reader.parse(new InputData("badExternalEntity.xml"));
         Element e = doc.getDocumentElement();
         assertEquals("root", e.getLocalName());



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org