You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kr...@apache.org on 2019/12/07 21:34:22 UTC
[lucene-solr] branch branch_8x updated: SOLR-14028: Fix test
permissions for TestSolrCLIRunExample
This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new 970264c SOLR-14028: Fix test permissions for TestSolrCLIRunExample
970264c is described below
commit 970264c6d2cd5fa3bfdcf022714bd72220be4cee
Author: Kevin Risden <kr...@apache.org>
AuthorDate: Sat Dec 7 00:47:52 2019 -0500
SOLR-14028: Fix test permissions for TestSolrCLIRunExample
Signed-off-by: Kevin Risden <kr...@apache.org>
---
lucene/common-build.xml | 1 -
lucene/tools/junit4/solr-tests.policy | 2 +-
.../java/org/apache/solr/util/SimplePostTool.java | 64 ++++++++++++++--------
3 files changed, 41 insertions(+), 26 deletions(-)
diff --git a/lucene/common-build.xml b/lucene/common-build.xml
index 2e45f62..45d9481 100644
--- a/lucene/common-build.xml
+++ b/lucene/common-build.xml
@@ -1174,7 +1174,6 @@
<!-- Restrict access to certain Java features and install security manager: -->
<sysproperty key="common.dir" file="${common.dir}" />
- <sysproperty key="common-solr.dir" file="${common.dir}/../solr" />
<sysproperty key="ant.library.dir" file="${ant.library.dir}" />
<sysproperty key="clover.db.dir" file="${clover.db.dir}" />
<syspropertyset>
diff --git a/lucene/tools/junit4/solr-tests.policy b/lucene/tools/junit4/solr-tests.policy
index 88beda0..7de5660 100644
--- a/lucene/tools/junit4/solr-tests.policy
+++ b/lucene/tools/junit4/solr-tests.policy
@@ -21,7 +21,7 @@ grant {
// contain read access to only what we need:
// 3rd party jar resources (where symlinks are not supported), test-files/ resources
permission java.io.FilePermission "${common.dir}${/}-", "read";
- permission java.io.FilePermission "${common-solr.dir}${/}-", "read";
+ permission java.io.FilePermission "${common.dir}${/}..${/}solr${/}-", "read";
// 3rd party jar resources (where symlinks are supported)
permission java.io.FilePermission "${user.home}${/}.ivy2${/}cache${/}-", "read";
// system jar resources
diff --git a/solr/core/src/java/org/apache/solr/util/SimplePostTool.java b/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
index d48c413..bad5959 100644
--- a/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
+++ b/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
@@ -42,6 +42,7 @@ import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.nio.file.InvalidPathException;
import java.security.GeneralSecurityException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -434,6 +435,15 @@ public class SimplePostTool {
"The web mode is a simple crawler following links within domain, default delay=10s.");
}
+ private boolean checkIsValidPath(File srcFile) {
+ try {
+ srcFile.toPath();
+ return true;
+ } catch (InvalidPathException e) {
+ return false;
+ }
+ }
+
/** Post all filenames provided in args
* @param args array of file names
* @param startIndexInArgs offset to start
@@ -446,21 +456,13 @@ public class SimplePostTool {
int filesPosted = 0;
for (int j = startIndexInArgs; j < args.length; j++) {
File srcFile = new File(args[j]);
- if(srcFile.isDirectory() && srcFile.canRead()) {
+ boolean isValidPath = checkIsValidPath(srcFile);
+ if(isValidPath && srcFile.isDirectory() && srcFile.canRead()) {
filesPosted += postDirectory(srcFile, out, type);
- } else if (srcFile.isFile() && srcFile.canRead()) {
+ } else if (isValidPath && srcFile.isFile() && srcFile.canRead()) {
filesPosted += postFiles(new File[] {srcFile}, out, type);
} else {
- File parent = srcFile.getParentFile();
- if(parent == null) parent = new File(".");
- String fileGlob = srcFile.getName();
- GlobFileFilter ff = new GlobFileFilter(fileGlob, false);
- File[] files = parent.listFiles(ff);
- if(files == null || files.length == 0) {
- warn("No files or directories matching "+srcFile);
- continue;
- }
- filesPosted += postFiles(parent.listFiles(ff), out, type);
+ filesPosted += handleGlob(srcFile, out, type);
}
}
return filesPosted;
@@ -477,21 +479,13 @@ public class SimplePostTool {
reset();
int filesPosted = 0;
for (File srcFile : files) {
- if(srcFile.isDirectory() && srcFile.canRead()) {
+ boolean isValidPath = checkIsValidPath(srcFile);
+ if(isValidPath && srcFile.isDirectory() && srcFile.canRead()) {
filesPosted += postDirectory(srcFile, out, type);
- } else if (srcFile.isFile() && srcFile.canRead()) {
+ } else if (isValidPath && srcFile.isFile() && srcFile.canRead()) {
filesPosted += postFiles(new File[] {srcFile}, out, type);
} else {
- File parent = srcFile.getParentFile();
- if(parent == null) parent = new File(".");
- String fileGlob = srcFile.getName();
- GlobFileFilter ff = new GlobFileFilter(fileGlob, false);
- File[] fileList = parent.listFiles(ff);
- if(fileList == null || fileList.length == 0) {
- warn("No files or directories matching "+srcFile);
- continue;
- }
- filesPosted += postFiles(fileList, out, type);
+ filesPosted += handleGlob(srcFile, out, type);
}
}
return filesPosted;
@@ -540,6 +534,28 @@ public class SimplePostTool {
}
/**
+ * This only handles file globs not full path globbing.
+ * @param globFile file holding glob path
+ * @param out outputStream to write results to
+ * @param type default content-type to use when posting (may be overridden in auto mode)
+ * @return number of files posted
+ */
+ int handleGlob(File globFile, OutputStream out, String type) {
+ int filesPosted = 0;
+ File parent = globFile.getParentFile();
+ if (parent == null) parent = new File(".");
+ String fileGlob = globFile.getName();
+ GlobFileFilter ff = new GlobFileFilter(fileGlob, false);
+ File[] fileList = parent.listFiles(ff);
+ if (fileList == null || fileList.length == 0) {
+ warn("No files or directories matching " + globFile);
+ } else {
+ filesPosted = postFiles(fileList, out, type);
+ }
+ return filesPosted;
+ }
+
+ /**
* This method takes as input a list of start URL strings for crawling,
* adds each one to a backlog and then starts crawling
* @param args the raw input args from main()