Author: markt
Date: Thu Dec 11 19:23:27 2014
New Revision: 1644730
URL: http://svn.apache.org/r1644730
Log:
Start to put together some unit tests for the RewriteValve based on
Konstantin's concerns raised in
https://issues.apache.org/bugzilla/show_bug.cgi?id=57215
Added:
tomcat/trunk/test/org/apache/catalina/valves/rewrite/
tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
(with props)
Modified:
tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
Modified: tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=1644730&r1=1644729&r2=1644730&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Thu Dec
11 19:23:27 2014
@@ -232,6 +232,25 @@ public abstract class TomcatBaseTest ext
}
+ /**
+ * Simple servlet that dumps request information. Tests using this should
+ * note that additional information may be added to in the future and
should
+ * therefore test return values accordingly.
+ */
+ public static final class SnoopServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ resp.setContentType("text/plain");
+ PrintWriter out = resp.getWriter();
+ out.println("00-RequestURI-" + req.getRequestURI());
+ }
+ }
+
+
/*
* Wrapper for getting the response.
*/
Added:
tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java?rev=1644730&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
(added)
+++ tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
Thu Dec 11 19:23:27 2014
@@ -0,0 +1,64 @@
+/*
+ * 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.valves.rewrite;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TestRewriteValve extends TomcatBaseTest {
+
+ @Test
+ public void testNoRewrite() throws Exception {
+ doTestRewrite("");
+ }
+
+ @Test
+ @Ignore // getRequestURI is not encoded
+ public void testNoopRewrite() throws Exception {
+ doTestRewrite("RewriteRule ^(.*) $1");
+ }
+
+ private void doTestRewrite(String config) throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // No file system docBase required
+ Context ctx = tomcat.addContext("", null);
+
+ RewriteValve rewriteValve = new RewriteValve();
+ ctx.getPipeline().addValve(rewriteValve);
+
+ rewriteValve.setConfiguration(config);
+
+ // Note: URLPatterns should be URL encoded
+ // (http://svn.apache.org/r285186)
+ Tomcat.addServlet(ctx, "snoop", new SnoopServlet());
+ ctx.addServletMapping("/a/%255A", "snoop");
+
+ tomcat.start();
+
+ ByteChunk res = getUrl("http://localhost:" + getPort() + "/a/%255A");
+
+ String body = res.toString();
+ Assert.assertTrue(body, body.contains("/a/%255A"));
+ }
+}
Propchange:
tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]