SOLR-14028: Fix test permissions for TestSolrCLIRunExample

Signed-off-by: Kevin Risden <krisden@apache.org>
This commit is contained in:
Kevin Risden 2019-12-07 00:47:52 -05:00
parent a1e51cd777
commit 7c8635d600
No known key found for this signature in database
GPG Key ID: 040FAE3292C5F73F
3 changed files with 41 additions and 26 deletions

View File

@ -1094,7 +1094,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>

View File

@ -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

View File

@ -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;
@ -539,6 +533,28 @@ public class SimplePostTool {
return filesPosted;
}
/**
* 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