You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by is...@apache.org on 2018/05/06 17:45:14 UTC
[2/2] lucene-solr:branch_7_3: SOLR-12316: Fix test to work on linux
and test also windows in a better way
SOLR-12316: Fix test to work on linux and test also windows in a better way
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ae0705ed
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ae0705ed
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ae0705ed
Branch: refs/heads/branch_7_3
Commit: ae0705edb59eaa567fe13ed3a222fdadc7153680
Parents: 6c4e45e
Author: Uwe Schindler <us...@apache.org>
Authored: Sun May 6 15:53:07 2018 +0200
Committer: Ishan Chattopadhyaya <is...@apache.org>
Committed: Sun May 6 23:13:48 2018 +0530
----------------------------------------------------------------------
.../apache/solr/util/TestSystemIdResolver.java | 30 +++++++++++++-------
1 file changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ae0705ed/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java b/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
index 4c2677d..f87eeb4 100644
--- a/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
+++ b/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
@@ -19,6 +19,7 @@ package org.apache.solr.util;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
+import java.util.Arrays;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.analysis.util.ResourceLoader;
@@ -29,11 +30,6 @@ import org.xml.sax.InputSource;
public class TestSystemIdResolver extends LuceneTestCase {
- public void setUp() throws Exception {
- super.setUp();
- System.setProperty("solr.allow.unsafe.resourceloading", "true");
- }
-
public void tearDown() throws Exception {
System.clearProperty("solr.allow.unsafe.resourceloading");
super.tearDown();
@@ -74,8 +70,6 @@ public class TestSystemIdResolver extends LuceneTestCase {
"solrres:/org/apache/solr/util/RTimer.class", "TestSystemIdResolver.class");
assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome+"/collection1/conf/schema.xml"),
SystemIdResolver.createSystemIdFromResourceName(testHome+"/collection1/conf/solrconfig.xml"), "schema.xml");
- assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-schema.xml"),
- SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-config.xml"), "crazy-path-to-schema.xml");
// if somebody uses an absolute uri (e.g., file://) we should fail resolving:
IOException ioe = expectThrows(IOException.class, () -> {
@@ -89,10 +83,24 @@ public class TestSystemIdResolver extends LuceneTestCase {
assertTrue(ioe.getMessage().startsWith("Cannot resolve absolute"));
// check that we can't escape with absolute file paths:
- ioe = expectThrows(IOException.class, () -> {
- resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", "/etc/passwd");
- });
- assertTrue(ioe.getMessage().startsWith("Can't find resource '/etc/passwd' in classpath or"));
+ for (String path : Arrays.asList("/etc/passwd", "/windows/notepad.exe")) {
+ ioe = expectThrows(IOException.class, () -> {
+ resolver.resolveEntity(null, null, "solrres:/solrconfig.xml", path);
+ });
+ assertTrue(ioe.getMessage().startsWith("Can't find resource")
+ || ioe.getMessage().contains("is outside resource loader dir"));
+ }
+ }
+
+ public void testUnsafeResolving() throws Exception {
+ System.setProperty("solr.allow.unsafe.resourceloading", "true");
+
+ final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
+ final ResourceLoader loader = new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
+ final SystemIdResolver resolver = new SystemIdResolver(loader);
+
+ assertEntityResolving(resolver, SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-schema.xml"),
+ SystemIdResolver.createSystemIdFromResourceName(testHome+"/crazy-path-to-config.xml"), "crazy-path-to-schema.xml");
}
}