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 2010/07/15 23:32:35 UTC

svn commit: r964611 - /tomcat/trunk/test/org/apache/catalina/connector/TestResponse.java

Author: markt
Date: Thu Jul 15 21:32:35 2010
New Revision: 964611

URL: http://svn.apache.org/viewvc?rev=964611&view=rev
Log:
Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=49598
Multiple invalid session cookies

Added:
    tomcat/trunk/test/org/apache/catalina/connector/TestResponse.java   (with props)

Added: tomcat/trunk/test/org/apache/catalina/connector/TestResponse.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestResponse.java?rev=964611&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestResponse.java (added)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestResponse.java Thu Jul 15 21:32:35 2010
@@ -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);
+        }
+        
+    }
+}

Propchange: tomcat/trunk/test/org/apache/catalina/connector/TestResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native



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