lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [41/50] [abbrv] lucene-solr:jira/solr-11779: SOLR-12316: Fix test to work on linux and test also windows in a better way
Date Tue, 08 May 2018 21:15:27 GMT
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/fb5b42a0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/fb5b42a0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/fb5b42a0

Branch: refs/heads/jira/solr-11779
Commit: fb5b42a0e4bb55f82985282a68fff01015c9693f
Parents: 1b76011
Author: Uwe Schindler <uschindler@apache.org>
Authored: Sun May 6 15:53:07 2018 +0200
Committer: Uwe Schindler <uschindler@apache.org>
Committed: Sun May 6 15:53:07 2018 +0200

----------------------------------------------------------------------
 .../apache/solr/util/TestSystemIdResolver.java  | 30 +++++++++++++-------
 1 file changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/fb5b42a0/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");    
   }
 
 }


Mime
View raw message