craigmcc 01/05/30 14:54:55
Modified: tester/src/bin tester.xml
tester/src/tester/org/apache/tester UpperCaseFilter.java
tester/web/WEB-INF web.xml
Added: tester/src/tester/org/apache/tester FilterRequest01.java
UpperCaseInputStream.java UpperCaseReader.java
UpperCaseRequest.java
Log:
Add some corresponding tests for input that is wrapped by a filter.
Revision Changes Path
1.48 +38 -1 jakarta-tomcat-4.0/tester/src/bin/tester.xml
Index: tester.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- tester.xml 2001/05/30 19:42:44 1.47
+++ tester.xml 2001/05/30 21:54:48 1.48
@@ -15,7 +15,7 @@
<taskdef name="tester" classname="org.apache.tester.TestClient"/>
- <target name="all"
depends="ROOT,Authentication,CaseSensitive,Decoding,ErrorPage,FilterResponse,Jndi,RequestDispatcher,Resources,ServletRequest,ServletResponse,HttpSession,XercesTest,SSITest"/>
+ <target name="all"
depends="ROOT,Authentication,CaseSensitive,Decoding,ErrorPage,FilterRequest,FilterResponse,Jndi,RequestDispatcher,Resources,ServletRequest,ServletResponse,HttpSession,XercesTest,SSITest"/>
<target name="ROOT">
@@ -343,6 +343,43 @@
status="200"
outContent="ErrorPage10 PASSED"/>
+
+ </target>
+
+
+ <target name="FilterRequest">
+
+ <!-- ========== Apply Upper Case Filter =============================== -->
+
+ <!-- Input via buffered reader -->
+ <tester host="${host}" port="${port}" protocol="HTTP/1.0"
+ request="${context.path}/FilterRequest01?type=reader"
+ debug="${debug}"
+ status="200"
+ inContent="FilterRequest01 Unwrapped Reader PASSED"
+ outContent="FILTERREQUEST01 UNWRAPPED READER PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="HTTP/1.0"
+ request="${context.path}/WrappedFilterRequest01?type=reader"
+ debug="${debug}"
+ status="200"
+ inContent="FilterRequest01 Wrapped Reader PASSED"
+ outContent="FILTERREQUEST01 WRAPPED READER PASSED"/>
+
+ <!-- Input via servlet input stream -->
+ <tester host="${host}" port="${port}" protocol="HTTP/1.0"
+ request="${context.path}/FilterRequest01?type=reader"
+ debug="${debug}"
+ status="200"
+ inContent="FilterRequest01 Unwrapped Stream PASSED"
+ outContent="FILTERREQUEST01 UNWRAPPED STREAM PASSED"/>
+
+ <tester host="${host}" port="${port}" protocol="HTTP/1.0"
+ request="${context.path}/WrappedFilterRequest01?type=reader"
+ debug="${debug}"
+ status="200"
+ inContent="FilterRequest01 Wrapped Stream PASSED"
+ outContent="FILTERREQUEST01 WRAPPED STREAM PASSED"/>
</target>
1.2 +4 -2
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/UpperCaseFilter.java
Index: UpperCaseFilter.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/UpperCaseFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UpperCaseFilter.java 2001/05/30 19:42:46 1.1
+++ UpperCaseFilter.java 2001/05/30 21:54:51 1.2
@@ -68,7 +68,7 @@
* Filter that simply transforms its output to upper case.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/05/30 19:42:46 $
+ * @version $Revision: 1.2 $ $Date: 2001/05/30 21:54:51 $
*/
public class UpperCaseFilter implements Filter {
@@ -88,10 +88,12 @@
FilterChain chain)
throws IOException, ServletException {
+ HttpServletRequest wrequest =
+ new UpperCaseRequest((HttpServletRequest) request);
HttpServletResponse wresponse =
new UpperCaseResponse((HttpServletResponse) response);
StaticLogger.write("UpperCaseFilter.doFilter() begin");
- chain.doFilter(request, wresponse);
+ chain.doFilter(wrequest, wresponse);
StaticLogger.write("UpperCaseFilter.doFilter() end");
}
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/FilterRequest01.java
Index: FilterRequest01.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* 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 Software Foundation. *
* *
* 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 indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Positive test for being able to filter input. The input will be echoed
* back in the response, after having been converted to upper case by the
* associated filter. Use request parameter <code>type</code> to determine
* whether to call getReader() ("reader") or getInputStream() ("stream").
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/05/30 21:54:50 $
*/
public class FilterRequest01 extends HttpServlet {
public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
StringBuffer sb = new StringBuffer();
String type = request.getParameter("type");
if (type == null)
type = "reader";
if (type.equalsIgnoreCase("reader")) {
BufferedReader br = request.getReader();
while (true) {
int c = br.read();
if (c < 0)
break;
sb.append((char) c);
}
br.close();
} else {
ServletInputStream sis = request.getInputStream();
while (true) {
int c = sis.read();
if (c < 0)
break;
sb.append((char) c);
}
sis.close();
}
writer.println(sb.toString());
while (true) {
String message = StaticLogger.read();
if (message == null)
break;
writer.println(message);
}
StaticLogger.reset();
}
}
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/UpperCaseInputStream.java
Index: UpperCaseInputStream.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* 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 Software Foundation. *
* *
* 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 indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* ServletInputStream that converts all characters to upper case.
* WARNING: This will only work on 8-bit character sets!
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/05/30 21:54:51 $
*/
public class UpperCaseInputStream extends ServletInputStream {
ServletInputStream stream = null;
public UpperCaseInputStream(ServletInputStream stream)
throws IOException {
super();
this.stream = stream;
}
public int read() throws IOException {
int c = stream.read();
if (c < 0)
return (c);
char ch = (char) c;
if (Character.isLowerCase(ch))
ch = Character.toUpperCase(ch);
return ((int) ch);
}
public int read(byte buf[], int off, int len) throws IOException {
int n = 0;
for (int i = off; i < (off + len); i++) {
int c = stream.read();
if (c < 0) {
if (n == 0)
return (-1);
break;
}
char ch = (char) c;
if (Character.isLowerCase(ch))
ch = Character.toUpperCase(ch);
buf[i] = (byte) ch;
n++;
}
return (n);
}
public int read(byte buf[]) throws IOException {
return (read(buf, 0, buf.length));
}
public int readLine(byte buf[], int off, int len) throws IOException {
int n = 0;
for (int i = off; i < (off + len); i++) {
int c = stream.read();
if (c < 0) {
if (n == 0)
return (-1);
break;
}
char ch = (char) c;
if (Character.isLowerCase(ch))
ch = Character.toUpperCase(ch);
buf[i] = (byte) ch;
n++;
if (ch == '\n')
break;
}
return (n);
}
}
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/UpperCaseReader.java
Index: UpperCaseReader.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* 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 Software Foundation. *
* *
* 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 indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* BufferedReader that converts all characters to upper case.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/05/30 21:54:51 $
*/
public class UpperCaseReader extends BufferedReader {
public UpperCaseReader(BufferedReader reader) throws IOException {
super(reader);
}
public int read() throws IOException {
int c = super.read();
if (c < 0)
return (c);
char ch = (char) c;
if (Character.isLowerCase(ch))
ch = Character.toUpperCase(ch);
return ((int) ch);
}
public int read(char buf[], int off, int len) throws IOException {
int n = 0;
for (int i = off; i < (off + len); i++) {
int c = super.read();
if (c < 0) {
if (n == 0)
return (-1);
break;
}
char ch = (char) c;
if (Character.isLowerCase(ch))
ch = Character.toUpperCase(ch);
buf[i] = ch;
n++;
}
return (n);
}
public int read(char buf[]) throws IOException {
return (read(buf, 0, buf.length));
}
}
1.1
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/UpperCaseRequest.java
Index: UpperCaseRequest.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* 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 Software Foundation. *
* *
* 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 indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
package org.apache.tester;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* HttpServletRequest wrapper that converts all input characters to
* upper case.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/05/30 21:54:52 $
*/
public class UpperCaseRequest extends HttpServletRequestWrapper {
HttpServletRequest request = null;
public UpperCaseRequest(HttpServletRequest request) {
super(request);
this.request = request;
}
public ServletInputStream getInputStream() throws IOException {
return (new UpperCaseInputStream(request.getInputStream()));
}
public BufferedReader getReader() throws IOException {
return (new UpperCaseReader(request.getReader()));
}
}
1.37 +30 -0 jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
Index: web.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- web.xml 2001/05/30 19:42:49 1.36
+++ web.xml 2001/05/30 21:54:54 1.37
@@ -120,6 +120,21 @@
<filter-mapping>
<filter-name>UpperCaseFilter</filter-name>
+ <url-pattern>/FilterRequest01</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>HttpFilter</filter-name>
+ <url-pattern>/WrappedFilterRequest01</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>UpperCaseFilter</filter-name>
+ <url-pattern>/WrappedFilterRequest01</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>UpperCaseFilter</filter-name>
<url-pattern>/FilterResponse01</url-pattern>
</filter-mapping>
@@ -453,6 +468,11 @@
</servlet>
<servlet>
+ <servlet-name>FilterRequest01</servlet-name>
+ <servlet-class>org.apache.tester.FilterRequest01</servlet-class>
+ </servlet>
+
+ <servlet>
<servlet-name>FilterResponse01</servlet-name>
<servlet-class>org.apache.tester.FilterResponse01</servlet-class>
</servlet>
@@ -844,6 +864,16 @@
<servlet-mapping>
<servlet-name>ErrorPage09</servlet-name>
<url-pattern>/WrappedErrorPage09</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>FilterRequest01</servlet-name>
+ <url-pattern>/FilterRequest01</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>FilterRequest01</servlet-name>
+ <url-pattern>/WrappedFilterRequest01</url-pattern>
</servlet-mapping>
<servlet-mapping>