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 2020/02/17 09:37:56 UTC

[tomcat] branch 8.5.x updated: Test case for OPTIONS request on a sub-class

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 e7ea351  Test case for OPTIONS request on a sub-class
e7ea351 is described below

commit e7ea351e70b3ed480a4942a61e58e61e6069569c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Feb 17 09:37:12 2020 +0000

    Test case for OPTIONS request on a sub-class
---
 test/javax/servlet/http/TestHttpServlet.java | 63 ++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/test/javax/servlet/http/TestHttpServlet.java b/test/javax/servlet/http/TestHttpServlet.java
index 8c03ee3..8de9d9f 100644
--- a/test/javax/servlet/http/TestHttpServlet.java
+++ b/test/javax/servlet/http/TestHttpServlet.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 
 import org.junit.Assert;
@@ -157,6 +158,41 @@ public class TestHttpServlet extends TomcatBaseTest {
     }
 
 
+
+
+    @Test
+    public void testDoOptions() throws Exception {
+        doTestDoOptions(new OptionsServlet(), "GET, HEAD, OPTIONS");
+    }
+
+
+    @Test
+    public void testDoOptionsSub() throws Exception {
+        doTestDoOptions(new OptionsServletSub(), "GET, HEAD, POST, OPTIONS");
+    }
+
+
+    private void doTestDoOptions(Servlet servlet, String expectedAllow) throws Exception{
+        Tomcat tomcat = getTomcatInstance();
+
+        // No file system docBase required
+        StandardContext ctx = (StandardContext) tomcat.addContext("", null);
+
+        // Map the test Servlet
+        Tomcat.addServlet(ctx, "servlet", servlet);
+        ctx.addServletMappingDecoded("/", "servlet");
+
+        tomcat.start();
+
+        Map<String,List<String>> resHeaders= new HashMap<>();
+        int rc = methodUrl("http://localhost:" + getPort() + "/", new ByteChunk(),
+               DEFAULT_CLIENT_TIMEOUT_MS, null, resHeaders, "OPTIONS");
+
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+        Assert.assertEquals(expectedAllow, resHeaders.get("Allow").get(0));
+    }
+
+
     private static class Bug57602ServletOuter extends HttpServlet {
 
         private static final long serialVersionUID = 1L;
@@ -204,4 +240,31 @@ public class TestHttpServlet extends TomcatBaseTest {
             pw.println("Data");
         }
     }
+
+
+    private static class OptionsServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            resp.setContentType("text/plain");
+            resp.setCharacterEncoding("UTF-8");
+            PrintWriter pw = resp.getWriter();
+            pw.print("OK");
+        }
+    }
+
+
+    private static class OptionsServletSub extends OptionsServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            doGet(req, resp);
+        }
+    }
 }


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