Search in sources :

Example 1 with ComponentEventLinkEncoder

use of org.apache.tapestry5.services.ComponentEventLinkEncoder in project tapestry-5 by apache.

the class RequestSecurityManagerImplTest method check_page_security.

@Test(dataProvider = "check_page_security_data")
public void check_page_security(boolean secureRequest, boolean securePage, LinkSecurity expectedLinkSecurity) {
    Request request = mockRequest();
    Response response = mockResponse();
    MetaDataLocator locator = mockMetaDataLocator();
    ComponentEventLinkEncoder encoder = newMock(ComponentEventLinkEncoder.class);
    train_isSecure(request, secureRequest);
    train_isSecure(locator, PAGE_NAME, securePage);
    replay();
    RequestSecurityManager manager = new RequestSecurityManagerImpl(request, response, encoder, locator, true);
    assertEquals(manager.checkPageSecurity(PAGE_NAME), expectedLinkSecurity);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) Request(org.apache.tapestry5.http.services.Request) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 2 with ComponentEventLinkEncoder

use of org.apache.tapestry5.services.ComponentEventLinkEncoder in project tapestry-5 by apache.

the class RequestSecurityManagerImplTest method check_page_not_secure.

@Test
public void check_page_not_secure() throws Exception {
    Request request = mockRequest();
    Response response = mockResponse();
    MetaDataLocator locator = mockMetaDataLocator();
    ComponentEventLinkEncoder encoder = newMock(ComponentEventLinkEncoder.class);
    train_isSecure(request, false);
    train_isSecure(locator, PAGE_NAME, false);
    replay();
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(PAGE_NAME, new EmptyEventContext(), false);
    RequestSecurityManager manager = new RequestSecurityManagerImpl(request, response, encoder, locator, true);
    assertFalse(manager.checkForInsecurePageRenderRequest(parameters));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 3 with ComponentEventLinkEncoder

use of org.apache.tapestry5.services.ComponentEventLinkEncoder in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method root_index_page_gone.

@Test
public void root_index_page_gone() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("Index")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("Index", new EmptyEventContext());
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 4 with ComponentEventLinkEncoder

use of org.apache.tapestry5.services.ComponentEventLinkEncoder in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method index_stripped_off.

@Test
public void index_stripped_off() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("admin/Index")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/admin/abc", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("admin/Index", new ArrayEventContext(typeCoercer, "abc"));
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 5 with ComponentEventLinkEncoder

use of org.apache.tapestry5.services.ComponentEventLinkEncoder in project tapestry-5 by apache.

the class LinkSourceImplTest method testEventLinkCreation2.

private void testEventLinkCreation2(String pageName, String nestedId, String eventType, boolean forForm, Object... context) {
    Page primaryPage = mockPage();
    PageRenderQueue queue = mockPageRenderQueue();
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    LinkCreationListener2 listener = mockLinkCreationListener2();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ArrayEventContext eventContext = new ArrayEventContext(typeCoercer, context);
    ArrayEventContext pageEventContext = new ArrayEventContext(typeCoercer, "a", "b");
    train_getRenderingPage(queue, null);
    train_getName(primaryPage, pageName);
    train_collectPageActivationContext(collector, pageName, "a", "b");
    ComponentEventRequestParameters parameters = new ComponentEventRequestParameters(pageName, pageName, nestedId, eventType, pageEventContext, eventContext);
    expect(linkEncoder.createComponentEventLink(parameters, forForm)).andReturn(link);
    listener.createdComponentEventLink(link, parameters);
    List<LinkCreationListener2> configuration = CollectionFactory.newList(listener);
    replay();
    LinkSource source = new LinkSourceImpl(queue, collector, typeCoercer, null, linkEncoder, null, null, configuration);
    Link returnedLink = source.createComponentEventLink(primaryPage, nestedId, eventType, forForm, context);
    // Make sure the same link is returned.
    assertSame(returnedLink, link);
    verify();
}
Also used : ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) Page(org.apache.tapestry5.internal.structure.Page) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) Link(org.apache.tapestry5.http.Link)

Aggregations

ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)13 Link (org.apache.tapestry5.http.Link)10 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)9 Test (org.testng.annotations.Test)9 Response (org.apache.tapestry5.http.services.Response)7 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)5 Request (org.apache.tapestry5.http.services.Request)4 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)4 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)4 RequestGlobals (org.apache.tapestry5.http.services.RequestGlobals)3 Page (org.apache.tapestry5.internal.structure.Page)3 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)3 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)3 ContextPathEncoder (org.apache.tapestry5.services.ContextPathEncoder)3 EventContext (org.apache.tapestry5.EventContext)2