Search in sources :

Example 1 with IRequestHandler

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());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) MockPageParametersAware(org.apache.wicket.MockPageParametersAware) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 2 with IRequestHandler

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());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) CryptoMapper(org.apache.wicket.core.request.mapper.CryptoMapper) WebApplication(org.apache.wicket.protocol.http.WebApplication) Test(org.junit.Test)

Example 3 with IRequestHandler

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestMapper(org.apache.wicket.request.IRequestMapper) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) Test(org.junit.Test)

Example 4 with IRequestHandler

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));
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestMapper(org.apache.wicket.request.IRequestMapper) Test(org.junit.Test)

Example 5 with IRequestHandler

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));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IRequestMapper(org.apache.wicket.request.IRequestMapper) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

IRequestHandler (org.apache.wicket.request.IRequestHandler)188 Test (org.junit.Test)159 Url (org.apache.wicket.request.Url)138 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)65 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)47 PageProvider (org.apache.wicket.core.request.handler.PageProvider)45 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)36 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)32 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)28 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)25 Request (org.apache.wicket.request.Request)25 MockPage (org.apache.wicket.MockPage)23 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)20 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)17 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)17 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)16 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)11 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)10 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)8 Page (org.apache.wicket.Page)6