SEC-1714: RegexRequestMatcher should prepend question mark to query string.

This commit is contained in:
Luke Taylor
2011-04-11 14:02:54 +01:00
parent 49dd928faa
commit ef72dd1986
2 changed files with 45 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
package org.springframework.security.web.util;
import static org.junit.Assert.*;
import org.junit.*;
import org.springframework.mock.web.MockHttpServletRequest;
/**
* @author Luke Taylor
*/
public class RegexRequestMatcherTests {
@Test
public void doesntMatchIfHttpMethodIsDifferent() throws Exception {
RegexRequestMatcher matcher = new RegexRequestMatcher(".*", "GET");
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/anything");
assertFalse(matcher.matches(request));
}
@Test
public void matchesIfHttpMethodAndPathMatch() throws Exception {
RegexRequestMatcher matcher = new RegexRequestMatcher(".*", "GET");
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/anything");
request.setServletPath("/anything");
assertTrue(matcher.matches(request));
}
@Test
public void queryStringIsMatcherCorrectly() throws Exception {
RegexRequestMatcher matcher = new RegexRequestMatcher(".*\\?x=y", "GET");
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/any/path?x=y");
request.setServletPath("/any");
request.setPathInfo("/path");
request.setQueryString("x=y");
assertTrue(matcher.matches(request));
}
}