You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2024/01/03 11:29:50 UTC
(tomcat) 07/12: Refactor test to test renegotiation failure rather than skipping test
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 00e7bca77412d7e727705b7d63111b39d373874c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jan 3 10:38:03 2024 +0000
Refactor test to test renegotiation failure rather than skipping test
---
test/org/apache/tomcat/util/net/TestSsl.java | 29 ++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/test/org/apache/tomcat/util/net/TestSsl.java b/test/org/apache/tomcat/util/net/TestSsl.java
index 4c77460ccd..7ed2b8f9bf 100644
--- a/test/org/apache/tomcat/util/net/TestSsl.java
+++ b/test/org/apache/tomcat/util/net/TestSsl.java
@@ -34,6 +34,7 @@ import javax.net.SocketFactory;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
@@ -43,7 +44,6 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.junit.Assert;
-import org.junit.Assume;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -242,23 +242,19 @@ public class TestSsl extends TomcatBaseTest {
}
@Test
- public void testRenegotiateWorks() throws Exception {
- Tomcat tomcat = getTomcatInstance();
+ public void testClientInitiatedRenegotiation() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
TesterSupport.initSsl(tomcat);
-
TesterSupport.configureSSLImplementation(tomcat, sslImplementationName, needApr);
- Assume.assumeTrue("SSL renegotiation has to be supported for this test",
- TesterSupport.isClientRenegotiationSupported(getTomcatInstance()));
+ boolean renegotiationSupported = TesterSupport.isClientRenegotiationSupported(getTomcatInstance());
Context root = tomcat.addContext("", TEMP_DIR);
- Wrapper w =
- Tomcat.addServlet(root, "tester", new TesterServlet());
+ Wrapper w = Tomcat.addServlet(root, "tester", new TesterServlet());
w.setAsyncSupported(true);
root.addServletMappingDecoded("/", "tester");
-
tomcat.start();
SSLContext sslCtx;
@@ -269,8 +265,7 @@ public class TestSsl extends TomcatBaseTest {
sslCtx.init(null, TesterSupport.getTrustManagers(), null);
SSLSocketFactory socketFactory = sslCtx.getSocketFactory();
- SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost",
- getPort());
+ SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", getPort());
OutputStream os = socket.getOutputStream();
InputStream is = socket.getInputStream();
@@ -285,7 +280,17 @@ public class TestSsl extends TomcatBaseTest {
socket.startHandshake();
- doRequest(os, r);
+ try {
+ doRequest(os, r);
+ if (!renegotiationSupported) {
+ Assert.fail("Renegotiation started when it should have failed");
+ }
+ } catch (SSLHandshakeException e) {
+ if (renegotiationSupported) {
+ Assert.fail("Renegotiation failed when it should be supported");
+ }
+ return;
+ }
// Handshake complete appears to be called asynchronously
int wait = 0;
while (wait < 5000 && !listener.isComplete()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org