use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class SecuredRemoteAddressRequestWrapperFactoryTest method test1.
/**
*/
@Test
public void test1() {
SecuredRemoteAddressRequestWrapperFactory factory = new SecuredRemoteAddressRequestWrapperFactory();
MockHttpServletRequest request = tester.getRequest();
request.setSecure(true);
assertFalse(factory.needsWrapper(request));
request.setRemoteAddr("111.222.333.444");
assertFalse(factory.needsWrapper(request));
request.setSecure(false);
assertTrue(factory.needsWrapper(request));
request.setRemoteAddr("10.222.333.444");
assertFalse(factory.needsWrapper(request));
request.setRemoteAddr("129.222.333.444");
assertTrue(factory.needsWrapper(request));
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class ServletWebRequestTest method wicket3599.
/**
* Tests that {@link ServletWebRequest#getClientUrl()} returns the current url + the query
* string when this is not error dispatched request. When the request is error dispatched it
* returns just the request uri to the error page without the query string
*/
@Test
public void wicket3599() {
MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null);
httpRequest.setURL(httpRequest.getContextPath() + "/request/Uri");
httpRequest.setParameter("some", "parameter");
ServletWebRequest webRequest = new ServletWebRequest(httpRequest, "");
Url clientUrl = webRequest.getClientUrl();
assertEquals("request/Uri?some=parameter", clientUrl.toString());
// simulates a request that has errors metadata
httpRequest.setAttribute("javax.servlet.error.request_uri", httpRequest.getContextPath() + "/any/source/of/error");
ServletWebRequest errorWebRequest = new ServletWebRequest(httpRequest, "");
Url errorClientUrl = errorWebRequest.getClientUrl();
assertEquals("any/source/of/error", errorClientUrl.toString());
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class ServletWebRequestTest method testClientURLIsContextRelativeInErrorResponses.
/**
* <a href="https://issues.apache.org/jira/browse/WICKET-4168">WICKET-4168</a>
*/
@Test
public void testClientURLIsContextRelativeInErrorResponses() {
MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null);
httpRequest.setURL(httpRequest.getContextPath() + "/request/Uri");
String problematiURI = httpRequest.getContextPath() + "/any/source/of/error";
httpRequest.setAttribute("javax.servlet.error.request_uri", problematiURI);
ServletWebRequest errorWebRequest = new ServletWebRequest(httpRequest, "");
Url errorClientUrl = errorWebRequest.getClientUrl();
assertEquals("any/source/of/error", errorClientUrl.toString());
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class ServletWebRequestTest method wicket5203.
/**
* Tests that {@link ServletWebRequest#getClientUrl()} returns the current url + the query
* string when this is not forward dispatched request. When the request is error dispatched it
* returns just the request uri to the error page without the query string
*/
@Test
public void wicket5203() {
String filterPath = "filterPath";
MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null);
httpRequest.setURL(httpRequest.getContextPath() + '/' + filterPath + "/request/Path");
httpRequest.setParameter("some", "parameter");
ServletWebRequest webRequest = new ServletWebRequest(httpRequest, filterPath);
Url clientUrl = webRequest.getClientUrl();
assertEquals("request/Path?some=parameter", clientUrl.toString());
// simulates a request that has errors metadata
httpRequest.setAttribute("javax.servlet.error.request_uri", httpRequest.getContextPath() + '/' + filterPath + "/any/source/of/error");
ServletWebRequest errorWebRequest = new ServletWebRequest(httpRequest, filterPath);
Url errorClientUrl = errorWebRequest.getClientUrl();
assertEquals("any/source/of/error", errorClientUrl.toString());
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class RequestUtilsTest method charset.
@Test
public void charset() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(null, null, null);
request.setCharacterEncoding("UTF-8");
assertEquals(Charset.forName("UTF-8"), RequestUtils.getCharset(request));
request.setCharacterEncoding("FOO");
assertEquals(Charset.forName("UTF-8"), RequestUtils.getCharset(request));
}
Aggregations