You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/07/22 22:05:13 UTC
svn commit: r1612678 -
/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLPropertiesConfiguration.java
Author: oheger
Date: Tue Jul 22 20:05:13 2014
New Revision: 1612678
URL: http://svn.apache.org/r1612678
Log:
Prevented TestXMLPropertiesConfiguration to access the internet.
A test case used to load a configuration file which references a DTD. This
caused an internet access. Now an entity resolver is set to avoid this.
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLPropertiesConfiguration.java
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLPropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLPropertiesConfiguration.java?rev=1612678&r1=1612677&r2=1612678&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLPropertiesConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLPropertiesConfiguration.java Tue Jul 22 20:05:13 2014
@@ -20,9 +20,6 @@ package org.apache.commons.configuration
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import java.io.File;
-import java.net.URL;
-
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
@@ -30,6 +27,8 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import java.io.File;
+import java.net.URL;
import org.apache.commons.configuration.ex.ConfigurationException;
import org.apache.commons.configuration.io.FileHandler;
@@ -37,6 +36,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.w3c.dom.Document;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
/**
* Test class for {@code XMLPropertiesConfiguration}.
@@ -87,6 +88,15 @@ public class TestXMLPropertiesConfigurat
URL location = ConfigurationAssert.getTestURL(TEST_PROPERTIES_FILE);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ dBuilder.setEntityResolver(new EntityResolver()
+ {
+ @Override
+ public InputSource resolveEntity(String publicId, String systemId)
+ {
+ return new InputSource(getClass().getClassLoader()
+ .getResourceAsStream("properties.dtd"));
+ }
+ });
File file = new File(location.toURI());
Document doc = dBuilder.parse(file);
XMLPropertiesConfiguration conf = new XMLPropertiesConfiguration(doc.getDocumentElement());