This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 8af39c6700aa648fb3879f6898a5b14f138e0e41 Author: remm <r...@apache.org> AuthorDate: Wed Mar 4 19:07:39 2020 +0100 Add test for BZ64195 It works for me, will see on CI. --- test/org/apache/tomcat/util/net/TestSsl.java | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/org/apache/tomcat/util/net/TestSsl.java b/test/org/apache/tomcat/util/net/TestSsl.java index b777f2c..03fe357 100644 --- a/test/org/apache/tomcat/util/net/TestSsl.java +++ b/test/org/apache/tomcat/util/net/TestSsl.java @@ -16,19 +16,27 @@ */ package org.apache.tomcat.util.net; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; +import java.util.Arrays; +import javax.net.SocketFactory; import javax.net.ssl.HandshakeCompletedEvent; import javax.net.ssl.HandshakeCompletedListener; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import org.junit.Assert; import org.junit.Assume; import org.junit.Test; @@ -70,6 +78,52 @@ public class TestSsl extends TomcatBaseTest { } @Test + public void testPost() throws Exception { + SocketFactory socketFactory = TesterSupport.configureClientSsl(); + + Tomcat tomcat = getTomcatInstance(); + TesterSupport.initSsl(tomcat); + + Context ctxt = tomcat.addContext("", null); + Tomcat.addServlet(ctxt, "post", new SimplePostServlet()); + ctxt.addServletMappingDecoded("/post", "post"); + tomcat.start(); + + SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", + getPort()); + + OutputStream os = socket.getOutputStream(); + + byte[] bytes = new byte[1024 * 1024]; // 1MB + Arrays.fill(bytes, (byte) 1); + + os.write("POST /post HTTP/1.1\r\n".getBytes()); + os.write("Host: localhost\r\n".getBytes()); + os.write("Content-Length: 1048576\r\n\r\n".getBytes()); + os.write(bytes); + os.flush(); + + InputStream is = socket.getInputStream(); + + // Skip to the end of the headers + byte[] endOfHeaders = "\r\n\r\n".getBytes(); + int found = 0; + while (found != endOfHeaders.length) { + if (is.read() == endOfHeaders[found]) { + found++; + } else { + found = 0; + } + } + + for (byte c : bytes) { + int read = is.read(); + Assert.assertEquals(c, read); + } + + } + + @Test public void testKeyPass() throws Exception { TesterSupport.configureClientSsl(); @@ -195,4 +249,28 @@ public class TestSsl extends TomcatBaseTest { return complete; } } + + public class SimplePostServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] in = new byte[1500]; + InputStream input = req.getInputStream(); + while (true) { + int n = input.read(in); + if (n > 0) { + baos.write(in, 0, n); + } else { + break; + } + } + byte[] out = baos.toByteArray(); + resp.setContentLength(out.length); + resp.getOutputStream().write(out); + } + + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org