use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class WicketTesterTest method setQueryParameterWhenRequestHasAnQueryUrl.
/**
* Asserting that parameters set in request get processed, even if the request URL already has
* query parameters
*/
@Test
public void setQueryParameterWhenRequestHasAnQueryUrl() {
PageParameters parameters = new PageParameters();
parameters.set("q_1", "q_1_value");
IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, parameters);
IRequestHandler pageRequestHandler = new BookmarkablePageRequestHandler(testPageProvider);
Url url = tester.getApplication().getRootRequestMapper().mapHandler(pageRequestHandler);
tester.getRequest().setParameter("q_2", "q_2_value");
tester.getRequest().setUrl(url);
tester.processRequest();
MockPageParametersAware page = (MockPageParametersAware) tester.getLastRenderedPage();
assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString());
assertEquals("q_2_value", page.getLastQueryParameters().getParameterValue("q_2").toString());
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class ISecuritySettingsTest method enforceMountsWithCryptoMapper.
/**
* https://issues.apache.org/jira/browse/WICKET-5560
*/
@Test
public void enforceMountsWithCryptoMapper() {
WebApplication app = tester.getApplication();
IRequestHandler handler = new BookmarkablePageRequestHandler(new PageProvider(UnknownPage.class));
String plainTextNonMountedUrl = tester.urlFor(handler).toString();
assertTrue("Plain text non mounted url should start with wicket/bookmarkable/: " + plainTextNonMountedUrl, plainTextNonMountedUrl.startsWith("wicket/bookmarkable/"));
tester.executeUrl(plainTextNonMountedUrl);
tester.assertRenderedPage(UnknownPage.class);
app.setRootRequestMapper(new CryptoMapper(app.getRootRequestMapper(), app));
/*
* Execute dummy request to get WicketTester to re-initialise with CryptoMapper in place.
*/
tester.executeUrl("");
String encryptedNonMountedUrl = tester.urlFor(handler).toString();
assertFalse("Encrypted URL should not start with wicket/bookmarkable/" + encryptedNonMountedUrl, encryptedNonMountedUrl.startsWith("wicket/bookmarkable/"));
tester.executeUrl(plainTextNonMountedUrl);
assertNull(tester.getLastRenderedPage());
tester.executeUrl(encryptedNonMountedUrl);
tester.assertRenderedPage(UnknownPage.class);
app.mountPackage("unknown", UnknownPage.class);
tester.executeUrl(plainTextNonMountedUrl);
assertNull(tester.getLastRenderedPage());
tester.executeUrl(encryptedNonMountedUrl);
tester.assertRenderedPage(UnknownPage.class);
app.getSecuritySettings().setEnforceMounts(true);
tester.executeUrl(plainTextNonMountedUrl);
assertNull(tester.getLastRenderedPage());
tester.executeUrl(encryptedNonMountedUrl);
assertNull(tester.getLastRenderedPage());
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class HttpsMapperTest method mapRequestWithCustomPorts.
@Test
public void mapRequestWithCustomPorts() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig(10, 20));
ServletWebRequest request = mock(ServletWebRequest.class);
HttpServletRequest req = mock(HttpServletRequest.class);
when(request.getContainerRequest()).thenReturn(req);
// https handler on http request, redirect to https
setupRequest(req, "http", "localhost", 10, "/ctx", "foo=bar");
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
when(delegate.mapRequest(request)).thenReturn(handler);
IRequestHandler resolved = mapper.mapRequest(request);
assertThat(resolved, is(instanceOf(RedirectHandler.class)));
assertThat(((RedirectHandler) resolved).getUrl(), is("https://localhost:20/ctx?foo=bar"));
// http handler on http request, return the original handler
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
reset(delegate);
when(delegate.mapRequest(request)).thenReturn(handler);
setupRequest(req, "https", "localhost", 20, "/ctx", "foo=bar");
resolved = mapper.mapRequest(request);
assertThat(resolved, is(instanceOf(RedirectHandler.class)));
assertThat(((RedirectHandler) resolved).getUrl(), is("http://localhost:10/ctx?foo=bar"));
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class HttpsMapperTest method getDesiredSchemeOfHandler.
@Test
public void getDesiredSchemeOfHandler() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.HTTPS));
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.HTTP));
handler = mock(IRequestHandler.class);
assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.ANY));
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class HttpsMapperTest method mapHandler.
@Test
public void mapHandler() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
ServletWebRequest request = mock(ServletWebRequest.class);
HttpServletRequest req = mock(HttpServletRequest.class);
when(request.getContainerRequest()).thenReturn(req);
// rendering url to https page on http, set protocol
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
Url url = new Url();
when(delegate.mapHandler(handler)).thenReturn(url);
when(req.getScheme()).thenReturn("http");
mapper.mapHandler(handler, request);
assertThat(url.getProtocol(), is("https"));
assertThat(url.getPort(), is(443));
// render url to http page on http, ignore protocol
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
url = new Url();
reset(delegate);
when(delegate.mapHandler(handler)).thenReturn(url);
when(req.getScheme()).thenReturn("http");
mapper.mapHandler(handler, request);
assertThat(url.getProtocol(), is(nullValue()));
// render url to http page on https, set protocol
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
url = new Url();
reset(delegate);
when(delegate.mapHandler(handler)).thenReturn(url);
when(req.getScheme()).thenReturn("https");
mapper.mapHandler(handler, request);
assertThat(url.getProtocol(), is("http"));
assertThat(url.getPort(), is(80));
}
Aggregations