Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=49598
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 15 Jul 2010 21:32:35 +0000 (21:32 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 15 Jul 2010 21:32:35 +0000 (21:32 +0000)
Multiple invalid session cookies

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@964611 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/catalina/connector/TestResponse.java [new file with mode: 0644]

diff --git a/test/org/apache/catalina/connector/TestResponse.java b/test/org/apache/catalina/connector/TestResponse.java
new file mode 100644 (file)
index 0000000..ec04c8b
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.catalina.connector;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+/**
+ * Test case for {@link Request}. 
+ */
+public class TestResponse extends TomcatBaseTest {
+
+    public void testBug49598() throws Exception {
+        // Setup Tomcat instance
+        Tomcat tomcat = getTomcatInstance();
+        
+        // Must have a real docBase - just use temp
+        File docBase = new File(System.getProperty("java.io.tmpdir"));
+        Context ctx = tomcat.addContext("/", docBase.getAbsolutePath());
+
+        Tomcat.addServlet(ctx, "servlet", new Bug49598Servlet());
+        ctx.addServletMapping("/", "servlet");
+
+        tomcat.start();
+        
+        Map<String,List<String>> headers = new HashMap<String,List<String>>();
+        getUrl("http://localhost:" + getPort() + "/", new ByteChunk(), headers);
+        
+        // Check for headers without a name
+        for (Map.Entry<String,List<String>> header : headers.entrySet()) {
+            if (header.getKey() == null) {
+                // Expected if this is the response line
+                List<String> values = header.getValue();
+                if (values.size() == 1 &&
+                        values.get(0).startsWith("HTTP/1.1")) {
+                    continue;
+                }
+                fail("Null header name detected for value " + values);
+            }
+        }
+        
+        // Check for exactly one Set-Cookie header
+        int count = 0;
+        for (String headerName : headers.keySet()) {
+            if ("Set-Cookie".equals(headerName)) {
+                count ++;
+            }
+        }
+        assertEquals(1, count);
+    }
+    
+    private static final class Bug49598Servlet extends HttpServlet {
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            HttpSession session = req.getSession(true);
+            session.invalidate();
+            req.getSession(true);
+        }
+        
+    }
+}