Hi, I've added 3 tests to javax_servlet_http/HttpServletResponse to validate that headers set after sendError() or sendRedirect are called are ignored by the container (this was an issue at one point).
The 3 new tests are: SendErrorIgnoreHeaderTestServlet.java SendError_StringIgnoreHeaderTestServlet.java SendRedirectIgnoreHeaderTestServlet.java These should be placed in ${WATCHDOG{/src/server/servlet-tests/WEB-INF/classes/tests/javax_servlet_http/HttpServletResponse To support these tests, I've added a new method to GTest, setUnexpectedHeaders (set in the servlet or jsp gtest.xml like so: unexpectedHeaders="key:value" ). This will setup a hashtable of headers to compare against the server response. The logic to checkResponse has been updated accordingly. More to come. Comments welcome. -rl
Index: GTest.java =================================================================== RCS file: /home/cvspublic/jakarta-watchdog-4.0/src/tools/org/apache/tomcat/task/GTest.java,v retrieving revision 1.3 diff -u -r1.3 GTest.java --- GTest.java 2001/09/28 04:09:56 1.3 +++ GTest.java 2001/11/19 23:54:31 @@ -35,6 +35,10 @@ String responseMatch; // the response should include the following headers Hashtable expectHeaders; + + // the response should not include the following headers + Hashtable unexpectedHeaders; + // Match request line String returnCode=""; @@ -197,10 +201,21 @@ //Ramesh public void setExpectHeaders( String s ) { - this.expectHeaders=new Hashtable(); - getHeaderDetails( s, expectHeaders ); + this.expectHeaders=new Hashtable(); + getHeaderDetails( s, expectHeaders ); - //parseHeader( s, expectHeaders ); + //parseHeader( s, expectHeaders ); + } + + /** + * <code>setUnexpectedHeaders</code> sets an ArrayList + * with headers that are not expected to be found in a response + * + * @param s a <code>String</code> value + */ + public void setUnexpectedHeaders( String s ) { + this.unexpectedHeaders = new Hashtable(); + getHeaderDetails( s, unexpectedHeaders ); } public void setResponseMatch( String s ) { @@ -329,30 +344,46 @@ if( expectHeaders != null ) { // Check if we got the expected headers if(headers==null) { - System.out.println("ERROR no response header, expecting header"); + System.out.println("ERROR no response header, expecting header"); } Enumeration e=expectHeaders.keys(); while( e.hasMoreElements()) { - String key=(String)e.nextElement(); - String value=(String)expectHeaders.get(key); - String respValue=(String)headers.get(key); - if( respValue==null || respValue.indexOf( value ) <0 ) { - System.out.println("ERROR expecting header " + key + ":" + - value + " GOT: " + respValue+ " HEADERS(" + headers + ")"); - if ( resultOut != null ) - { - expectedString = "<expectedHeader>" + key + ":"+ value + "</expectedHeader>\n"; - actualString = "<actualHeader>"+ key + ":" + respValue + "</actualHeader>\n"; - resultOut.write(expectedString.getBytes() ); - resultOut.write(actualString.getBytes() ); + String key=(String)e.nextElement(); + String value=(String)expectHeaders.get(key); + String respValue=(String)headers.get(key); + if( respValue==null || respValue.indexOf( value ) <0 ) { + System.out.println("ERROR expecting header " + key + ":" + + value + " GOT: " + respValue+ " HEADERS(" + +headers + ")"); + if ( resultOut != null ) + { + expectedString = "<expectedHeader>" + key + ":"+ value + +"</expectedHeader>\n"; + actualString = "<actualHeader>"+ key + ":" + respValue + +"</actualHeader>\n"; + resultOut.write(expectedString.getBytes() ); + resultOut.write(actualString.getBytes() ); - } + } - return false; - } + return false; + } } - } + + // check to see if any unexpected headers we're recieved + if ( unexpectedHeaders != null ) { + if ( headers != null ) { + Enumeration e = unexpectedHeaders.keys(); + while( e.hasMoreElements() ) { + String key = (String) e.nextElement(); + String value = (String) unexpectedHeaders.get( key ); + String respValue = (String) headers.get( key ); + if ( respValue != null && respValue.indexOf( value ) > 0 ) { + System.out.println( "ERROR Unexpected header: " + key + ":" + +value + + " found in server response." ); + return false; + } + } + } + } if( responseMatch != null ) { // check if we got the string we wanted
/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package tests.javax_servlet_http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintWriter; /** * A Test for verify that headers added after sendError, * as it commits the response, are ignored by the container. */ public class SendErrorIgnoreHeaderTestServlet extends HttpServlet { public void service ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.sendError( HttpServletResponse.SC_CONTINUE ); response.addHeader( "HttpServletResponse", "sendErrorIgnoreHeader" ); } }
/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package tests.javax_servlet_http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintWriter; /** * Tests that a header added after a call to sendError() will * be ignored by the container and not sent to the client. */ public class SendError_StringIgnoreHeaderTestServlet extends HttpServlet { public void service ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { response.sendError( HttpServletResponse.SC_CONTINUE, "in SendError_StringIgnoreHeaderTest servlet" ); response.addHeader( "HttpServletResponse", "sendErrorMsgIgnoreHeader" ); } }
/* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package tests.javax_servlet_http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import java.io.IOException; import java.net.InetAddress; import java.io.PrintWriter; /** * Test to verify that headers added after a call to sendRedirect() * are ignored by the container and not sent to the client. */ public class SendRedirectIgnoreHeaderTestServlet extends HttpServlet { public void service ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { // Relative path of the new Location String path = "/RedirectedTest"; response.sendRedirect( path ); response.addHeader( "HttpServletResponse", "sendRedirectIgnoreHeader" ); } }
Index: servlet-gtest.xml =================================================================== RCS file: /home/cvspublic/jakarta-watchdog-4.0/src/conf/servlet-gtest.xml,v retrieving revision 1.19 diff -u -r1.19 servlet-gtest.xml --- servlet-gtest.xml 2001/07/20 23:07:56 1.19 +++ servlet-gtest.xml 2001/11/19 23:53:30 @@ -872,6 +872,24 @@ debug="0" host="${host}" port="${port}" returnCode="200" /> + <gtest request="GET /servlet-tests/SendErrorIgnoreHeaderTestServlet HTTP/1.0" + testName="SendErrorIgnoreHeaderTest" + assertion="Headers set after the response is committed will be ignored by +the servlet container. Servlet 2.3 Specification, Section SRV.5.2" + testStrategy="Cause the response to be committed in the servlet by calling +sendError(), and then set a header. Validate via the GTest client that the header +set, does not appear in the response" + debug="0" host="${host}" port="${port}" +unexpectedHeaders="HttpServletResponse:sendErrorIgnoreHeader" /> + + <gtest request="GET /servlet-tests/SendError_StringIgnoreHeaderTestServlet +HTTP/1.0" + testName="SendError_StringIgnoreHeaderTest" + assertion="Headers set after the response is committed will be ignored by +the servlet container. Servlet 2.3 Specification, Section SRV.5.2" + testStrategy="Cause the response to be committed in the servlet by calling +sendError(), and then set a header. Validate via the GTest client that the header +set, does not appear in the response." + debug="0" host="${host}" port="${port}" +unexpectedHeaders="HttpServletResponse:sendErrorMsgIgnoreHeader" /> + + <gtest request="GET /servlet-tests/SendRedirectIgnoreHeaderTestServlet HTTP/1.0" + testName="SendRedirectIgnoreHeaderTestServlet" + assertion="Headers set after the response is committed will be ignored by +the servlet container. Servlet 2.3 Specification, Section SRV.5.2" + testStrategy="Cause the response to be committed in the servlet by calling +sendRedirect(), and then set a header. Validate via the GTest client that the header +set, does not appear in the response." + debug="0" host="${host}" port="${port}" +unexpectedHeaders="HttpServletResponse:sendRedirectIgnoreHeader" /> + <!-- javax_servlet_http_HttpSession tests -->
Index: web.xml =================================================================== RCS file: /home/cvspublic/jakarta-watchdog-4.0/src/server/servlet-tests/WEB-INF/web.xml,v retrieving revision 1.3 diff -u -r1.3 web.xml --- web.xml 2000/12/22 18:59:14 1.3 +++ web.xml 2001/11/19 23:52:56 @@ -280,7 +280,33 @@ </servlet-class> </servlet> + <servlet> + <servlet-name> + SendErrorIgnoreHeaderTestServlet + </servlet-name> + <servlet-class> + +tests.javax_servlet_http.HttpServletResponse.SendErrorIgnoreHeaderTestServlet + </servlet-class> + </servlet> + <servlet> + <servlet-name> + SendError_StringIgnoreHeaderTestServlet + </servlet-name> + <servlet-class> + +tests.javax_servlet_http.HttpServletResponse.SendError_StringIgnoreHeaderTestServlet + </servlet-class> + </servlet> + + <servlet> + <servlet-name> + SendRedirectIgnoreHeaderTestServlet + </servlet-name> + <servlet-class> + +tests.javax_servlet_http.HttpServletResponse.SendRedirectIgnoreHeaderTestServlet + </servlet-class> + </servlet> + <!-- HttpSession --> <servlet> @@ -2093,6 +2119,32 @@ </url-pattern> </servlet-mapping> + <servlet-mapping> + <servlet-name> + SendErrorIgnoreHeaderTestServlet + </servlet-name> + <url-pattern> + /SendErrorIgnoreHeaderTestServlet + </url-pattern> + </servlet-mapping> + + <servlet-mapping> + <servlet-name> + SendError_StringIgnoreHeaderTestServlet + </servlet-name> + <url-pattern> + /SendError_StringIgnoreHeaderTestServlet + </url-pattern> + </servlet-mapping> + + <servlet-mapping> + <servlet-name> + SendRedirectIgnoreHeaderTestServlet + </servlet-name> + <url-pattern> + /SendRedirectIgnoreHeaderTestServlet + </url-pattern> + </servlet-mapping> <servlet-mapping> <servlet-name>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>