mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-21 20:35:54 +00:00
remove the ability for code to change file permissions, this was
only needed for pluginmanager's test, and pluginmanager doesn't even run with securitymanager yet.
This commit is contained in:
parent
6be9954d28
commit
3d8b4dae33
@ -102,6 +102,7 @@ allprojects {
|
||||
|
||||
subprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven {
|
||||
name 'sonatype-snapshots'
|
||||
|
@ -88,9 +88,6 @@ grant {
|
||||
// otherwise can be provided only to test libraries
|
||||
permission java.lang.RuntimePermission "fileSystemProvider";
|
||||
|
||||
// needed by plugin manager to set unix permissions
|
||||
permission java.lang.RuntimePermission "accessUserInformation";
|
||||
|
||||
// needed by jvminfo for monitoring the jvm
|
||||
permission java.lang.management.ManagementPermission "monitor";
|
||||
|
||||
|
@ -31,10 +31,8 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileExists;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileNotExists;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.elasticsearch.common.io.FileTestUtils.assertFileContent;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.elasticsearch.common.io.FileSystemUtils}.
|
||||
@ -138,25 +136,6 @@ public class FileSystemUtilsTests extends ESTestCase {
|
||||
assertFileContent(dst, "dir/file2.txt.new", "UPDATED");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a file contains a given String
|
||||
* @param dir root dir for file
|
||||
* @param filename relative path from root dir to file
|
||||
* @param expected expected content (if null, we don't expect any file)
|
||||
*/
|
||||
public static void assertFileContent(Path dir, String filename, String expected) throws IOException {
|
||||
Assert.assertThat(Files.exists(dir), is(true));
|
||||
Path file = dir.resolve(filename);
|
||||
if (expected == null) {
|
||||
Assert.assertThat("file [" + file + "] should not exist.", Files.exists(file), is(false));
|
||||
} else {
|
||||
assertFileExists(file);
|
||||
String fileContent = new String(Files.readAllBytes(file), java.nio.charset.StandardCharsets.UTF_8);
|
||||
// trim the string content to prevent different handling on windows vs. unix and CR chars...
|
||||
Assert.assertThat(fileContent.trim(), equalTo(expected.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testAppend() {
|
||||
assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 0),
|
||||
PathUtils.get("/foo/bar/hello/world/this_is/awesome"));
|
||||
|
@ -35,22 +35,9 @@ import static org.hamcrest.Matchers.contains;
|
||||
|
||||
public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
static void writeProperties(Path pluginDir, String... stringProps) throws IOException {
|
||||
assert stringProps.length % 2 == 0;
|
||||
Files.createDirectories(pluginDir);
|
||||
Path propertiesFile = pluginDir.resolve(PluginInfo.ES_PLUGIN_PROPERTIES);
|
||||
Properties properties = new Properties();
|
||||
for (int i = 0; i < stringProps.length; i += 2) {
|
||||
properties.put(stringProps[i], stringProps[i + 1]);
|
||||
}
|
||||
try (OutputStream out = Files.newOutputStream(propertiesFile)) {
|
||||
properties.store(out, "");
|
||||
}
|
||||
}
|
||||
|
||||
public void testReadFromProperties() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", "my_plugin",
|
||||
"version", "1.0",
|
||||
@ -71,7 +58,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesNameMissing() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir);
|
||||
PluginTestUtil.writeProperties(pluginDir);
|
||||
try {
|
||||
PluginInfo.readFromProperties(pluginDir);
|
||||
fail("expected missing name exception");
|
||||
@ -79,7 +66,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
assertTrue(e.getMessage().contains("Property [name] is missing in"));
|
||||
}
|
||||
|
||||
writeProperties(pluginDir, "name", "");
|
||||
PluginTestUtil.writeProperties(pluginDir, "name", "");
|
||||
try {
|
||||
PluginInfo.readFromProperties(pluginDir);
|
||||
fail("expected missing name exception");
|
||||
@ -90,7 +77,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesDescriptionMissing() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir, "name", "fake-plugin");
|
||||
PluginTestUtil.writeProperties(pluginDir, "name", "fake-plugin");
|
||||
try {
|
||||
PluginInfo.readFromProperties(pluginDir);
|
||||
fail("expected missing description exception");
|
||||
@ -101,7 +88,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesVersionMissing() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir, "description", "fake desc", "name", "fake-plugin");
|
||||
PluginTestUtil.writeProperties(pluginDir, "description", "fake desc", "name", "fake-plugin");
|
||||
try {
|
||||
PluginInfo.readFromProperties(pluginDir);
|
||||
fail("expected missing version exception");
|
||||
@ -112,7 +99,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesJvmAndSiteMissing() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"version", "1.0",
|
||||
"name", "my_plugin");
|
||||
@ -126,7 +113,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesElasticsearchVersionMissing() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", "my_plugin",
|
||||
"version", "1.0",
|
||||
@ -141,7 +128,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesJavaVersionMissing() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", "my_plugin",
|
||||
"elasticsearch.version", Version.CURRENT.toString(),
|
||||
@ -158,7 +145,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
public void testReadFromPropertiesJavaVersionIncompatible() throws Exception {
|
||||
String pluginName = "fake-plugin";
|
||||
Path pluginDir = createTempDir().resolve(pluginName);
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", pluginName,
|
||||
"elasticsearch.version", Version.CURRENT.toString(),
|
||||
@ -177,7 +164,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
public void testReadFromPropertiesBadJavaVersionFormat() throws Exception {
|
||||
String pluginName = "fake-plugin";
|
||||
Path pluginDir = createTempDir().resolve(pluginName);
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", pluginName,
|
||||
"elasticsearch.version", Version.CURRENT.toString(),
|
||||
@ -195,7 +182,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesBogusElasticsearchVersion() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"version", "1.0",
|
||||
"jvm", "true",
|
||||
@ -211,7 +198,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesOldElasticsearchVersion() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", "my_plugin",
|
||||
"version", "1.0",
|
||||
@ -227,7 +214,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesJvmMissingClassname() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", "my_plugin",
|
||||
"version", "1.0",
|
||||
@ -245,7 +232,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
public void testReadFromPropertiesSitePlugin() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
Files.createDirectories(pluginDir.resolve("_site"));
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", "my_plugin",
|
||||
"version", "1.0",
|
||||
@ -258,7 +245,7 @@ public class PluginInfoTests extends ESTestCase {
|
||||
|
||||
public void testReadFromPropertiesSitePluginWithoutSite() throws Exception {
|
||||
Path pluginDir = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(pluginDir,
|
||||
PluginTestUtil.writeProperties(pluginDir,
|
||||
"description", "fake desc",
|
||||
"name", "my_plugin",
|
||||
"version", "1.0",
|
||||
|
@ -43,7 +43,6 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static java.nio.file.attribute.PosixFilePermission.*;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.plugins.PluginInfoTests.writeProperties;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@ -319,7 +318,7 @@ public class PluginManagerPermissionTests extends ESTestCase {
|
||||
|
||||
private URL createPlugin(boolean withBinDir, boolean withConfigDir) throws IOException {
|
||||
final Path structure = createTempDir().resolve("fake-plugin");
|
||||
writeProperties(structure, "description", "fake desc",
|
||||
PluginTestUtil.writeProperties(structure, "description", "fake desc",
|
||||
"version", "1.0",
|
||||
"elasticsearch.version", Version.CURRENT.toString(),
|
||||
"jvm", "true",
|
@ -71,9 +71,8 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static org.elasticsearch.common.cli.CliTool.ExitStatus.USAGE;
|
||||
import static org.elasticsearch.common.cli.CliToolTestCase.args;
|
||||
import static org.elasticsearch.common.io.FileSystemUtilsTests.assertFileContent;
|
||||
import static org.elasticsearch.common.io.FileTestUtils.assertFileContent;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.plugins.PluginInfoTests.writeProperties;
|
||||
import static org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@ -83,7 +82,7 @@ import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||
@LuceneTestCase.SuppressFileSystems("*") // TODO: clean up this test to allow extra files
|
||||
// TODO: jimfs is really broken here (throws wrong exception from detection method).
|
||||
// if its in your classpath, then do not use plugins!!!!!!
|
||||
public class PluginManagerIT extends ESIntegTestCase {
|
||||
public class PluginManagerTests extends ESIntegTestCase {
|
||||
|
||||
private Environment environment;
|
||||
private CaptureOutputTerminal terminal = new CaptureOutputTerminal();
|
||||
@ -129,7 +128,7 @@ public class PluginManagerIT extends ESIntegTestCase {
|
||||
|
||||
/** creates a plugin .zip and returns the url for testing */
|
||||
private String createPlugin(final Path structure, String... properties) throws IOException {
|
||||
writeProperties(structure, properties);
|
||||
PluginTestUtil.writeProperties(structure, properties);
|
||||
Path zip = createTempDir().resolve(structure.getFileName() + ".zip");
|
||||
try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(zip))) {
|
||||
Files.walkFileTree(structure, new SimpleFileVisitor<Path>() {
|
||||
@ -151,7 +150,7 @@ public class PluginManagerIT extends ESIntegTestCase {
|
||||
|
||||
/** creates a plugin .zip and bad checksum file and returns the url for testing */
|
||||
private String createPluginWithBadChecksum(final Path structure, String... properties) throws IOException {
|
||||
writeProperties(structure, properties);
|
||||
PluginTestUtil.writeProperties(structure, properties);
|
||||
Path zip = createTempDir().resolve(structure.getFileName() + ".zip");
|
||||
try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(zip))) {
|
||||
Files.walkFileTree(structure, new SimpleFileVisitor<Path>() {
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.io;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileExists;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
/** test helper methods for working with files */
|
||||
public class FileTestUtils {
|
||||
|
||||
/**
|
||||
* Check that a file contains a given String
|
||||
* @param dir root dir for file
|
||||
* @param filename relative path from root dir to file
|
||||
* @param expected expected content (if null, we don't expect any file)
|
||||
*/
|
||||
public static void assertFileContent(Path dir, String filename, String expected) throws IOException {
|
||||
Assert.assertThat(Files.exists(dir), is(true));
|
||||
Path file = dir.resolve(filename);
|
||||
if (expected == null) {
|
||||
Assert.assertThat("file [" + file + "] should not exist.", Files.exists(file), is(false));
|
||||
} else {
|
||||
assertFileExists(file);
|
||||
String fileContent = new String(Files.readAllBytes(file), java.nio.charset.StandardCharsets.UTF_8);
|
||||
// trim the string content to prevent different handling on windows vs. unix and CR chars...
|
||||
Assert.assertThat(fileContent.trim(), equalTo(expected.trim()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.plugins;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Properties;
|
||||
|
||||
/** Utility methods for testing plugins */
|
||||
public class PluginTestUtil {
|
||||
|
||||
/** convenience method to write a plugin properties file */
|
||||
public static void writeProperties(Path pluginDir, String... stringProps) throws IOException {
|
||||
assert stringProps.length % 2 == 0;
|
||||
Files.createDirectories(pluginDir);
|
||||
Path propertiesFile = pluginDir.resolve(PluginInfo.ES_PLUGIN_PROPERTIES);
|
||||
Properties properties = new Properties();
|
||||
for (int i = 0; i < stringProps.length; i += 2) {
|
||||
properties.put(stringProps[i], stringProps[i + 1]);
|
||||
}
|
||||
try (OutputStream out = Files.newOutputStream(propertiesFile)) {
|
||||
properties.store(out, "");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user