Skip to content

Commit 69c96a7

Browse files
authored
Fix broken test on FIPS for specific seed (elastic#40939)
Under random seed 4304ED44CB755610 the generated byte pattern causes BC-FIPS to throw java.io.IOException: DER length more than 4 bytes: 101 Rather than simply returning an empty list (as it does for most random values). Resolves: elastic#40816
1 parent ccbed3d commit 69c96a7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

libs/ssl-config/src/test/java/org/elasticsearch/common/ssl/PemTrustConfigTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,19 @@ private void assertCertificateChain(PemTrustConfig trustConfig, String... caName
123123

124124
private void assertEmptyFile(PemTrustConfig trustConfig, Path file) {
125125
final SslConfigException exception = expectThrows(SslConfigException.class, trustConfig::createTrustManager);
126+
logger.info("failure", exception);
126127
assertThat(exception.getMessage(), Matchers.containsString(file.toAbsolutePath().toString()));
127128
assertThat(exception.getMessage(), Matchers.containsString("failed to parse any certificates"));
128129
}
129130

130131
private void assertInvalidFileFormat(PemTrustConfig trustConfig, Path file) {
131-
if (inFipsJvm()) {
132-
// When running on BC-FIPS, an invalid file format behaves like an empty file
133-
assertEmptyFile(trustConfig, file);
134-
return;
135-
}
136132
final SslConfigException exception = expectThrows(SslConfigException.class, trustConfig::createTrustManager);
137133
assertThat(exception.getMessage(), Matchers.containsString(file.toAbsolutePath().toString()));
134+
// When running on BC-FIPS, an invalid file format *might* just fail to parse, without any errors (just like an empty file)
135+
// or it might behave per the SUN provider, and throw a GSE (depending on exactly what was invalid)
136+
if (inFipsJvm() && exception.getMessage().contains("failed to parse any certificates")) {
137+
return;
138+
}
138139
assertThat(exception.getMessage(), Matchers.containsString("cannot create trust"));
139140
assertThat(exception.getMessage(), Matchers.containsString("PEM"));
140141
assertThat(exception.getCause(), Matchers.instanceOf(GeneralSecurityException.class));

0 commit comments

Comments
 (0)