Search in sources :

Example 21 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class InitialFlowSetupActionCookieTests method verifySettingContextPath.

@Test
public void verifySettingContextPath() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath(CONST_CONTEXT_PATH);
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    this.action.doExecute(context);
    assertEquals(CONST_CONTEXT_PATH + '/', this.warnCookieGenerator.getCookiePath());
    assertEquals(CONST_CONTEXT_PATH + '/', this.tgtCookieGenerator.getCookiePath());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 22 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class InitialFlowSetupActionSsoTests method disableFlowIfNoService.

@Test
public void disableFlowIfNoService() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    this.thrown.expect(NoSuchFlowExecutionException.class);
    this.action.execute(context);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class ServiceAuthorizationCheckTests method unauthorizedServiceProvided.

@Test
public void unauthorizedServiceProvided() throws Exception {
    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.getFlowScope().put("service", this.unauthorizedService);
    this.thrown.expect(UnauthorizedServiceException.class);
    this.serviceAuthorizationCheck.doExecute(mockRequestContext);
    fail("Should have thrown UnauthorizedServiceException");
}
Also used : MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.Test)

Example 24 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class TicketGrantingTicketCheckActionTests method verifyValidTicket.

@Test
public void verifyValidTicket() throws Exception {
    final MockRequestContext ctx = new MockRequestContext();
    final AuthenticationResult ctxAuthN = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport());
    final TicketGrantingTicket tgt = this.getCentralAuthenticationService().createTicketGrantingTicket(ctxAuthN);
    WebUtils.putTicketGrantingTicketInScopes(ctx, tgt);
    final TicketGrantingTicketCheckAction action = new TicketGrantingTicketCheckAction(this.getCentralAuthenticationService());
    final Event event = action.doExecute(ctx);
    assertEquals(TicketGrantingTicketCheckAction.VALID, event.getId());
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) TicketGrantingTicketCheckAction(org.apereo.cas.web.flow.login.TicketGrantingTicketCheckAction) Test(org.junit.Test)

Example 25 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class TicketGrantingTicketCheckActionTests method verifyNullTicket.

@Test
public void verifyNullTicket() throws Exception {
    final MockRequestContext ctx = new MockRequestContext();
    final TicketGrantingTicketCheckAction action = new TicketGrantingTicketCheckAction(this.getCentralAuthenticationService());
    final Event event = action.doExecute(ctx);
    assertEquals(TicketGrantingTicketCheckAction.NOT_EXISTS, event.getId());
}
Also used : Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) TicketGrantingTicketCheckAction(org.apereo.cas.web.flow.login.TicketGrantingTicketCheckAction) Test(org.junit.Test)

Aggregations

MockRequestContext (org.springframework.webflow.test.MockRequestContext)73 Test (org.junit.Test)68 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)53 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)53 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)50 MockServletContext (org.springframework.mock.web.MockServletContext)46 Event (org.springframework.webflow.execution.Event)34 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)14 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)10 DeliveryOptions (org.opennms.reporting.core.DeliveryOptions)8 Credential (org.apereo.cas.authentication.Credential)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 Service (org.apereo.cas.authentication.principal.Service)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 Clients (org.pac4j.core.client.Clients)4 FacebookClient (org.pac4j.oauth.client.FacebookClient)4 MutableAttributeMap (org.springframework.webflow.core.collection.MutableAttributeMap)4 Authentication (org.apereo.cas.authentication.Authentication)3 SamlMetadataUIInfo (org.apereo.cas.support.saml.mdui.SamlMetadataUIInfo)3