use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class RenewAuthenticationRequestCheckActionTests method verifyRenew.
@Test
public void verifyRenew() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val strategy = new DefaultSingleSignOnParticipationStrategy(servicesManager, casProperties.getSso(), mock(TicketRegistrySupport.class), mock(AuthenticationServiceSelectionPlan.class));
val action = new RenewAuthenticationRequestCheckAction(strategy);
assertEquals(CasWebflowConstants.TRANSITION_ID_RENEW, action.execute(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class SessionStoreTicketGrantingTicketActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putTicketGrantingTicketInScopes(context, new MockTicketGrantingTicket("casuser"));
val action = new SessionStoreTicketGrantingTicketAction(JEESessionStore.INSTANCE);
val result = action.execute(context);
assertNull(result);
val webContext = new JEEContext(request, response);
assertTrue(JEESessionStore.INSTANCE.get(webContext, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID).isPresent());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DelegatedAuthenticationClientFinishLogoutActionTests method verifyOperationFailsWithError.
@Test
public void verifyOperationFailsWithError() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "SAML2Client");
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val samlClient = (SAML2Client) builtClients.findClient("SAML2Client").get();
val handler = mock(SAML2ProfileHandler.class);
when(handler.receive(any())).thenThrow(new FoundAction("https://google.com"));
samlClient.setLogoutProfileHandler(handler);
val result = delegatedAuthenticationClientFinishLogoutAction.execute(context);
assertNull(result);
assertEquals(HttpStatus.FOUND.value(), response.getStatus());
assertEquals("https://google.com", response.getHeader("Location"));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DelegatedAuthenticationClientFinishLogoutActionTests method verifyOperationWithRedirect.
@Test
public void verifyOperationWithRedirect() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putDelegatedAuthenticationClientName(context, "SAML2Client");
WebUtils.putLogoutRedirectUrl(context, "https://google.com");
val result = delegatedAuthenticationClientFinishLogoutAction.execute(context);
assertNull(result);
val samlClient = (SAML2Client) builtClients.findClient("SAML2Client").get();
assertEquals("https://google.com", samlClient.getLogoutValidator().getPostLogoutURL());
assertNull(WebUtils.getLogoutRedirectUrl(context, String.class));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DelegatedAuthenticationClientRetryActionTests method verifyOperationWithRedirect.
@Test
public void verifyOperationWithRedirect() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putDelegatedAuthenticationClientName(context, "SAML2Client");
val result = retryAction.execute(context);
assertNull(result);
assertNotNull(response.getHeaderValue("Location"));
assertEquals(HttpStatus.FOUND.value(), response.getStatus());
}
Aggregations