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 2019/11/16 14:41:13 UTC

[tomcat] branch 8.5.x updated: Improve unit test robustness

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 96cc274  Improve unit test robustness
96cc274 is described below

commit 96cc274e05c8d2c5d8949aec36bf301b32b13834
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Sat Nov 16 13:59:58 2019 +0000

    Improve unit test robustness
---
 .../connector/TestCoyoteAdapterRequestFuzzing.java      | 17 +++++++++++++++++
 test/org/apache/catalina/startup/SimpleHttpClient.java  |  6 +++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java b/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java
index acd01a7..dc8ac5e 100644
--- a/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java
+++ b/test/org/apache/catalina/connector/TestCoyoteAdapterRequestFuzzing.java
@@ -16,7 +16,11 @@
  */
 package org.apache.catalina.connector;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -135,6 +139,19 @@ public class TestCoyoteAdapterRequestFuzzing extends TomcatBaseTest {
         }
 
         @Override
+        protected OutputStream createOutputStream(Socket socket) throws IOException {
+            // Override the default implementation so we can create a large
+            // enough buffer to hold the entire request.
+            // The default implementation uses the 8k buffer in the
+            // StreamEncoder. Since some requests are larger than this, those
+            // requests will be sent in several parts. If the first part is
+            // sufficient for Tomcat to determine the request is invalid, Tomcat
+            // will close the connection, causing the write of the remaining
+            // parts to fail which in turn causes the test to fail.
+            return new BufferedOutputStream(super.createOutputStream(socket), 32 * 1024);
+        }
+
+        @Override
         public boolean isResponseBodyOK() {
             // Response body varies. It is the response code that is of interest
             // in these tests.
diff --git a/test/org/apache/catalina/startup/SimpleHttpClient.java b/test/org/apache/catalina/startup/SimpleHttpClient.java
index 6ff2050..a5ced3e 100644
--- a/test/org/apache/catalina/startup/SimpleHttpClient.java
+++ b/test/org/apache/catalina/startup/SimpleHttpClient.java
@@ -188,7 +188,7 @@ public abstract class SimpleHttpClient {
         socket = new Socket();
         socket.setSoTimeout(soTimeout);
         socket.connect(addr,connectTimeout);
-        OutputStream os = socket.getOutputStream();
+        OutputStream os = createOutputStream(socket);
         writer = new OutputStreamWriter(os, encoding);
         InputStream is = socket.getInputStream();
         Reader r = new InputStreamReader(is, encoding);
@@ -198,6 +198,10 @@ public abstract class SimpleHttpClient {
         connect(0,0);
     }
 
+    protected OutputStream createOutputStream(Socket socket) throws IOException {
+        return socket.getOutputStream();
+    }
+
     public void processRequest() throws IOException, InterruptedException {
         processRequest(true);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org