tweak tests and add some commenting

This commit is contained in:
Jesse McConnell 2012-11-29 11:30:02 -06:00
parent 51bb01e14b
commit a22f2a25eb
2 changed files with 16 additions and 3 deletions

View File

@ -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;
}

View File

@ -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