Search in sources :

Example 16 with MockRequestContext

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

the class AllSpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldBeChecked.

@Test
public void ensureRemoteIpShouldBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction("^192\\.158\\..+", "", 0);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("192.158.5.781");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 17 with MockRequestContext

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

the class AllSpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldNotBeChecked.

@Test
public void ensureRemoteIpShouldNotBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction("^192\\.158\\..+", "", 0);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("193.158.5.781");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertNotEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 18 with MockRequestContext

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

the class AllSpnegoKnownClientSystemsFilterActionTests method verifyIpMismatchWhenCheckingHostnameForSpnego.

@Test
public void verifyIpMismatchWhenCheckingHostnameForSpnego() {
    final HostNameSpnegoKnownClientSystemsFilterAction action = new HostNameSpnegoKnownClientSystemsFilterAction("14\\..+", "", 0, "\\w+\\.\\w+\\.\\w+");
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr(ALTERNATE_REMOTE_IP);
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().no(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 19 with MockRequestContext

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

the class LdapSpnegoKnownClientSystemsFilterActionTests method ensureLdapAttributeShouldDoSpnego.

@Test
public void ensureLdapAttributeShouldDoSpnego() throws Exception {
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("localhost");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.execute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with MockRequestContext

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

the class GenerateServiceTicketActionTests method verifyTicketGrantingTicketExpiredTgt.

@Test
public void verifyTicketGrantingTicketExpiredTgt() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put(SERVICE_PARAM, RegisteredServiceTestUtils.getService());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE_PARAM);
    WebUtils.putTicketGrantingTicketInScopes(context, this.ticketGrantingTicket);
    this.ticketGrantingTicket.markTicketExpired();
    getTicketRegistry().updateTicket(this.ticketGrantingTicket);
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
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)

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