Skip to content

Commit e29865d

Browse files
authored
Fix string replacement in certutil http test (#69319)
This test had 2 issues: 1. It performed a replacement using a string literal on a randomly generated string. It is possible that the filename had ".csr" somewhere in the basename, which would then produce incorrect results 2. It used the wrong base file for the substitution (key vs csr). This fixes the bug by using an index based replacement rather than a textual one. Resolves: #67328
1 parent aa83a8e commit e29865d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

x-pack/plugin/security/cli/src/test/java/org/elasticsearch/xpack/security/cli/HttpCertificateCommandTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,11 @@ public void testGenerateSingleCertificateSigningRequest() throws Exception {
184184
// Verify the key
185185
assertMatchingPair(getPublicKey(csr), privateKey);
186186

187-
final String crtName = keyPath.getFileName().toString().replace(".csr", ".crt");
187+
final String csrName = csrPath.getFileName().toString();
188+
final String crtName = csrName.substring(0, csrName.length() - 4) + ".crt";
188189

189190
// Verify the README
190-
assertThat(esReadme, containsString(csrPath.getFileName().toString()));
191+
assertThat(esReadme, containsString(csrName));
191192
assertThat(esReadme, containsString(crtName));
192193
assertThat(esReadme, containsString(keyPath.getFileName().toString()));
193194
assertThat(esReadme, containsString(ymlPath.getFileName().toString()));
@@ -196,7 +197,7 @@ public void testGenerateSingleCertificateSigningRequest() throws Exception {
196197
}
197198

198199
// Verify the yml
199-
assertThat(yml, not(containsString(csrPath.getFileName().toString())));
200+
assertThat(yml, not(containsString(csrName)));
200201
assertThat(yml, containsString(crtName));
201202
assertThat(yml, containsString(keyPath.getFileName().toString()));
202203
if ("".equals(password) == false) {
@@ -209,7 +210,7 @@ public void testGenerateSingleCertificateSigningRequest() throws Exception {
209210
// No CA in CSR mode
210211

211212
verifyKibanaDirectory(zipRoot, false, List.of("Certificate Signing Request"),
212-
Stream.of(password, csrPath.getFileName().toString())
213+
Stream.of(password, csrName)
213214
.filter(s -> "".equals(s) == false).collect(Collectors.toList()));
214215
}
215216

0 commit comments

Comments
 (0)