Search in sources :

Example 51 with IRequestHandler

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

the class CryptoMapperTest method mountedPageRequestListenerParameter.

/**
 * Tests that PageComponentInfo parameters are encrypted on Mounted pages
 */
@Test
public void mountedPageRequestListenerParameter() {
    final String componentPath = "link";
    PageAndComponentProvider provider = new PageAndComponentProvider(Page1.class, componentPath);
    IRequestHandler requestHandler = new ListenerRequestHandler(provider);
    Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler);
    assertTrue(plainUrl.toString().startsWith(MOUNTED_URL));
    /*
		 * Do not allow unencrypted request listener urls to mounted pages.
		 */
    assertNull(mapper.mapRequest(getRequest(plainUrl)));
    /*
		 * Test encryption of request listener parameter.
		 */
    Url encryptedUrl = mapper.mapHandler(requestHandler);
    assertEquals(Url.parse(MOUNTED_URL).getSegments(), encryptedUrl.getSegments());
    assertTrue(encryptedUrl.getQueryParameters().size() > 0);
    for (Url.QueryParameter qp : encryptedUrl.getQueryParameters()) {
        if (Strings.isEmpty(qp.getValue())) {
            PageComponentInfo pci = PageComponentInfo.parse(qp.getName());
            assertNull("PageComponentInfo query parameter not encrypted", pci);
        }
    }
    requestHandler = mapper.mapRequest(getRequest(encryptedUrl));
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
    ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
    assertEquals(componentPath, handler.getComponentPath());
    assertEquals(Page1.class, handler.getPageClass());
    /*
		 * We anticipate that sometimes multiple cryptomappers will be used. It should still work in these situations.
		 */
    requestHandler = new CryptoMapper(mapper, tester.getApplication()).mapRequest(getRequest(encryptedUrl));
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
    handler = (ListenerRequestHandler) requestHandler;
    assertEquals(componentPath, handler.getComponentPath());
    assertEquals(Page1.class, handler.getPageClass());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) Test(org.junit.Test)

Example 52 with IRequestHandler

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

the class CryptoMapperTest method bookmarkablePageDecrypt2.

/**
 * https://issues.apache.org/jira/browse/WICKET-6131
 *
 * Tests that encrypted URLs for bookmarkable pages are decrypted and passed to the wrapped mapper.
 * Extra segments should be ignored.
 */
@Test
public void bookmarkablePageDecrypt2() {
    String encryptedExtraSegments = "/i87b7/i87b7";
    Request request = getRequest(Url.parse(ENCRYPTED_BOOKMARKABLE_URL + encryptedExtraSegments));
    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 53 with IRequestHandler

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

the class MountedMapperTest method encode5.

/**
 */
@Test
public void encode5() {
    MockPage page = new MockPage(15);
    page.getPageParameters().set(0, "i1");
    page.getPageParameters().set(1, "i2");
    page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
    page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
    page.setCreatedBookmarkable(false);
    IPageProvider provider = new PageProvider(page);
    IRequestHandler handler = new RenderPageRequestHandler(provider);
    Url url = encoder.mapHandler(handler);
    // mounted pages must render mounted url even for page that has not been
    // created by
    // bookmarkable
    // URL
    assertEquals("some/mount/path/i1/i2?15&a=b&b=c", url.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) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 54 with IRequestHandler

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

the class MountedMapperTest method placeholderEncode3.

/**
 * Test Url creation with {@link RenderPageRequestHandler}. Cheat that the page instance is not
 * new, this way the produced Url has version '1' in the page info parameter
 */
@Test
public void placeholderEncode3() {
    PageParameters parameters = new PageParameters();
    parameters.set(0, "i1");
    parameters.set(1, "i2");
    parameters.set("a", "b", INamedParameters.Type.QUERY_STRING);
    parameters.set("b", "c", INamedParameters.Type.QUERY_STRING);
    parameters.set("param1", "p1", INamedParameters.Type.PATH);
    parameters.set("param2", "p2", INamedParameters.Type.PATH);
    PageProvider provider = new PageProvider(MockPage.class, parameters) {

        @Override
        public boolean isNewPageInstance() {
            return false;
        }
    };
    provider.setPageSource(context);
    IRequestHandler handler = new RenderPageRequestHandler(provider);
    Url url = placeholderEncoder.mapHandler(handler);
    assertEquals("some/p1/path/p2/i1/i2?1&a=b&b=c", url.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) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 55 with IRequestHandler

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

the class MountedMapperTest method placeholderDecodeWithIndexedParameters.

/**
 */
@Test
public void placeholderDecodeWithIndexedParameters() {
    Url url = Url.parse("some/p1/path/p2/p3/p4");
    IRequestHandler handler = placeholderEncoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    assertEquals(2, page.getPageParameters().getIndexedCount());
    assertTrue(page.getPageParameters().getNamedKeys().size() == 2);
    assertEquals("p1", page.getPageParameters().get("param1").toString());
    assertEquals("p2", page.getPageParameters().get("param2").toString());
    assertEquals("p3", page.getPageParameters().get(0).toString());
    assertEquals("p4", page.getPageParameters().get(1).toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) 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