Remove packaging tests for the x-pack command line tools. (#56)

Signed-off-by: Peter Nied <petern@amazon.com>
This commit is contained in:
Rabi Panda 2021-02-08 21:20:57 -08:00 committed by Peter Nied
parent 7381e68d14
commit 64d0e8aa0d
9 changed files with 0 additions and 456 deletions

View File

@ -334,27 +334,6 @@ public class ArchiveTests extends PackagingTestCase {
});
}
public void test90SecurityCliPackaging() throws Exception {
final Installation.Executables bin = installation.executables();
if (distribution().isDefault()) {
assertThat(installation.lib.resolve("tools").resolve("security-cli"), fileExists());
final Platforms.PlatformAction action = () -> {
Result result = sh.run(bin.certutilTool + " --help");
assertThat(result.stdout, containsString("Simplifies certificate creation for use with the Elastic Stack"));
// Ensure that the exit code from the java command is passed back up through the shell script
result = sh.runIgnoreExitCode(bin.certutilTool + " invalid-command");
assertThat(result.exitCode, is(not(0)));
assertThat(result.stderr, containsString("Unknown command [invalid-command]"));
};
Platforms.onLinux(action);
Platforms.onWindows(action);
} else {
assertThat(installation.lib.resolve("tools").resolve("security-cli"), fileDoesNotExist());
}
}
public void test91ElasticsearchShardCliPackaging() throws Exception {
final Installation.Executables bin = installation.executables();
@ -397,28 +376,4 @@ public class ArchiveTests extends PackagingTestCase {
Result result = sh.run("echo y | " + installation.executables().nodeTool + " unsafe-bootstrap");
assertThat(result.stdout, containsString("Master node was successfully bootstrapped"));
}
public void test94ElasticsearchNodeExecuteCliNotEsHomeWorkDir() throws Exception {
final Installation.Executables bin = installation.executables();
// Run the cli tools from the tmp dir
sh.setWorkingDirectory(getRootTempDir());
Platforms.PlatformAction action = () -> {
Result result = sh.run(bin.certutilTool + " -h");
assertThat(result.stdout, containsString("Simplifies certificate creation for use with the Elastic Stack"));
result = sh.run(bin.syskeygenTool + " -h");
assertThat(result.stdout, containsString("system key tool"));
result = sh.run(bin.setupPasswordsTool + " -h");
assertThat(result.stdout, containsString("Sets the passwords for reserved users"));
result = sh.run(bin.usersTool + " -h");
assertThat(result.stdout, containsString("Manages elasticsearch file users"));
};
// TODO: this should be checked on all distributions
if (distribution().isDefault()) {
Platforms.onLinux(action);
Platforms.onWindows(action);
}
}
}

View File

@ -1,114 +0,0 @@
/*
* 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.packaging.test;
import org.apache.http.client.fluent.Request;
import org.elasticsearch.packaging.util.Distribution;
import org.elasticsearch.packaging.util.FileUtils;
import org.elasticsearch.packaging.util.Platforms;
import org.elasticsearch.packaging.util.ServerUtils;
import org.elasticsearch.packaging.util.Shell;
import org.junit.Before;
import org.junit.BeforeClass;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import static com.carrotsearch.randomizedtesting.RandomizedTest.assumeFalse;
import static java.nio.file.StandardOpenOption.APPEND;
import static java.nio.file.StandardOpenOption.CREATE;
import static org.elasticsearch.packaging.util.FileMatcher.Fileness.File;
import static org.elasticsearch.packaging.util.FileMatcher.file;
import static org.elasticsearch.packaging.util.FileMatcher.p600;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assume.assumeTrue;
public class CertGenCliTests extends PackagingTestCase {
private static final Path instancesFile = getRootTempDir().resolve("instances.yml");
private static final Path certificatesFile = getRootTempDir().resolve("certificates.zip");
@Before
public void filterDistros() {
assumeTrue("only default distro", distribution.flavor == Distribution.Flavor.DEFAULT);
assumeFalse("no docker", distribution.isDocker());
}
@BeforeClass
public static void cleanupFiles() {
FileUtils.rm(instancesFile, certificatesFile);
}
public void test10Install() throws Exception {
install();
}
public void test20Help() {
Shell.Result result = installation.executables().certgenTool.run("--help");
assertThat(result.stdout, containsString("Simplifies certificate creation"));
}
public void test30Generate() throws Exception {
final List<String> yaml = new ArrayList<>();
yaml.add("instances:");
yaml.add(" - name: \"mynode\"");
yaml.add(" ip:");
yaml.add(" - \"127.0.0.1\"");
Files.write(instancesFile, yaml, CREATE, APPEND);
installation.executables().certgenTool.run("--in " + instancesFile + " --out " + certificatesFile);
String owner = installation.getOwner();
assertThat(certificatesFile, file(File, owner, owner, p600));
}
public void test31ExtractCerts() throws Exception {
// windows 2012 r2 has powershell 4.0, which lacks Expand-Archive
assumeFalse(Platforms.OS_NAME.equals("Windows Server 2012 R2"));
Path certsDir = installation.config("certs");
sh.extractZip(certificatesFile, certsDir);
Path caDir = certsDir.resolve("ca");
assertThat(caDir.resolve("ca.key"), file(File, null, null, null));
assertThat(caDir.resolve("ca.crt"), file(File, null, null, null));
Path nodeDir = certsDir.resolve("mynode");
assertThat(nodeDir.resolve("mynode.key"), file(File, null, null, null));
assertThat(nodeDir.resolve("mynode.crt"), file(File, null, null, null));
FileUtils.cp(certsDir, installation.config("certs"));
}
public void test40RunWithCert() throws Exception {
// windows 2012 r2 has powershell 4.0, which lacks Expand-Archive
assumeFalse(Platforms.OS_NAME.equals("Windows Server 2012 R2"));
List<String> yaml = new ArrayList<>();
yaml.add("node.name: mynode");
Files.write(installation.config("elasticsearch.yml"), yaml, CREATE, APPEND);
assertWhileRunning(
() -> ServerUtils.makeRequest(Request.Get("https://127.0.0.1:9200"), null, null, installation.config("certs/ca/ca.crt"))
);
}
}

View File

@ -1,51 +0,0 @@
/*
* 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.packaging.test;
import org.elasticsearch.packaging.util.Distribution;
import org.elasticsearch.packaging.util.Shell;
import org.junit.Before;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
public class CronEvalCliTests extends PackagingTestCase {
@Before
public void filterDistros() {
assumeTrue("only default distro", distribution.flavor == Distribution.Flavor.DEFAULT);
assumeFalse("no docker", distribution.isDocker());
}
public void test10Install() throws Exception {
install();
}
public void test20Help() throws Exception {
Shell.Result result = installation.executables().cronevalTool.run("--help");
assertThat(result.stdout, containsString("Validates and evaluates a cron expression"));
}
public void test30Run() throws Exception {
Shell.Result result = installation.executables().cronevalTool.run("'0 0 20 ? * MON-THU' -c 2");
assertThat(result.stdout, containsString("Valid!"));
}
}

View File

@ -449,30 +449,6 @@ public class DockerTests extends PackagingTestCase {
assertThat(result.stdout, containsString("java.net.UnknownHostException: this.is.not.valid: Name or service not known"));
}
/**
* Check whether the elasticsearch-certutil tool has been shipped correctly,
* and if present then it can execute.
*/
public void test090SecurityCliPackaging() {
final Installation.Executables bin = installation.executables();
final Path securityCli = installation.lib.resolve("tools").resolve("security-cli");
if (distribution().isDefault()) {
assertTrue(existsInContainer(securityCli));
Result result = sh.run(bin.certutilTool + " --help");
assertThat(result.stdout, containsString("Simplifies certificate creation for use with the Elastic Stack"));
// Ensure that the exit code from the java command is passed back up through the shell script
result = sh.runIgnoreExitCode(bin.certutilTool + " invalid-command");
assertThat(result.isSuccess(), is(false));
assertThat(result.stdout, containsString("Unknown command [invalid-command]"));
} else {
assertFalse(existsInContainer(securityCli));
}
}
/**
* Check that the elasticsearch-shard tool is shipped in the Docker image and is executable.
*/

View File

@ -1,151 +0,0 @@
/*
* 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.packaging.test;
import org.apache.http.client.fluent.Request;
import org.elasticsearch.packaging.util.Distribution;
import org.elasticsearch.packaging.util.FileUtils;
import org.elasticsearch.packaging.util.ServerUtils;
import org.elasticsearch.packaging.util.Shell;
import org.junit.Before;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.collection.IsMapContaining.hasKey;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
public class PasswordToolsTests extends PackagingTestCase {
private static final Pattern USERPASS_REGEX = Pattern.compile("PASSWORD (\\w+) = ([^\\s]+)");
private static final String BOOTSTRAP_PASSWORD = "myS3curepass";
@Before
public void filterDistros() {
assumeTrue("only default distro", distribution.flavor == Distribution.Flavor.DEFAULT);
assumeFalse("no docker", distribution.isDocker());
}
public void test010Install() throws Exception {
install();
}
public void test20GeneratePasswords() throws Exception {
assertWhileRunning(() -> {
Shell.Result result = installation.executables().setupPasswordsTool.run("auto --batch", null);
Map<String, String> userpasses = parseUsersAndPasswords(result.stdout);
for (Map.Entry<String, String> userpass : userpasses.entrySet()) {
String response = ServerUtils.makeRequest(
Request.Get("http://localhost:9200"),
userpass.getKey(),
userpass.getValue(),
null
);
assertThat(response, containsString("You Know, for Search"));
}
});
}
public void test30AddBootstrapPassword() throws Exception {
try (Stream<Path> dataFiles = Files.list(installation.data)) {
// delete each dir under data, not data itself
dataFiles.forEach(file -> {
if (distribution.platform != Distribution.Platform.WINDOWS) {
FileUtils.rm(file);
return;
}
// HACK: windows asynchronously releases file locks after processes exit. Unfortunately there is no clear way to wait on
// those locks being released. We might be able to use `openfiles /query`, but that requires modifying global settings
// in our windows images with `openfiles /local on` (which requires a restart, thus needs to be baked into the images).
// The following sleep allows time for windows to release the data file locks from Elasticsearch which was stopped in the
// previous test.
int retries = 30;
Exception failure = null;
while (retries-- > 0) {
try {
FileUtils.rm(file);
return;
} catch (Exception e) {
if (failure == null) {
failure = e;
} else {
failure.addSuppressed(e);
}
try {
Thread.sleep(1000);
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
return;
}
}
}
throw new RuntimeException("failed to delete " + file, failure);
});
}
installation.executables().keystoreTool.run("add --stdin bootstrap.password", BOOTSTRAP_PASSWORD);
assertWhileRunning(() -> {
String response = ServerUtils.makeRequest(
Request.Get("http://localhost:9200/_cluster/health?wait_for_status=green&timeout=180s"),
"elastic",
BOOTSTRAP_PASSWORD,
null
);
assertThat(response, containsString("\"status\":\"green\""));
});
}
public void test40GeneratePasswordsBootstrapAlreadySet() throws Exception {
assertWhileRunning(() -> {
Shell.Result result = installation.executables().setupPasswordsTool.run("auto --batch", null);
Map<String, String> userpasses = parseUsersAndPasswords(result.stdout);
assertThat(userpasses, hasKey("elastic"));
for (Map.Entry<String, String> userpass : userpasses.entrySet()) {
String response = ServerUtils.makeRequest(
Request.Get("http://localhost:9200"),
userpass.getKey(),
userpass.getValue(),
null
);
assertThat(response, containsString("You Know, for Search"));
}
});
}
private Map<String, String> parseUsersAndPasswords(String output) {
Matcher matcher = USERPASS_REGEX.matcher(output);
assertNotNull(matcher);
Map<String, String> userpases = new HashMap<>();
while (matcher.find()) {
userpases.put(matcher.group(1), matcher.group(2));
}
return userpases;
}
}

View File

@ -158,9 +158,6 @@ public class Archives {
public static void verifyArchiveInstallation(Installation installation, Distribution distribution) {
verifyOssInstallation(installation, distribution, ARCHIVE_OWNER);
if (distribution.flavor == Distribution.Flavor.DEFAULT) {
verifyDefaultInstallation(installation, distribution, ARCHIVE_OWNER);
}
}
private static void verifyOssInstallation(Installation es, Distribution distribution, String owner) {
@ -200,30 +197,6 @@ public class Archives {
.forEach(doc -> assertThat(es.home.resolve(doc), file(File, owner, owner, p644)));
}
private static void verifyDefaultInstallation(Installation es, Distribution distribution, String owner) {
Stream.of(
"elasticsearch-certgen",
"elasticsearch-certutil",
"elasticsearch-croneval",
"elasticsearch-migrate",
"elasticsearch-saml-metadata",
"elasticsearch-setup-passwords",
"elasticsearch-syskeygen",
"elasticsearch-users"
).forEach(executable -> {
assertThat(es.bin(executable), file(File, owner, owner, p755));
if (distribution.packaging == Distribution.Packaging.ZIP) {
assertThat(es.bin(executable + ".bat"), file(File, owner));
}
});
Stream.of("users", "users_roles", "roles.yml", "role_mapping.yml", "log4j2.properties")
.forEach(configFile -> assertThat(es.config(configFile), file(File, owner, owner, p660)));
}
public static Shell.Result startElasticsearch(Installation installation, Shell sh) {
return runElasticsearchStartCommand(installation, sh, null, true);
}

View File

@ -484,9 +484,6 @@ public class Docker {
*/
public static void verifyContainerInstallation(Installation installation, Distribution distribution) {
verifyOssInstallation(installation);
if (distribution.flavor == Distribution.Flavor.DEFAULT) {
verifyDefaultInstallation(installation);
}
}
private static void verifyOssInstallation(Installation es) {
@ -529,21 +526,6 @@ public class Docker {
});
}
private static void verifyDefaultInstallation(Installation es) {
Stream.of(
"elasticsearch-certgen",
"elasticsearch-certutil",
"elasticsearch-croneval",
"elasticsearch-saml-metadata",
"elasticsearch-setup-passwords",
"elasticsearch-syskeygen",
"elasticsearch-users"
).forEach(executable -> assertPermissionsAndOwnership(es.bin(executable), p755));
Stream.of("role_mapping.yml", "roles.yml", "users", "users_roles")
.forEach(configFile -> assertPermissionsAndOwnership(es.config(configFile), p660));
}
public static void waitForElasticsearch(Installation installation) throws Exception {
withLogging(() -> ServerUtils.waitForElasticsearch(installation));
}

View File

@ -191,13 +191,7 @@ public class Installation {
public final Executable elasticsearch = new Executable("elasticsearch");
public final Executable pluginTool = new Executable("elasticsearch-plugin");
public final Executable keystoreTool = new Executable("elasticsearch-keystore");
public final Executable certutilTool = new Executable("elasticsearch-certutil");
public final Executable certgenTool = new Executable("elasticsearch-certgen");
public final Executable cronevalTool = new Executable("elasticsearch-croneval");
public final Executable shardTool = new Executable("elasticsearch-shard");
public final Executable nodeTool = new Executable("elasticsearch-node");
public final Executable setupPasswordsTool = new Executable("elasticsearch-setup-passwords");
public final Executable syskeygenTool = new Executable("elasticsearch-syskeygen");
public final Executable usersTool = new Executable("elasticsearch-users");
}
}

View File

@ -163,9 +163,6 @@ public class Packages {
public static void verifyPackageInstallation(Installation installation, Distribution distribution, Shell sh) {
verifyOssInstallation(installation, distribution, sh);
if (distribution.flavor == Distribution.Flavor.DEFAULT) {
verifyDefaultInstallation(installation, distribution);
}
}
private static void verifyOssInstallation(Installation es, Distribution distribution, Shell sh) {
@ -228,23 +225,6 @@ public class Packages {
}
}
private static void verifyDefaultInstallation(Installation es, Distribution distribution) {
Stream.of(
"elasticsearch-certgen",
"elasticsearch-certutil",
"elasticsearch-croneval",
"elasticsearch-migrate",
"elasticsearch-saml-metadata",
"elasticsearch-setup-passwords",
"elasticsearch-syskeygen",
"elasticsearch-users"
).forEach(executable -> assertThat(es.bin(executable), file(File, "root", "root", p755)));
Stream.of("users", "users_roles", "roles.yml", "role_mapping.yml", "log4j2.properties")
.forEach(configFile -> assertThat(es.config(configFile), file(File, "root", "elasticsearch", p660)));
}
/**
* Starts Elasticsearch, without checking that startup is successful.
*/