20
20
package org .elasticsearch .packaging .test ;
21
21
22
22
import org .elasticsearch .packaging .util .Distribution ;
23
+ import org .elasticsearch .packaging .util .Docker ;
23
24
import org .elasticsearch .packaging .util .FileUtils ;
24
25
import org .elasticsearch .packaging .util .Installation ;
25
26
import org .elasticsearch .packaging .util .Platforms ;
35
36
import static org .elasticsearch .packaging .util .Archives .ARCHIVE_OWNER ;
36
37
import static org .elasticsearch .packaging .util .Archives .installArchive ;
37
38
import static org .elasticsearch .packaging .util .Archives .verifyArchiveInstallation ;
39
+ import static org .elasticsearch .packaging .util .Docker .assertPermissionsAndOwnership ;
40
+ import static org .elasticsearch .packaging .util .Docker .waitForPathToExist ;
38
41
import static org .elasticsearch .packaging .util .FileMatcher .Fileness .File ;
39
42
import static org .elasticsearch .packaging .util .FileMatcher .file ;
40
43
import static org .elasticsearch .packaging .util .FileMatcher .p660 ;
45
48
import static org .elasticsearch .packaging .util .Packages .verifyPackageInstallation ;
46
49
import static org .hamcrest .CoreMatchers .containsString ;
47
50
import static org .hamcrest .CoreMatchers .is ;
48
- import static org .hamcrest .CoreMatchers .not ;
49
51
import static org .hamcrest .CoreMatchers .notNullValue ;
50
52
import static org .junit .Assume .assumeThat ;
51
53
import static org .junit .Assume .assumeTrue ;
@@ -54,7 +56,7 @@ public class KeystoreManagementTests extends PackagingTestCase {
54
56
55
57
private static final String PASSWORD_ERROR_MESSAGE = "Provided keystore password was incorrect" ;
56
58
57
- /** We need an initially installed package */
59
+ /** Test initial archive state */
58
60
public void test10InstallArchiveDistribution () throws Exception {
59
61
assumeTrue (distribution ().isArchive ());
60
62
@@ -63,11 +65,12 @@ public void test10InstallArchiveDistribution() throws Exception {
63
65
64
66
final Installation .Executables bin = installation .executables ();
65
67
Shell .Result r = sh .runIgnoreExitCode (bin .keystoreTool .toString () + " has-passwd" );
66
- assertThat ("has-passwd should fail" , r .exitCode , not (is (0 )));
67
- assertThat ("has-passwd should fail" , r .stderr , containsString ("ERROR: Elasticsearch keystore not found" ));
68
+ assertFalse ("has-passwd should fail" , r .isSuccess ());
69
+ assertThat ("has-passwd should indicate missing keystore" ,
70
+ r .stderr , containsString ("ERROR: Elasticsearch keystore not found" ));
68
71
}
69
72
70
- /** We need an initially installed package */
73
+ /** Test initial package state */
71
74
public void test11InstallPackageDistribution () throws Exception {
72
75
assumeTrue (distribution ().isPackage ());
73
76
@@ -78,11 +81,34 @@ public void test11InstallPackageDistribution() throws Exception {
78
81
79
82
final Installation .Executables bin = installation .executables ();
80
83
Shell .Result r = sh .runIgnoreExitCode (bin .keystoreTool .toString () + " has-passwd" );
81
- assertThat ("has-passwd should fail" , r .exitCode , not (is (0 )));
82
- assertThat ("has-passwd should fail" , r .stderr , containsString ("ERROR: Keystore is not password-protected" ));
84
+ assertFalse ("has-passwd should fail" , r .isSuccess ());
85
+ assertThat ("has-passwd should indicate unprotected keystore" ,
86
+ r .stderr , containsString ("ERROR: Keystore is not password-protected" ));
87
+ Shell .Result r2 = bin .keystoreTool .run ("list" );
88
+ assertThat (r2 .stdout , containsString ("keystore.seed" ));
89
+ }
90
+
91
+ /** Test initial Docker state */
92
+ public void test12InstallDockerDistribution () throws Exception {
93
+ assumeTrue (distribution ().isDocker ());
94
+
95
+ installation = Docker .runContainer (distribution ());
96
+
97
+ try {
98
+ waitForPathToExist (installation .config ("elasticsearch.keystore" ));
99
+ } catch (InterruptedException e ) {
100
+ throw new RuntimeException (e );
101
+ }
102
+
103
+ final Installation .Executables bin = installation .executables ();
104
+ Shell .Result r = sh .runIgnoreExitCode (bin .keystoreTool .toString () + " has-passwd" );
105
+ assertFalse ("has-passwd should fail" , r .isSuccess ());
106
+ assertThat ("has-passwd should indicate unprotected keystore" ,
107
+ r .stdout , containsString ("ERROR: Keystore is not password-protected" ));
108
+ Shell .Result r2 = bin .keystoreTool .run ("list" );
109
+ assertThat (r2 .stdout , containsString ("keystore.seed" ));
83
110
}
84
111
85
- @ Ignore /* Ignored for feature branch, awaits fix: https://github.com/elastic/elasticsearch/issues/49469 */
86
112
public void test20CreateKeystoreManually () throws Exception {
87
113
rmKeystoreIfExists ();
88
114
createKeystore ();
@@ -95,7 +121,7 @@ public void test20CreateKeystoreManually() throws Exception {
95
121
}
96
122
97
123
public void test30AutoCreateKeystore () throws Exception {
98
- assumeTrue ("RPMs and Debs install a keystore file" , distribution .isArchive ());
124
+ assumeTrue ("Packages and docker are installed with a keystore file" , distribution .isArchive ());
99
125
rmKeystoreIfExists ();
100
126
101
127
startElasticsearch ();
@@ -239,12 +265,31 @@ private void createKeystore() throws Exception {
239
265
Platforms .onWindows (() -> {
240
266
sh .chown (keystore );
241
267
});
268
+
269
+ if (distribution ().isDocker ()) {
270
+ try {
271
+ waitForPathToExist (keystore );
272
+ } catch (InterruptedException e ) {
273
+ throw new RuntimeException (e );
274
+ }
275
+ }
242
276
}
243
277
244
278
private void rmKeystoreIfExists () {
245
279
Path keystore = installation .config ("elasticsearch.keystore" );
246
- if (Files .exists (keystore )) {
247
- FileUtils .rm (keystore );
280
+ if (distribution ().isDocker ()) {
281
+ try {
282
+ waitForPathToExist (keystore );
283
+ } catch (InterruptedException e ) {
284
+ throw new RuntimeException (e );
285
+ }
286
+
287
+ // Move the auto-created one out of the way, or else the CLI prompts asks us to confirm
288
+ sh .run ("rm " + keystore );
289
+ } else {
290
+ if (Files .exists (keystore )) {
291
+ FileUtils .rm (keystore );
292
+ }
248
293
}
249
294
}
250
295
@@ -267,7 +312,7 @@ private void assertPasswordProtectedKeystore() {
267
312
assertThat ("keystore should be password protected" , r .exitCode , is (0 ));
268
313
}
269
314
270
- private void verifyKeystorePermissions () throws Exception {
315
+ private void verifyKeystorePermissions () {
271
316
Path keystore = installation .config ("elasticsearch.keystore" );
272
317
switch (distribution .packaging ) {
273
318
case TAR :
@@ -279,7 +324,7 @@ private void verifyKeystorePermissions() throws Exception {
279
324
assertThat (keystore , file (File , "root" , "elasticsearch" , p660 ));
280
325
break ;
281
326
case DOCKER :
282
- // TODO #49469
327
+ assertPermissionsAndOwnership ( keystore , p660 );
283
328
break ;
284
329
default :
285
330
throw new IllegalStateException ("Unknown Elasticsearch packaging type." );
0 commit comments