summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-02-23 15:57:39 +0100
committerGitHub <noreply@github.com>2021-02-23 15:57:39 +0100
commit9d906802e2449c03f2ee04b8cb462533aecf8f28 (patch)
tree1f53f2803ec0a7d0fb2c907d79e1b323310eddde
parent8296c81b4c9d9c5d65c4ff92310b414b3721b777 (diff)
parent1ab6f7c515439668534863bb7573fbbc13313a7d (diff)
Merge pull request #16643 from vespa-engine/bjorncs/reenable-test
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java28
1 files changed, 17 insertions, 11 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
index f61939de90b..b0dfd228c8b 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/HttpServerTest.java
@@ -44,10 +44,11 @@ import org.eclipse.jetty.client.ProxyProtocolClientConnectionFactory.V2;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
import org.eclipse.jetty.util.ssl.SslContextFactory;
-import org.junit.Ignore;
+import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.mockito.Mockito;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
@@ -67,6 +68,7 @@ import java.security.cert.X509Certificate;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -102,11 +104,14 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -645,7 +650,7 @@ public class HttpServerTest {
.build();
assertHttpsRequestTriggersSslHandshakeException(
driver, clientCtx, null, null, "Received fatal alert: bad_certificate");
- verify(metricConsumer.mockitoMock())
+ verify(metricConsumer.mockitoMock(), atLeast(1))
.add(MetricDefinitions.SSL_HANDSHAKE_FAILURE_MISSING_CLIENT_CERT, 1L, MetricConsumerMock.STATIC_CONTEXT);
assertTrue(driver.close());
Assertions.assertThat(connectionLog.logEntries()).hasSize(1);
@@ -654,7 +659,6 @@ public class HttpServerTest {
}
@Test
- @Ignore
public void requireThatMetricIsIncrementedWhenClientUsesIncompatibleTlsVersion() throws IOException {
Path privateKeyFile = tmpFolder.newFile().toPath();
Path certificateFile = tmpFolder.newFile().toPath();
@@ -668,9 +672,11 @@ public class HttpServerTest {
.withKeyStore(privateKeyFile, certificateFile)
.build();
- assertHttpsRequestTriggersSslHandshakeException(
- driver, clientCtx, "TLSv1.1", null, "protocol");
- verify(metricConsumer.mockitoMock())
+ boolean tlsv11Enabled = List.of(clientCtx.getDefaultSSLParameters().getProtocols()).contains("TLSv1.1");
+ assumeTrue("TLSv1.1 must be enabled in installed JDK", tlsv11Enabled);
+
+ assertHttpsRequestTriggersSslHandshakeException(driver, clientCtx, "TLSv1.1", null, "protocol");
+ verify(metricConsumer.mockitoMock(), atLeast(1))
.add(MetricDefinitions.SSL_HANDSHAKE_FAILURE_INCOMPATIBLE_PROTOCOLS, 1L, MetricConsumerMock.STATIC_CONTEXT);
assertTrue(driver.close());
Assertions.assertThat(connectionLog.logEntries()).hasSize(1);
@@ -694,7 +700,7 @@ public class HttpServerTest {
assertHttpsRequestTriggersSslHandshakeException(
driver, clientCtx, null, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "Received fatal alert: handshake_failure");
- verify(metricConsumer.mockitoMock())
+ verify(metricConsumer.mockitoMock(), atLeast(1))
.add(MetricDefinitions.SSL_HANDSHAKE_FAILURE_INCOMPATIBLE_CIPHERS, 1L, MetricConsumerMock.STATIC_CONTEXT);
assertTrue(driver.close());
Assertions.assertThat(connectionLog.logEntries()).hasSize(1);
@@ -722,11 +728,10 @@ public class HttpServerTest {
assertHttpsRequestTriggersSslHandshakeException(
driver, clientCtx, null, null, "Received fatal alert: certificate_unknown");
- verify(metricConsumer.mockitoMock())
+ verify(metricConsumer.mockitoMock(), atLeast(1))
.add(MetricDefinitions.SSL_HANDSHAKE_FAILURE_INVALID_CLIENT_CERT, 1L, MetricConsumerMock.STATIC_CONTEXT);
assertTrue(driver.close());
Assertions.assertThat(connectionLog.logEntries()).hasSize(1);
- ConnectionLogEntry logEntry = connectionLog.logEntries().get(0);
assertSslHandshakeFailurePresent(
connectionLog.logEntries().get(0), SSLHandshakeException.class, SslHandshakeFailure.INVALID_CLIENT_CERT.failureType());
}
@@ -750,7 +755,7 @@ public class HttpServerTest {
assertHttpsRequestTriggersSslHandshakeException(
driver, clientCtx, null, null, "Received fatal alert: certificate_unknown");
- verify(metricConsumer.mockitoMock())
+ verify(metricConsumer.mockitoMock(), atLeast(1))
.add(MetricDefinitions.SSL_HANDSHAKE_FAILURE_EXPIRED_CLIENT_CERT, 1L, MetricConsumerMock.STATIC_CONTEXT);
assertTrue(driver.close());
Assertions.assertThat(connectionLog.logEntries()).hasSize(1);
@@ -969,7 +974,8 @@ public class HttpServerTest {
} catch (SSLException e) {
// This exception is thrown if Apache httpclient's write thread detects the handshake failure before the read thread.
log.log(Level.WARNING, "Client failed to get a proper TLS handshake response: " + e.getMessage(), e);
- assertThat(e.getMessage(), containsString("readHandshakeRecord")); // Only ignore this specific ssl exception
+ // Only ignore a subset of exceptions
+ assertThat(e.getMessage(), anyOf(containsString("readHandshakeRecord"), containsString("Broken pipe")));
}
}