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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations