Skip to content

Commit 89bf0db

Browse files
authored
Fix string replacement in certutil http test (#69404)
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. Backport of: #69319
1 parent dc16cb7 commit 89bf0db

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
@@ -185,10 +185,11 @@ public void testGenerateSingleCertificateSigningRequest() throws Exception {
185185
// Verify the key
186186
assertMatchingPair(getPublicKey(csr), privateKey);
187187

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

190191
// Verify the README
191-
assertThat(esReadme, containsString(csrPath.getFileName().toString()));
192+
assertThat(esReadme, containsString(csrName));
192193
assertThat(esReadme, containsString(crtName));
193194
assertThat(esReadme, containsString(keyPath.getFileName().toString()));
194195
assertThat(esReadme, containsString(ymlPath.getFileName().toString()));
@@ -197,7 +198,7 @@ public void testGenerateSingleCertificateSigningRequest() throws Exception {
197198
}
198199

199200
// Verify the yml
200-
assertThat(yml, not(containsString(csrPath.getFileName().toString())));
201+
assertThat(yml, not(containsString(csrName)));
201202
assertThat(yml, containsString(crtName));
202203
assertThat(yml, containsString(keyPath.getFileName().toString()));
203204
if ("".equals(password) == false) {
@@ -210,7 +211,7 @@ public void testGenerateSingleCertificateSigningRequest() throws Exception {
210211
// No CA in CSR mode
211212
verifyKibanaDirectory(zipRoot, false,
212213
Collections.singletonList("Certificate Signing Request"),
213-
Stream.of(password, csrPath.getFileName().toString())
214+
Stream.of(password, csrName)
214215
.filter(s -> "".equals(s) == false).collect(Collectors.toList()));
215216
}
216217

0 commit comments

Comments
 (0)