Search in sources :

Example 16 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class CryptoMapperTest method homePageWithNonEncryptedQueryParameters.

/**
 * Verifies that the home page can be reached with non-encrypted query parameters.
 * https://issues.apache.org/jira/browse/WICKET-4345
 *
 * Also, test that the URL for the home page with non-encrypted parameters is not encrypted, to avoid unnecessary redirects.
 */
@Test
public void homePageWithNonEncryptedQueryParameters() {
    String expectedEncrypted = "?namedKey1=namedValue1";
    PageParameters expectedParameters = new PageParameters();
    expectedParameters.add("namedKey1", "namedValue1");
    RenderPageRequestHandler renderPageRequestHandler = new RenderPageRequestHandler(new PageProvider(tester.getApplication().getHomePage(), expectedParameters));
    Url url = mapper.mapHandler(renderPageRequestHandler);
    assertEquals(expectedEncrypted, url.toString());
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class));
    RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
    assertEquals(tester.getApplication().getHomePage(), handler.getPageClass());
    StringValue queryParam = handler.getPageParameters().get("namedKey1");
    assertEquals("namedValue1", queryParam.toOptionalString());
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 17 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class CryptoMapperTest method bookmarkablePageEncrypt.

/**
 * Tests that URLs for bookmarkable pages are encrypted.
 */
@Test
public void bookmarkablePageEncrypt() {
    IRequestHandler renderPage2BookmarkableHandler = new RenderPageRequestHandler(new PageProvider(Page2.class, new PageParameters()));
    Url plainTextUrl = mapper.getDelegateMapper().mapHandler(renderPage2BookmarkableHandler);
    assertEquals(PLAIN_BOOKMARKABLE_URL, plainTextUrl.toString());
    Url encryptedUrl = mapper.mapHandler(renderPage2BookmarkableHandler);
    assertEquals(ENCRYPTED_BOOKMARKABLE_URL, encryptedUrl.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 18 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class CryptoMapperTest method markedEncryptedUrlDecrypt.

@Test
public void markedEncryptedUrlDecrypt() {
    mapper.setMarkEncryptedUrls(true);
    Request request = getRequest(Url.parse("crypt." + ENCRYPTED_BOOKMARKABLE_URL));
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertTrue(requestHandler instanceof RenderPageRequestHandler);
    RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
    assertEquals(Page2.class, handler.getPageClass());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) Request(org.apache.wicket.request.Request) Test(org.junit.Test)

Example 19 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class CryptoMapperTest method homePage.

/**
 * Tests that the home page is requestable.
 */
@Test
public void homePage() {
    IRequestHandler requestHandler = mapper.mapRequest(getRequest(Url.parse("")));
    assertNotNull("Unable to map request for home page", requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class));
    RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
    assertSame(tester.getApplication().getHomePage(), handler.getPageClass());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) Test(org.junit.Test)

Example 20 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class CryptoMapperTest method expiredMarkedEncryptedUrlThrowsPageExpiredException.

@Test(expected = PageExpiredException.class)
public void expiredMarkedEncryptedUrlThrowsPageExpiredException() {
    mapper.setMarkEncryptedUrls(true);
    Url encryptedUrl = mapper.mapHandler(new RenderPageRequestHandler(new PageProvider(Page2.class)));
    assertTrue(encryptedUrl.getSegments().get(0).startsWith("crypt."));
    encryptedUrl.getSegments().remove(0);
    encryptedUrl.getSegments().add(0, "crypt.no decryptable");
    mapper.mapRequest(getRequest(encryptedUrl));
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)75 IRequestHandler (org.apache.wicket.request.IRequestHandler)64 Test (org.junit.Test)61 Url (org.apache.wicket.request.Url)50 PageProvider (org.apache.wicket.core.request.handler.PageProvider)36 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)32 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)19 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)16 MockPage (org.apache.wicket.MockPage)13 Request (org.apache.wicket.request.Request)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)5 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)3 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)3 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)2 WebResponse (org.apache.wicket.request.http.WebResponse)2