Search in sources :

Example 6 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.

the class WebApplicationServiceFactoryTests method verifyServiceCreationSuccessfullyByService.

@Test
public void verifyServiceCreationSuccessfullyByService() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, "test");
    final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
    final WebApplicationService service = factory.createService(request);
    assertNotNull(service);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 7 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.

the class CentralAuthenticationServiceImplTests method authenticateTwiceWithRenew.

/**
     * This test simulates :
     * - a first authentication for a default service
     * - a second authentication with the renew parameter and the same service (and same credentials)
     * - a validation of the second ticket.
     * When supplemental authentications were returned with the chained authentications, the validation specification
     * failed as it only expects one authentication. Thus supplemental authentications should not be returned in the
     * chained authentications. Both concepts are orthogonal.
     */
@Test
public void authenticateTwiceWithRenew() throws AbstractTicketException, AuthenticationException {
    final CentralAuthenticationService cas = getCentralAuthenticationService();
    final Service svc = getService("testDefault");
    final UsernamePasswordCredential goodCredential = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
    final TicketGrantingTicket tgtId = cas.createTicketGrantingTicket(ctx);
    cas.grantServiceTicket(tgtId.getId(), svc, ctx);
    // simulate renew with new good same credentials
    final ServiceTicket st2Id = cas.grantServiceTicket(tgtId.getId(), svc, ctx);
    final Assertion assertion = cas.validateServiceTicket(st2Id.getId(), svc);
    final ValidationSpecification validationSpecification = new Cas20WithoutProxyingValidationSpecification();
    assertTrue(validationSpecification.isSatisfiedBy(assertion, new MockHttpServletRequest()));
}
Also used : Cas20WithoutProxyingValidationSpecification(org.apereo.cas.validation.Cas20WithoutProxyingValidationSpecification) ValidationSpecification(org.apereo.cas.validation.ValidationSpecification) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Assertion(org.apereo.cas.validation.Assertion) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Cas20WithoutProxyingValidationSpecification(org.apereo.cas.validation.Cas20WithoutProxyingValidationSpecification) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 8 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.

the class InitialFlowSetupActionCookieTests method verifySettingContextPath.

@Test
public void verifySettingContextPath() throws Exception {
    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 9 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest 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.thrown.expectMessage(startsWith("No flow execution could be found with key 'null'"));
    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 10 with MockHttpServletRequest

use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.

the class InitialFlowSetupActionTests method verifyNoServiceFound.

@Test
public void verifyNoServiceFound() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
    final Event event = this.action.execute(context);
    assertNull(WebUtils.getService(context));
    assertEquals("success", event.getId());
}
Also used : ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1056 Test (org.junit.Test)827 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)557 Before (org.junit.Before)92 MockFilterChain (org.springframework.mock.web.MockFilterChain)89 FilterChain (javax.servlet.FilterChain)79 MockServletContext (org.springframework.mock.web.MockServletContext)71 Authentication (org.springframework.security.core.Authentication)70 HttpServletRequest (javax.servlet.http.HttpServletRequest)51 MockHttpSession (org.springframework.mock.web.MockHttpSession)49 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)47 Cookie (javax.servlet.http.Cookie)44 MockRequestContext (org.springframework.webflow.test.MockRequestContext)42 HttpServletResponse (javax.servlet.http.HttpServletResponse)39 HashMap (java.util.HashMap)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 ModelAndView (org.springframework.web.servlet.ModelAndView)32 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)30 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)30 RegisteredService (org.apereo.cas.services.RegisteredService)27