From 67a0fc8ea3b633a71187d1ba7dc9357ac1af5606 Mon Sep 17 00:00:00 2001 From: Rabi Panda Date: Sat, 6 Feb 2021 20:55:31 -0800 Subject: [PATCH] Remove packaging tests for the x-pack command line tools. --- .../packaging/test/ArchiveTests.java | 45 ------ .../packaging/test/CertGenCliTests.java | 114 ------------- .../packaging/test/CronEvalCliTests.java | 51 ------ .../packaging/test/DockerTests.java | 24 --- .../packaging/test/PasswordToolsTests.java | 151 ------------------ .../packaging/util/Archives.java | 27 ---- .../elasticsearch/packaging/util/Docker.java | 18 --- .../packaging/util/Installation.java | 6 - .../packaging/util/Packages.java | 20 --- 9 files changed, 456 deletions(-) delete mode 100644 qa/os/src/test/java/org/elasticsearch/packaging/test/CertGenCliTests.java delete mode 100644 qa/os/src/test/java/org/elasticsearch/packaging/test/CronEvalCliTests.java delete mode 100644 qa/os/src/test/java/org/elasticsearch/packaging/test/PasswordToolsTests.java diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java b/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java index 786bce6d471a0..f6f36614fd039 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java @@ -334,27 +334,6 @@ public void test80RelativePathConf() throws Exception { }); } - 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 void test93ElasticsearchNodeCustomDataPathAndNotEsHomeWorkDir() throws Ex 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); - } - } - } diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/test/CertGenCliTests.java b/qa/os/src/test/java/org/elasticsearch/packaging/test/CertGenCliTests.java deleted file mode 100644 index bd48309ca5ae8..0000000000000 --- a/qa/os/src/test/java/org/elasticsearch/packaging/test/CertGenCliTests.java +++ /dev/null @@ -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 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 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")) - ); - } -} diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/test/CronEvalCliTests.java b/qa/os/src/test/java/org/elasticsearch/packaging/test/CronEvalCliTests.java deleted file mode 100644 index 136ed4e1168de..0000000000000 --- a/qa/os/src/test/java/org/elasticsearch/packaging/test/CronEvalCliTests.java +++ /dev/null @@ -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!")); - } -} diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/test/DockerTests.java b/qa/os/src/test/java/org/elasticsearch/packaging/test/DockerTests.java index abcd0f521dd9c..deaf896314bb7 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/test/DockerTests.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/test/DockerTests.java @@ -449,30 +449,6 @@ public void test085EnvironmentVariablesAreRespectedUnderDockerExec() { 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. */ diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/test/PasswordToolsTests.java b/qa/os/src/test/java/org/elasticsearch/packaging/test/PasswordToolsTests.java deleted file mode 100644 index 042e04509998e..0000000000000 --- a/qa/os/src/test/java/org/elasticsearch/packaging/test/PasswordToolsTests.java +++ /dev/null @@ -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 userpasses = parseUsersAndPasswords(result.stdout); - for (Map.Entry 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 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 userpasses = parseUsersAndPasswords(result.stdout); - assertThat(userpasses, hasKey("elastic")); - for (Map.Entry 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 parseUsersAndPasswords(String output) { - Matcher matcher = USERPASS_REGEX.matcher(output); - assertNotNull(matcher); - Map userpases = new HashMap<>(); - while (matcher.find()) { - userpases.put(matcher.group(1), matcher.group(2)); - } - return userpases; - } -} diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/util/Archives.java b/qa/os/src/test/java/org/elasticsearch/packaging/util/Archives.java index f7dba382557f1..ba67e7161dc52 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/util/Archives.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/util/Archives.java @@ -158,9 +158,6 @@ private static void setupArchiveUsersLinux(Path installPath) { 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 @@ private static void verifyOssInstallation(Installation es, Distribution distribu .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); } diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/util/Docker.java b/qa/os/src/test/java/org/elasticsearch/packaging/util/Docker.java index 0e6a4541f12c0..e619d6f0e299f 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/util/Docker.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/util/Docker.java @@ -484,9 +484,6 @@ public static void waitForPathToExist(Path path) throws InterruptedException { */ 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 @@ private static void verifyOssInstallation(Installation es) { }); } - 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)); } diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/util/Installation.java b/qa/os/src/test/java/org/elasticsearch/packaging/util/Installation.java index b7a00118540d0..c144c7e0d869f 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/util/Installation.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/util/Installation.java @@ -191,13 +191,7 @@ public class Executables { 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"); } } diff --git a/qa/os/src/test/java/org/elasticsearch/packaging/util/Packages.java b/qa/os/src/test/java/org/elasticsearch/packaging/util/Packages.java index 369ad170430ce..5c1c89cbeaa25 100644 --- a/qa/os/src/test/java/org/elasticsearch/packaging/util/Packages.java +++ b/qa/os/src/test/java/org/elasticsearch/packaging/util/Packages.java @@ -163,9 +163,6 @@ public static void remove(Distribution distribution) throws Exception { 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 @@ private static void verifyOssInstallation(Installation es, Distribution distribu } } - 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. */