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

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


The following commit(s) were added to refs/heads/11.0.x by this push:
     new 978aae5588 Add test to confirm cookie names are case insensitive
978aae5588 is described below

commit 978aae558807b92b75931e975b07ecd520cbcc06
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Dec 11 13:35:35 2024 +0000

    Add test to confirm cookie names are case insensitive
---
 .../http/TestCookieProcessorGenerationHttp.java    | 45 +++++++++++++++++++---
 1 file changed, 39 insertions(+), 6 deletions(-)

diff --git 
a/test/org/apache/tomcat/util/http/TestCookieProcessorGenerationHttp.java 
b/test/org/apache/tomcat/util/http/TestCookieProcessorGenerationHttp.java
index 468d051c23..a057807b46 100644
--- a/test/org/apache/tomcat/util/http/TestCookieProcessorGenerationHttp.java
+++ b/test/org/apache/tomcat/util/http/TestCookieProcessorGenerationHttp.java
@@ -44,7 +44,9 @@ public class TestCookieProcessorGenerationHttp extends 
TomcatBaseTest {
         // No file system docBase required
         Context ctx = getProgrammaticRootContext();
         ctx.setCookieProcessor(new Rfc6265CookieProcessor());
-        Tomcat.addServlet(ctx, "test", new CookieServlet("\u0120"));
+        Map<String,String> cookies = new HashMap<>();
+        cookies.put("Test", "\u0120");
+        Tomcat.addServlet(ctx, "test", new CookieServlet(cookies));
         ctx.addServletMappingDecoded("/test", "test");
         tomcat.start();
 
@@ -68,19 +70,50 @@ public class TestCookieProcessorGenerationHttp extends 
TomcatBaseTest {
 
         private static final long serialVersionUID = 1L;
 
-        private final String cookieValue;
+        private final Map<String,String> cookieNamesValues;
 
-        CookieServlet(String cookieValue) {
-            this.cookieValue = cookieValue;
+        CookieServlet(Map<String,String> cookieNamesValues) {
+            this.cookieNamesValues = cookieNamesValues;
         }
 
         @Override
         protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                 throws ServletException, IOException {
-            Cookie cookie = new Cookie("Test", cookieValue);
-            resp.addCookie(cookie);
+            for (Map.Entry<String,String> entry : 
cookieNamesValues.entrySet()) {
+                Cookie cookie = new Cookie(entry.getKey(), entry.getValue());
+                resp.addCookie(cookie);
+            }
             resp.setContentType("text/plain");
             resp.getWriter().print("OK");
         }
     }
+
+
+    @Test
+    public void testCaseSensitiveCookie() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        // No file system docBase required
+        Context ctx = getProgrammaticRootContext();
+        ctx.setCookieProcessor(new Rfc6265CookieProcessor());
+        Map<String,String> cookies = new HashMap<>();
+        cookies.put("aaa", "zzz");
+        cookies.put("aAa", "yyy");
+        Tomcat.addServlet(ctx, "test", new CookieServlet(cookies));
+        ctx.addServletMappingDecoded("/test", "test");
+        tomcat.start();
+
+        Map<String,List<String>> headers = new HashMap<>();
+        ByteChunk res = new ByteChunk();
+        getUrl("http://localhost:"; + getPort() + "/test", res, headers);
+        List<String> cookieHeaders = headers.get("Set-Cookie");
+        Assert.assertEquals("There should be two Set-Cookie headers in this 
test",
+                2, cookieHeaders.size());
+        // Remove the cookies the client sees from the map that was sent. 
Should leave the map empty.
+        for (String cookieHeader : cookieHeaders) {
+            String[] nv = cookieHeader.split("=");
+            Assert.assertEquals(2, nv.length);
+            Assert.assertTrue(nv[1].equals(cookies.remove(nv[0])));
+        }
+        Assert.assertEquals(0,  cookies.size());
+    }
 }


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

Reply via email to