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