Search in sources :

Example 36 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class SingleSignOnSessionStatusEndpointTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
    request.setCookies(response.getCookies());
    val entity = singleSignOnSessionStatusEndpoint.ssoStatus(null, request);
    assertTrue(entity.getStatusCode().is2xxSuccessful());
    val body = Objects.requireNonNull(Map.class.cast(entity.getBody()));
    assertTrue(body.containsKey("principal"));
    assertTrue(body.containsKey("authenticationDate"));
    assertTrue(body.containsKey("ticketGrantingTicketCreationTime"));
    assertTrue(body.containsKey("ticketGrantingTicketPreviousTimeUsed"));
    assertTrue(body.containsKey("ticketGrantingTicketLastTimeUsed"));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Map(java.util.Map) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 37 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class SamlResponseArtifactEncoderTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val registeredService = getSamlRegisteredServiceForTestShib();
    val authnRequest = getAuthnRequestFor(registeredService);
    val adaptor = SamlRegisteredServiceServiceProviderMetadataFacade.get(samlRegisteredServiceCachingMetadataResolver, registeredService, authnRequest).get();
    val encoder = new SamlResponseArtifactEncoder(velocityEngine, adaptor, request, response, samlArtifactMap);
    assertEquals(SAMLConstants.SAML2_ARTIFACT_BINDING_URI, encoder.getBinding());
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
    request.setCookies(response.getCookies());
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, new MockHttpServletResponse()));
    val issuer = mock(Issuer.class);
    when(issuer.getValue()).thenReturn("cas");
    val samlResponse = mock(Response.class);
    when(samlResponse.getIssuer()).thenReturn(issuer);
    assertNotNull(encoder.encode(authnRequest, samlResponse, "relay-state", new MessageContext()));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) MessageContext(org.opensaml.messaging.context.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 38 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class SamlProfileSaml2ResponseBuilderTests method verifySamlResponseWithAttributeQuery.

@Test
public void verifySamlResponseWithAttributeQuery() throws Exception {
    val request = buildHttpRequest();
    val response = new MockHttpServletResponse();
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketRegistry.addTicket(tgt);
    val webContext = new JEEContext(request, response);
    samlIdPDistributedSessionStore.set(webContext, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, tgt.getId());
    val service = getSamlRegisteredServiceForTestShib(true, true);
    service.setIssuerEntityId("https://issuer.example.org");
    service.getAttributeValueTypes().put("permissions", XSObject.class.getSimpleName());
    val adaptor = SamlRegisteredServiceServiceProviderMetadataFacade.get(samlRegisteredServiceCachingMetadataResolver, service, service.getServiceId()).get();
    val authnRequest = getAuthnRequestFor(service);
    val assertion = getAssertion();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, response));
    val samlResponse = buildResponse(request, response, service, adaptor, authnRequest, assertion, SAMLConstants.SAML2_ARTIFACT_BINDING_URI);
    assertNotNull(samlResponse);
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) JEEContext(org.pac4j.core.context.JEEContext) XSObject(org.apache.xerces.xs.XSObject) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 39 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class SamlProfileSaml2ResponseBuilderTests method buildHttpRequest.

private MockHttpServletRequest buildHttpRequest() throws Exception {
    val request = new MockHttpServletRequest();
    val tgt = new MockTicketGrantingTicket("casuser");
    request.addHeader(casProperties.getTgc().getName(), tgt.getId());
    ticketRegistry.addTicket(tgt);
    return request;
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest)

Example 40 with MockTicketGrantingTicket

use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.

the class ConfirmLogoutActionTests method verifyLocateByContext.

@Test
public void verifyLocateByContext() throws Exception {
    val context = new MockRequestContext();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
    val ticket = new MockTicketGrantingTicket("casuser");
    getCentralAuthenticationService().addTicket(ticket);
    WebUtils.putTicketGrantingTicketInScopes(context, ticket);
    val result = action.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, result.getId());
    assertNotNull(WebUtils.getAuthentication(context));
    assertNotNull(WebUtils.getTicketGrantingTicket(context));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)224 lombok.val (lombok.val)199 Test (org.junit.jupiter.api.Test)164 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)93 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)92 MockRequestContext (org.springframework.webflow.test.MockRequestContext)42 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)39 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)36 JEEContext (org.pac4j.core.context.JEEContext)33 MockServletContext (org.springframework.mock.web.MockServletContext)33 HashMap (java.util.HashMap)31 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)18 Test (org.junit.Test)18 WebApplicationServiceFactory (org.apereo.cas.authentication.principal.WebApplicationServiceFactory)13 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)12 CasProfile (org.pac4j.cas.profile.CasProfile)11 Authentication (org.apereo.cas.authentication.Authentication)10 HardTimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy)10 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)10 RedirectView (org.springframework.web.servlet.view.RedirectView)10