From d52ed502b08fbe87fa79400fb6c26a4103df43fe Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 16 Dec 2011 21:26:37 +0100 Subject: [PATCH] Sketch of test for idle expiration on SSL. --- .../jetty/client/SslBytesServerTest.java | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/SslBytesServerTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/SslBytesServerTest.java index f6b919ed64f..c963b09e9b7 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/SslBytesServerTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/SslBytesServerTest.java @@ -1,8 +1,5 @@ package org.eclipse.jetty.client; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.lessThan; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -19,7 +16,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; - import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLSocket; @@ -48,6 +44,9 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.lessThan; + public class SslBytesServerTest extends SslBytesTest { private final AtomicInteger sslHandles = new AtomicInteger(); @@ -100,6 +99,7 @@ public class SslBytesServerTest extends SslBytesTest }; } }; + connector.setMaxIdleTime(2000); // connector.setPort(5870); connector.setPort(0); @@ -1181,6 +1181,54 @@ public class SslBytesServerTest extends SslBytesTest closeClient(client); } + @Ignore + @Test + public void testServerCloseClientDoesNotClose() throws Exception + { + final SSLSocket client = newClient(); + final OutputStream clientOutput = client.getOutputStream(); + + SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow(); + client.startHandshake(); + Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); + + byte[] data = new byte[3 * 1024]; + Arrays.fill(data, (byte)'Y'); + String content = new String(data, "UTF-8"); + automaticProxyFlow = proxy.startAutomaticFlow(); + clientOutput.write(("" + + "POST / HTTP/1.1\r\n" + + "Host: localhost\r\n" + + "Content-Type: text/plain\r\n" + + "Content-Length: " + content.length() + "\r\n" + + "Connection: close\r\n" + + "\r\n" + + content).getBytes("UTF-8")); + clientOutput.flush(); + Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); + + BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8")); + String line = reader.readLine(); + Assert.assertNotNull(line); + Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); + while ((line = reader.readLine()) != null) + { + if (line.trim().length() == 0) + break; + } + + // Check that we did not spin + Assert.assertThat(sslHandles.get(), lessThan(20)); + Assert.assertThat(httpParses.get(), lessThan(50)); + + // TODO: instead of sleeping, we should expect the connection being closed by the idle timeout + // TODO: mechanism; unfortunately this now is not working, and this test fails because the idle + // TODO: timeout will not trigger. + TimeUnit.SECONDS.sleep(100); + + closeClient(client); + } + private void assumeJavaVersionSupportsTLSRenegotiations() { // Due to a security bug, TLS renegotiations were disabled in JDK 1.6.0_19-21