Search in sources :

Example 41 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class CryptoMapperTest method resourceReferenceWithModifiedSegments.

/**
 * Relative ResourceReferences, WICKET-3514
 */
@Test
public void resourceReferenceWithModifiedSegments() {
    PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt");
    Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
    url.getSegments().remove(url.getSegments().size() - 1);
    url.getSegments().add("modified-crypt.txt");
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(ResourceReferenceRequestHandler.class));
    ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler;
    assertEquals(getClass(), handler.getResourceReference().getScope());
    assertEquals("crypt/modified-crypt.txt", handler.getResourceReference().getName());
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) Request(org.apache.wicket.request.Request) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 42 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class CryptoMapperTest method homePageForceEncryptionOfRequestListener.

/**
 * Tests that we do not allow unencrypted URLs to IRequestListeners on the home page, like: ?0-0.ILinkListener-link
 */
@Test
public void homePageForceEncryptionOfRequestListener() {
    PageAndComponentProvider provider = new PageAndComponentProvider(tester.getApplication().getHomePage(), "link");
    IRequestHandler requestHandler = new BookmarkableListenerRequestHandler(provider);
    Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler);
    assertTrue("Plain URL for home page has segments: " + plainUrl.toString(), plainUrl.getSegments().isEmpty());
    assertNull(mapper.mapRequest(getRequest(plainUrl)));
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 43 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class CryptoMapperTest method pageInstanceDecrypt.

/**
 * Make sure that encrypted page instance URLs are decrypted and the correct handler resolved.
 */
@Test
public void pageInstanceDecrypt() {
    IRequestHandler requestHandler = mapper.mapRequest(getRequest(Url.parse(ENCRYPTED_PAGE_INSTANCE_URL)));
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class));
    RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
    assertEquals(5, handler.getPageId().intValue());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) Test(org.junit.Test)

Example 44 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class CryptoMapperTest method pageParameters.

/**
 * Tests that named and indexed parameters are properly (en|de)crypted
 */
@Test
public void pageParameters() {
    String expectedEncrypted = "L7ExSNbPC4sb6TPJDblCAopL53TWmZP5y7BQEaJSJAC05HXod5M5U7gT2yNT0lK5L6L09ZAOoZkGyUhseyPrC4S5tqUUrV6zipc4_Ni877FDOOoE5C_Cd7YCyK1xSScpVhno6LeBz2wiu5oWyf7hB1RKcv6zkhEBmbx8vU7K7-e4xe1_LO8Y3fhEjMSQyU9BVh7Uz4HKzkR2OxFo5LaDzQ/L7E59/yPr6a/5L6ae/OxF2c";
    PageParameters expectedParameters = new PageParameters();
    expectedParameters.add("namedKey1", "namedValue1");
    expectedParameters.add("namedKey2", "namedValue2");
    expectedParameters.set(0, "indexedValue1");
    expectedParameters.set(1, "indexedValue2");
    RenderPageRequestHandler renderPageRequestHandler = new RenderPageRequestHandler(new PageProvider(Page2.class, 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(Page2.class, handler.getPageClass());
    PageParameters actualParameters = handler.getPageParameters();
    assertEquals(expectedParameters, actualParameters);
}
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) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 45 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler 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)

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