Author: markt
Date: Wed Nov 2 11:57:28 2016
New Revision: 1767643
URL: http://svn.apache.org/viewvc?rev=1767643&view=rev
Log:
Update the tests to check for a 400 response rather than ignoring the
failed test
Modified:
tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
Modified:
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=1767643&r1=1767642&r2=1767643&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
(original)
+++ tomcat/trunk/test/org/apache/catalina/valves/rewrite/TestRewriteValve.java
Wed Nov 2 11:57:28 2016
@@ -19,7 +19,6 @@ package org.apache.catalina.valves.rewri
import java.nio.charset.StandardCharsets;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import org.apache.catalina.Context;
@@ -228,24 +227,22 @@ public class TestRewriteValve extends To
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithBothQsFlagsRNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE",
"/c/\u00C2\u00A1\u00C2\u00A1", "id=\u00C2\u00A1");
+ "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithBothQsFlagsRBNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/\u00C2\u00A1%C2%A1",
"id=%C2%A1");
+ "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@@ -277,26 +274,22 @@ public class TestRewriteValve extends To
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithBothQsFlagsRNEQSA() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE,QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/\u00C2\u00A1\u00C2\u00A1",
- "id=\u00C2\u00A1&di=\u00C2\u00AE");
+ "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithBothQsFlagsRBNEQSA() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE,QSA]",
- "/b/%C2%A1/id=%C2%A1?di=%C2%AE", "/c/\u00C2\u00A1%C2%A1",
- "id=%C2%A1&di=\u00C2\u00AE");
+ "/b/%C2%A1/id=%C2%A1?di=%C2%AE", null);
}
@@ -333,24 +326,22 @@ public class TestRewriteValve extends To
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithOriginalQsFlagsRNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,NE]",
- "/b/%C2%A1?id=%C2%A1", "/c/\u00C2\u00A1\u00C2\u00A1",
"id=\u00C2\u00A1");
+ "/b/%C2%A1?id=%C2%A1", null);
}
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithOriginalQsFlagsRBNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B,NE]",
- "/b/%C2%A1?id=%C2%A1", "/c/\u00C2\u00A1%C2%A1",
"id=\u00C2\u00A1");
+ "/b/%C2%A1?id=%C2%A1", null);
}
@@ -396,24 +387,22 @@ public class TestRewriteValve extends To
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithRewriteQsFlagsRNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,NE]",
- "/b/%C2%A1/id=%C2%A1", "/c/\u00C2\u00A1\u00C2\u00A1",
"id=\u00C2\u00A1");
+ "/b/%C2%A1/id=%C2%A1", null);
}
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8WithRewriteQsFlagsRBNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
doTestRewrite("RewriteRule ^/b/(.*)/(.*) /c/\u00A1$1?$2 [R,B,NE]",
- "/b/%C2%A1/id=%C2%A1", "/c/\u00C2\u00A1%C2%A1", "id=%C2%A1");
+ "/b/%C2%A1/id=%C2%A1", null);
}
@@ -455,24 +444,20 @@ public class TestRewriteValve extends To
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8FlagsRNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,NE]",
- "/b/%C2%A1", "/c/\u00C2\u00A1\u00C2\u00A1");
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,NE]", "/b/%C2%A1",
null);
}
@Test
- @Ignore // Use of NE results in invalid characters in request-target
public void testUtf8FlagsRBNE() throws Exception {
// Note %C2%A1 == \u00A1
// Failing to escape the redirect means UTF-8 bytes in the Location
// header which will be treated as if they are ISO-8859-1
- doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B,NE]",
- "/b/%C2%A1", "/c/\u00C2\u00A1%C2%A1");
+ doTestRewrite("RewriteRule ^/b/(.*) /c/\u00A1$1 [R,B,NE]",
"/b/%C2%A1", null);
}
@@ -526,22 +511,29 @@ public class TestRewriteValve extends To
tomcat.start();
- ByteChunk res = getUrl("http://localhost:" + getPort() + request);
+ ByteChunk res = new ByteChunk();
+ int rc = getUrl("http://localhost:" + getPort() + request, res, null);
res.setCharset(StandardCharsets.UTF_8);
- String body = res.toString();
- RequestDescriptor requestDesc = SnoopResult.parse(body);
- String requestURI = requestDesc.getRequestInfo("REQUEST-URI");
- Assert.assertEquals(expectedURI, requestURI);
-
- if (expectedQueryString != null) {
- String queryString =
requestDesc.getRequestInfo("REQUEST-QUERY-STRING");
- Assert.assertEquals(expectedQueryString, queryString);
- }
-
- if (expectedAttributeValue != null) {
- String attributeValue = requestDesc.getAttribute("X-Test");
- Assert.assertEquals(expectedAttributeValue, attributeValue);
+ if (expectedURI == null) {
+ // Rewrite is expected to fail. Probably because invalid characters
+ // were written into the request target
+ Assert.assertEquals(400, rc);
+ } else {
+ String body = res.toString();
+ RequestDescriptor requestDesc = SnoopResult.parse(body);
+ String requestURI = requestDesc.getRequestInfo("REQUEST-URI");
+ Assert.assertEquals(expectedURI, requestURI);
+
+ if (expectedQueryString != null) {
+ String queryString =
requestDesc.getRequestInfo("REQUEST-QUERY-STRING");
+ Assert.assertEquals(expectedQueryString, queryString);
+ }
+
+ if (expectedAttributeValue != null) {
+ String attributeValue = requestDesc.getAttribute("X-Test");
+ Assert.assertEquals(expectedAttributeValue, attributeValue);
+ }
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]