Skip to content

Commit 1f3b26d

Browse files
Factor out CA certificate in packaging tests
1 parent 774c1f0 commit 1f3b26d

File tree

10 files changed

+136
-150
lines changed

10 files changed

+136
-150
lines changed

qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveGenerateInitialCredentialsTests.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.elasticsearch.packaging.test;
1010

11-
import org.apache.http.client.fluent.Request;
1211
import org.elasticsearch.packaging.util.Distribution;
1312
import org.elasticsearch.packaging.util.FileUtils;
1413
import org.elasticsearch.packaging.util.ServerUtils;
@@ -83,12 +82,7 @@ public void test40VerifyAutogeneratedCredentials() throws Exception {
8382
assertThat(parseElasticPassword(result.stdout), notNullValue());
8483
assertThat(parseKibanaToken(result.stdout), notNullValue());
8584
assertThat(parseFingerprint(result.stdout), notNullValue());
86-
String response = ServerUtils.makeRequest(
87-
Request.Get("https://localhost:9200"),
88-
"elastic",
89-
parseElasticPassword(result.stdout),
90-
ServerUtils.getCaCert(installation)
91-
);
85+
String response = makeRequestAsElastic("https://localhost:9200", parseElasticPassword(result.stdout));
9286
assertThat(response, containsString("You Know, for Search"));
9387
}
9488

qa/os/src/test/java/org/elasticsearch/packaging/test/ArchiveTests.java

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static org.elasticsearch.packaging.util.FileUtils.append;
3737
import static org.elasticsearch.packaging.util.FileUtils.mv;
3838
import static org.elasticsearch.packaging.util.FileUtils.rm;
39-
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
4039
import static org.hamcrest.CoreMatchers.containsString;
4140
import static org.hamcrest.CoreMatchers.equalTo;
4241
import static org.hamcrest.CoreMatchers.is;
@@ -53,16 +52,10 @@ public static void filterDistros() {
5352
assumeTrue("only archives", distribution.isArchive());
5453
}
5554

56-
private static String superuser = "test_superuser";
57-
private static String superuserPassword = "test_superuser";
58-
5955
public void test10Install() throws Exception {
6056
installation = installArchive(sh, distribution());
6157
verifyArchiveInstallation(installation, distribution());
62-
Result result = sh.run(
63-
installation.executables().usersTool + " useradd " + superuser + " -p " + superuserPassword + " -r " + "superuser"
64-
);
65-
assumeTrue(result.isSuccess());
58+
setFileSuperuser("test_superuser", "test_superuser_password");
6659
// See https://bugs.openjdk.java.net/browse/JDK-8267701. In short, when generating PKCS#12 keystores in JDK 12 and later
6760
// the MAC algorithm used for integrity protection is incompatible with any previous JDK version. This affects us as we generate
6861
// PKCS12 keystores on startup ( with the bundled JDK ) but we also need to run certain tests with a JDK other than the bundled
@@ -208,7 +201,7 @@ public void test44AutoConfigurationNotTriggeredOnNotWriteableConfDir() throws Ex
208201
startElasticsearch();
209202
verifySecurityNotAutoConfigured(installation);
210203
// the node still starts, with Security enabled, but without TLS auto-configured (so only authentication)
211-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, null);
204+
runElasticsearchTests();
212205
stopElasticsearch();
213206
} finally {
214207
Platforms.onWindows(() -> {
@@ -294,10 +287,8 @@ public void test52AutoConfigurationOnWindows() throws Exception {
294287

295288
public void test60StartAndStop() throws Exception {
296289
startElasticsearch();
297-
298290
assertThat(installation.logs.resolve("gc.log"), fileExists());
299-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
300-
291+
runElasticsearchTests();
301292
stopElasticsearch();
302293
}
303294

@@ -312,7 +303,7 @@ public void test61EsJavaHomeOverride() throws Exception {
312303
});
313304

314305
startElasticsearch();
315-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
306+
runElasticsearchTests();
316307
stopElasticsearch();
317308

318309
String systemJavaHome1 = sh.getEnv().get("ES_JAVA_HOME");
@@ -339,7 +330,7 @@ public void test62JavaHomeIgnored() throws Exception {
339330
assertThat(runResult.stderr, containsString("warning: ignoring JAVA_HOME=" + systemJavaHome + "; using bundled JDK"));
340331

341332
startElasticsearch();
342-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
333+
runElasticsearchTests();
343334
stopElasticsearch();
344335

345336
// if the JDK started with the bundled JDK then we know that JAVA_HOME was ignored
@@ -363,7 +354,7 @@ public void test63BundledJdkRemoved() throws Exception {
363354
});
364355

365356
startElasticsearch();
366-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
357+
runElasticsearchTests();
367358
stopElasticsearch();
368359

369360
String systemJavaHome1 = sh.getEnv().get("ES_JAVA_HOME");
@@ -384,7 +375,7 @@ public void test64JavaHomeWithSpecialCharacters() throws Exception {
384375

385376
// verify ES can start, stop and run plugin list
386377
startElasticsearch();
387-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
378+
runElasticsearchTests();
388379
stopElasticsearch();
389380

390381
String pluginListCommand = installation.bin + "/elasticsearch-plugin list";
@@ -409,7 +400,7 @@ public void test64JavaHomeWithSpecialCharacters() throws Exception {
409400

410401
// verify ES can start, stop and run plugin list
411402
startElasticsearch();
412-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
403+
runElasticsearchTests();
413404
stopElasticsearch();
414405

415406
String pluginListCommand = installation.bin + "/elasticsearch-plugin list";
@@ -427,7 +418,7 @@ public void test65ForceBundledJdkEmptyJavaHome() throws Exception {
427418
sh.getEnv().put("ES_JAVA_HOME", "");
428419

429420
startElasticsearch();
430-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
421+
runElasticsearchTests();
431422
stopElasticsearch();
432423
}
433424

@@ -439,7 +430,7 @@ public void test65ForceBundledJdkEmptyJavaHome() throws Exception {
439430
public void test66InstallUnderPosix() throws Exception {
440431
sh.getEnv().put("POSIXLY_CORRECT", "1");
441432
startElasticsearch();
442-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
433+
runElasticsearchTests();
443434
stopElasticsearch();
444435
}
445436

@@ -452,11 +443,11 @@ public void test70CustomPathConfAndJvmOptions() throws Exception {
452443
sh.getEnv().put("ES_JAVA_OPTS", "-XX:-UseCompressedOops");
453444
startElasticsearch();
454445

455-
final String nodesResponse = makeRequest(
446+
final String nodesResponse = ServerUtils.makeRequest(
456447
Request.Get("https://localhost:9200/_nodes"),
457-
superuser,
458-
superuserPassword,
459-
ServerUtils.getCaCert(installation)
448+
"test_superuser",
449+
"test_superuser_password",
450+
ServerUtils.getCaCert(tempConf)
460451
);
461452
assertThat(nodesResponse, containsString("\"heap_init_in_bytes\":536870912"));
462453
assertThat(nodesResponse, containsString("\"using_compressed_ordinary_object_pointers\":\"false\""));
@@ -473,12 +464,7 @@ public void test71CustomJvmOptionsDirectoryFile() throws Exception {
473464

474465
startElasticsearch();
475466

476-
final String nodesResponse = makeRequest(
477-
Request.Get("https://localhost:9200/_nodes"),
478-
superuser,
479-
superuserPassword,
480-
ServerUtils.getCaCert(installation)
481-
);
467+
final String nodesResponse = makeRequest("https://localhost:9200/_nodes");
482468
assertThat(nodesResponse, containsString("\"heap_init_in_bytes\":536870912"));
483469

484470
stopElasticsearch();
@@ -501,12 +487,7 @@ public void test72CustomJvmOptionsDirectoryFilesAreProcessedInSortedOrder() thro
501487

502488
startElasticsearch();
503489

504-
final String nodesResponse = makeRequest(
505-
Request.Get("https://localhost:9200/_nodes"),
506-
superuser,
507-
superuserPassword,
508-
ServerUtils.getCaCert(installation)
509-
);
490+
final String nodesResponse = makeRequest("https://localhost:9200/_nodes");
510491
assertThat(nodesResponse, containsString("\"heap_init_in_bytes\":536870912"));
511492
assertThat(nodesResponse, containsString("\"using_compressed_ordinary_object_pointers\":\"false\""));
512493

@@ -523,7 +504,7 @@ public void test73CustomJvmOptionsDirectoryFilesWithoutOptionsExtensionIgnored()
523504
append(jvmOptionsIgnored, "-Xthis_is_not_a_valid_option\n");
524505

525506
startElasticsearch();
526-
ServerUtils.runElasticsearchTests(superuser, superuserPassword, ServerUtils.getCaCert(installation));
507+
runElasticsearchTests();
527508
stopElasticsearch();
528509
} finally {
529510
rm(jvmOptionsIgnored);
@@ -535,12 +516,7 @@ public void test80RelativePathConf() throws Exception {
535516
append(tempConf.resolve("elasticsearch.yml"), "node.name: relative");
536517
startElasticsearch();
537518

538-
final String nodesResponse = makeRequest(
539-
Request.Get("https://localhost:9200/_nodes"),
540-
superuser,
541-
superuserPassword,
542-
ServerUtils.getCaCert(installation)
543-
);
519+
final String nodesResponse = makeRequest("https://localhost:9200/_nodes");
544520
assertThat(nodesResponse, containsString("\"name\":\"relative\""));
545521

546522
stopElasticsearch();

qa/os/src/test/java/org/elasticsearch/packaging/test/ConfigurationTests.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,22 @@
1212
import org.elasticsearch.packaging.util.FileUtils;
1313
import org.elasticsearch.packaging.util.Platforms;
1414
import org.elasticsearch.packaging.util.ServerUtils;
15-
import org.elasticsearch.packaging.util.Shell;
1615
import org.junit.Before;
1716

1817
import static org.elasticsearch.packaging.util.FileUtils.append;
19-
import static org.elasticsearch.packaging.util.ServerUtils.makeRequest;
2018
import static org.hamcrest.Matchers.equalTo;
21-
import static org.hamcrest.Matchers.is;
2219
import static org.junit.Assume.assumeFalse;
2320

2421
public class ConfigurationTests extends PackagingTestCase {
2522

26-
private static String superuser = "test_superuser";
27-
private static String superuserPassword = "test_superuser";
28-
2923
@Before
3024
public void filterDistros() {
3125
assumeFalse("no docker", distribution.isDocker());
3226
}
3327

3428
public void test10Install() throws Exception {
3529
install();
36-
Shell.Result result = sh.run(
37-
installation.executables().usersTool + " useradd " + superuser + " -p " + superuserPassword + " -r " + "superuser"
38-
);
39-
assertThat(result.isSuccess(), is(true));
30+
setFileSuperuser("test_superuser", "test_superuser_password");
4031
}
4132

4233
public void test20HostnameSubstitution() throws Exception {
@@ -53,10 +44,10 @@ public void test20HostnameSubstitution() throws Exception {
5344
// security auto-config requires that the archive owner and the node process user be the same
5445
Platforms.onWindows(() -> sh.chown(confPath, installation.getOwner()));
5546
assertWhileRunning(() -> {
56-
final String nameResponse = makeRequest(
47+
final String nameResponse = ServerUtils.makeRequest(
5748
Request.Get(protocol + "://localhost:9200/_cat/nodes?h=name"),
58-
superuser,
59-
superuserPassword,
49+
"test_superuser",
50+
"test_superuser_password",
6051
ServerUtils.getCaCert(confPath)
6152
).strip();
6253
assertThat(nameResponse, equalTo("mytesthost"));

qa/os/src/test/java/org/elasticsearch/packaging/test/DockerTests.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
*/
9494
public class DockerTests extends PackagingTestCase {
9595
private Path tempDir;
96-
private static final String USERNAME = "elastic";
9796
private static final String PASSWORD = "nothunter2";
9897

9998
@BeforeClass
@@ -125,13 +124,8 @@ public void test010Install() throws Exception {
125124
* Check that security is enabled
126125
*/
127126
public void test011SecurityEnabledStatus() throws Exception {
128-
waitForElasticsearch(installation, USERNAME, PASSWORD);
129-
final int statusCode = ServerUtils.makeRequestAndGetStatus(
130-
Request.Get("https://localhost:9200"),
131-
USERNAME,
132-
"wrong_password",
133-
ServerUtils.getCaCert(installation)
134-
);
127+
waitForElasticsearch(installation, "elastic", PASSWORD);
128+
final int statusCode = makeRequestAsElastic("wrong_password");
135129
assertThat(statusCode, equalTo(401));
136130
}
137131

@@ -226,7 +220,7 @@ public void test041AmazonCaCertsAreInTheKeystore() {
226220
* Check that when the keystore is created on startup, it is created with the correct permissions.
227221
*/
228222
public void test042KeystorePermissionsAreCorrect() {
229-
waitForElasticsearch(installation, USERNAME, PASSWORD);
223+
waitForElasticsearch(installation, "elastic", PASSWORD);
230224

231225
assertThat(installation.config("elasticsearch.keystore"), file(p660));
232226
}
@@ -236,11 +230,11 @@ public void test042KeystorePermissionsAreCorrect() {
236230
* is minimally functional.
237231
*/
238232
public void test050BasicApiTests() throws Exception {
239-
waitForElasticsearch(installation, USERNAME, PASSWORD);
233+
waitForElasticsearch(installation, "elastic", PASSWORD);
240234

241235
assertTrue(existsInContainer(installation.logs.resolve("gc.log")));
242236

243-
ServerUtils.runElasticsearchTests(USERNAME, PASSWORD, ServerUtils.getCaCert(installation));
237+
runElasticsearchTestsAsElastic(PASSWORD);
244238
}
245239

246240
/**
@@ -276,9 +270,9 @@ public void test070BindMountCustomPathConfAndJvmOptions() throws Exception {
276270
.envVar("ELASTIC_PASSWORD", PASSWORD)
277271
);
278272

279-
waitForElasticsearch(installation, USERNAME, PASSWORD);
273+
waitForElasticsearch(installation, "elastic", PASSWORD);
280274

281-
final JsonNode nodes = getJson("/_nodes", USERNAME, PASSWORD, ServerUtils.getCaCert(installation)).get("nodes");
275+
final JsonNode nodes = getJson("/_nodes", "elastic", PASSWORD, ServerUtils.getCaCert(installation)).get("nodes");
282276
final String nodeId = nodes.fieldNames().next();
283277

284278
final int heapSize = nodes.at("/" + nodeId + "/jvm/mem/heap_init_in_bytes").intValue();
@@ -304,9 +298,9 @@ public void test071BindMountCustomPathWithDifferentUID() throws Exception {
304298
distribution(),
305299
builder().volume(tempEsDataDir.toAbsolutePath(), installation.data).envVar("ELASTIC_PASSWORD", PASSWORD)
306300
);
307-
waitForElasticsearch(installation, USERNAME, PASSWORD);
301+
waitForElasticsearch(installation, "elastic", PASSWORD);
308302

309-
final JsonNode nodes = getJson("/_nodes", USERNAME, PASSWORD, ServerUtils.getCaCert(installation));
303+
final JsonNode nodes = getJson("/_nodes", "elastic", PASSWORD, ServerUtils.getCaCert(installation));
310304

311305
assertThat(nodes.at("/_nodes/total").intValue(), equalTo(1));
312306
assertThat(nodes.at("/_nodes/successful").intValue(), equalTo(1));
@@ -360,7 +354,7 @@ public void test072RunEsAsDifferentUserAndGroup() throws Exception {
360354
.volume(tempEsLogsDir.toAbsolutePath(), installation.logs)
361355
);
362356

363-
waitForElasticsearch(installation, USERNAME, PASSWORD);
357+
waitForElasticsearch(installation, "elastic", PASSWORD);
364358
rmDirWithPrivilegeEscalation(tempEsConfigDir);
365359
rmDirWithPrivilegeEscalation(tempEsDataDir);
366360
rmDirWithPrivilegeEscalation(tempEsLogsDir);
@@ -374,7 +368,7 @@ public void test073RunEsAsDifferentUserAndGroupWithoutBindMounting() {
374368
// Restart the container
375369
runContainer(distribution(), builder().extraArgs("--group-add 0").uid(501, 501).envVar("ELASTIC_PASSWORD", PASSWORD));
376370

377-
waitForElasticsearch(installation, USERNAME, PASSWORD);
371+
waitForElasticsearch(installation, "elastic", PASSWORD);
378372
}
379373

380374
/**
@@ -778,7 +772,7 @@ public void test110OrgOpencontainersLabels() throws Exception {
778772
* Check that the container logs contain the expected content for Elasticsearch itself.
779773
*/
780774
public void test120DockerLogsIncludeElasticsearchLogs() {
781-
waitForElasticsearch(installation, USERNAME, PASSWORD);
775+
waitForElasticsearch(installation, "elastic", PASSWORD);
782776
final Result containerLogs = getContainerLogs();
783777

784778
assertThat("Container logs should contain full class names", containerLogs.stdout, containsString("org.elasticsearch.node.Node"));
@@ -791,7 +785,7 @@ public void test120DockerLogsIncludeElasticsearchLogs() {
791785
public void test121CanUseStackLoggingConfig() {
792786
runContainer(distribution(), builder().envVar("ES_LOG_STYLE", "file").envVar("ELASTIC_PASSWORD", PASSWORD));
793787

794-
waitForElasticsearch(installation, USERNAME, PASSWORD);
788+
waitForElasticsearch(installation, "elastic", PASSWORD);
795789

796790
final Result containerLogs = getContainerLogs();
797791
final List<String> stdout = containerLogs.stdout.lines().collect(Collectors.toList());
@@ -806,7 +800,7 @@ public void test121CanUseStackLoggingConfig() {
806800
public void test122CanUseDockerLoggingConfig() {
807801
runContainer(distribution(), builder().envVar("ES_LOG_STYLE", "console").envVar("ELASTIC_PASSWORD", PASSWORD));
808802

809-
waitForElasticsearch(installation, USERNAME, PASSWORD);
803+
waitForElasticsearch(installation, "elastic", PASSWORD);
810804

811805
final Result containerLogs = getContainerLogs();
812806
final List<String> stdout = containerLogs.stdout.lines().collect(Collectors.toList());
@@ -830,12 +824,12 @@ public void test123CannotUseUnknownLoggingConfig() {
830824
public void test124CanRestartContainerWithStackLoggingConfig() {
831825
runContainer(distribution(), builder().envVar("ES_LOG_STYLE", "file").envVar("ELASTIC_PASSWORD", PASSWORD));
832826

833-
waitForElasticsearch(installation, USERNAME, PASSWORD);
827+
waitForElasticsearch(installation, "elastic", PASSWORD);
834828

835829
restartContainer();
836830

837831
// If something went wrong running Elasticsearch the second time, this will fail.
838-
waitForElasticsearch(installation, USERNAME, PASSWORD);
832+
waitForElasticsearch(installation, "elastic", PASSWORD);
839833
}
840834

841835
/**
@@ -871,9 +865,9 @@ public void test131InitProcessHasCorrectPID() {
871865
* Check that Elasticsearch reports per-node cgroup information.
872866
*/
873867
public void test140CgroupOsStatsAreAvailable() throws Exception {
874-
waitForElasticsearch(installation, USERNAME, PASSWORD);
868+
waitForElasticsearch(installation, "elastic", PASSWORD);
875869

876-
final JsonNode nodes = getJson("/_nodes/stats/os", USERNAME, PASSWORD, ServerUtils.getCaCert(installation)).get("nodes");
870+
final JsonNode nodes = getJson("/_nodes/stats/os", "elastic", PASSWORD, ServerUtils.getCaCert(installation)).get("nodes");
877871

878872
final String nodeId = nodes.fieldNames().next();
879873

@@ -907,7 +901,7 @@ public void test150MachineDependentHeap() throws Exception {
907901
builder().memory("942m").volume(jvmOptionsPath, containerJvmOptionsPath).envVar("ELASTIC_PASSWORD", PASSWORD)
908902
);
909903

910-
waitForElasticsearch(installation, USERNAME, PASSWORD);
904+
waitForElasticsearch(installation, "elastic", PASSWORD);
911905

912906
// Grab the container output and find the line where it print the JVM arguments. This will
913907
// let us see what the automatic heap sizing calculated.

0 commit comments

Comments
 (0)