From a22f2a25ebd93f5d361dbc6b3c07deb2697be450 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 29 Nov 2012 11:30:02 -0600 Subject: [PATCH] tweak tests and add some commenting --- .../eclipse/jetty/rewrite/handler/ValidUrlRule.java | 11 +++++++++++ .../jetty/rewrite/handler/ValidUrlRuleTest.java | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ValidUrlRule.java b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ValidUrlRule.java index 195f451bcef..688859a2adf 100644 --- a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ValidUrlRule.java +++ b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ValidUrlRule.java @@ -25,6 +25,15 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.util.URIUtil; +/** + * This rule can be used to protect against invalid unicode characters in a url making it into applications. + * + * The logic is as follows. + * + * - if decoded uri character is an iso control character return code/reason + * - if no UnicodeBlock is found for character return code/reason + * - if character is in UnicodeBlock.SPECIALS return code/reason + */ public class ValidUrlRule extends Rule { String _code = "400"; @@ -81,10 +90,12 @@ public class ValidUrlRule extends Rule response.setStatus(code); } + // we have matched, return target and consider it is handled return target; } } + // we have not matched so return null return null; } diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java index 4513d80331a..1ba760721a3 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java @@ -58,14 +58,16 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase } @Test - public void testInvalidUrl2() throws Exception + public void testInvalidUrlWithReason() throws Exception { - _rule.setCode("404"); + _rule.setCode("405"); + _rule.setReason("foo"); _request.setRequestURI("/%00/"); String result = _rule.matchAndApply(_request.getRequestURI(), _request, _response); - assertEquals(404,_response.getStatus()); + assertEquals(405,_response.getStatus()); + assertEquals("foo",_response.getReason()); } @Test