From: markt Date: Thu, 15 Jul 2010 21:32:35 +0000 (+0000) Subject: Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=49598 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6034979b4bd7418a487176e2a4fa109b377a657d;p=tomcat7.0 Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=49598 Multiple invalid session cookies git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@964611 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/org/apache/catalina/connector/TestResponse.java b/test/org/apache/catalina/connector/TestResponse.java new file mode 100644 index 000000000..ec04c8bc3 --- /dev/null +++ b/test/org/apache/catalina/connector/TestResponse.java @@ -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> headers = new HashMap>(); + getUrl("http://localhost:" + getPort() + "/", new ByteChunk(), headers); + + // Check for headers without a name + for (Map.Entry> header : headers.entrySet()) { + if (header.getKey() == null) { + // Expected if this is the response line + List 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); + } + + } +}