Skip to content

Commit a4b2dc9

Browse files
committed
Update SSLTrustRestrictionTests for JDK11
In prior versions of Java, we expected to see a SSLHandshakeException when starting a handshake with a server that we do not trust. In JDK11, the exception has changed to a SSLException, which SSLHandshakeException extends. This is most likely a side effect of the TLS 1.3 changes in JDK11. This change updates the test to catch the SSLException instead of the SSLHandshakeException and enables the test to work on JDK8 through JDK11. Closes elastic#29989
1 parent 33a264a commit a4b2dc9

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLTrustRestrictionsTests.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import org.apache.logging.log4j.message.ParameterizedMessage;
99
import org.elasticsearch.ElasticsearchException;
10-
import org.elasticsearch.bootstrap.JavaVersion;
1110
import org.elasticsearch.common.io.PathUtils;
1211
import org.elasticsearch.common.settings.Settings;
1312
import org.elasticsearch.common.transport.TransportAddress;
@@ -25,7 +24,7 @@
2524
import org.junit.AfterClass;
2625
import org.junit.BeforeClass;
2726

28-
import javax.net.ssl.SSLHandshakeException;
27+
import javax.net.ssl.SSLException;
2928
import javax.net.ssl.SSLSocket;
3029
import javax.net.ssl.SSLSocketFactory;
3130
import java.io.IOException;
@@ -166,33 +165,29 @@ public void testCertificateWithTrustedNameIsAccepted() throws Exception {
166165
writeRestrictions("*.trusted");
167166
try {
168167
tryConnect(trustedCert);
169-
} catch (SSLHandshakeException | SocketException ex) {
168+
} catch (SSLException | SocketException ex) {
170169
logger.warn(new ParameterizedMessage("unexpected handshake failure with certificate [{}] [{}]",
171170
trustedCert.certificate.getSubjectDN(), trustedCert.certificate.getSubjectAlternativeNames()), ex);
172171
fail("handshake should have been successful, but failed with " + ex);
173172
}
174173
}
175174

176175
public void testCertificateWithUntrustedNameFails() throws Exception {
177-
// see https://github.com/elastic/elasticsearch/issues/29989
178-
assumeTrue("test fails on JDK 11 currently", JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0);
179176
writeRestrictions("*.trusted");
180177
try {
181178
tryConnect(untrustedCert);
182179
fail("handshake should have failed, but was successful");
183-
} catch (SSLHandshakeException | SocketException ex) {
180+
} catch (SSLException | SocketException ex) {
184181
// expected
185182
}
186183
}
187184

188185
public void testRestrictionsAreReloaded() throws Exception {
189-
// see https://github.com/elastic/elasticsearch/issues/29989
190-
assumeTrue("test fails on JDK 11 currently", JavaVersion.current().compareTo(JavaVersion.parse("11")) < 0);
191186
writeRestrictions("*");
192187
assertBusy(() -> {
193188
try {
194189
tryConnect(untrustedCert);
195-
} catch (SSLHandshakeException | SocketException ex) {
190+
} catch (SSLException | SocketException ex) {
196191
fail("handshake should have been successful, but failed with " + ex);
197192
}
198193
}, MAX_WAIT_RELOAD.millis(), TimeUnit.MILLISECONDS);
@@ -202,7 +197,7 @@ public void testRestrictionsAreReloaded() throws Exception {
202197
try {
203198
tryConnect(untrustedCert);
204199
fail("handshake should have failed, but was successful");
205-
} catch (SSLHandshakeException | SocketException ex) {
200+
} catch (SSLException | SocketException ex) {
206201
// expected
207202
}
208203
}, MAX_WAIT_RELOAD.millis(), TimeUnit.MILLISECONDS);

0 commit comments

Comments
 (0)