Search in sources :

Example 1 with PageProvider

use of org.apache.wicket.core.request.handler.PageProvider 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 PageProvider

use of org.apache.wicket.core.request.handler.PageProvider 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 PageProvider

use of org.apache.wicket.core.request.handler.PageProvider 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 PageProvider

use of org.apache.wicket.core.request.handler.PageProvider 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 PageProvider

use of org.apache.wicket.core.request.handler.PageProvider 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

PageProvider (org.apache.wicket.core.request.handler.PageProvider)60 Test (org.junit.Test)49 IRequestHandler (org.apache.wicket.request.IRequestHandler)45 Url (org.apache.wicket.request.Url)38 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)36 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)34 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)23 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)17 MockPage (org.apache.wicket.MockPage)16 Page (org.apache.wicket.Page)5 TestMapperContext (org.apache.wicket.core.request.mapper.TestMapperContext)4 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 WebPage (org.apache.wicket.markup.html.WebPage)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)3 MockPageParametersAware (org.apache.wicket.MockPageParametersAware)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ExceptionErrorPage (org.apache.wicket.markup.html.pages.ExceptionErrorPage)2