use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DelegatedClientAuthenticationActionTests method verifyServerSideRedirectAuthentication.
@Test
public void verifyServerSideRedirectAuthentication() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val service = CoreAuthenticationTestUtils.getService("https://delegated2.example.org");
servicesManager.save(RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of()));
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
setRequestContext(context);
setExternalContext(context.getExternalContext());
assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, delegatedAuthenticationAction.execute(context).getId());
assertEquals(HttpStatus.FOUND.value(), response.getStatus());
assertEquals(DelegatedClientIdentityProviderConfigurationFactory.ENDPOINT_URL_REDIRECT + "?client_name=CasClient", response.getHeader("Location"));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DelegatedClientIdentityProviderConfigurationProducerTests method verifyOperationAutoRedirect.
@Test
public void verifyOperationAutoRedirect() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val accessStrategy = new DefaultRegisteredServiceAccessStrategy();
accessStrategy.setDelegatedAuthenticationPolicy(new DefaultRegisteredServiceDelegatedAuthenticationPolicy(List.of("SAML2Client"), false, false));
val registeredService = RegisteredServiceTestUtils.getRegisteredService("https://delegated2.example.org");
registeredService.setAccessStrategy(accessStrategy);
servicesManager.save(registeredService);
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService("https://delegated2.example.org"));
assertNotNull(producer.produce(context));
assertNotNull(WebUtils.getDelegatedAuthenticationProviderConfigurations(context));
assertNotNull(WebUtils.getDelegatedAuthenticationProviderPrimary(context));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DelegatedClientIdentityProviderConfigurationProducerTests method verifyOperationPrimaryProvider.
@Test
public void verifyOperationPrimaryProvider() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val accessStrategy = new DefaultRegisteredServiceAccessStrategy();
accessStrategy.setDelegatedAuthenticationPolicy(new DefaultRegisteredServiceDelegatedAuthenticationPolicy(List.of("CasClient"), false, true));
val registeredService = RegisteredServiceTestUtils.getRegisteredService("https://delegated.example.org");
registeredService.setAccessStrategy(accessStrategy);
servicesManager.save(registeredService);
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService("https://delegated.example.org"));
assertNotNull(producer.produce(context));
assertNotNull(WebUtils.getDelegatedAuthenticationProviderConfigurations(context));
assertNotNull(WebUtils.getDelegatedAuthenticationProviderPrimary(context));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DelegatedClientAuthenticationDynamicDiscoveryExecutionActionTests method verifyOperationWithClient.
@Test
public void verifyOperationWithClient() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter("username", "cas@example.org");
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val result = delegatedAuthenticationDiscoveryAction.execute(context);
assertNotNull(result);
assertEquals(CasWebflowConstants.TRANSITION_ID_REDIRECT, result.getId());
assertTrue(context.getRequestScope().contains(DelegatedClientAuthenticationDynamicDiscoveryExecutionAction.REQUEST_SCOPE_ATTR_PROVIDER_REDIRECT_URL, String.class));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class CasEurekaServerServletInitializerTests method verifyInitializer.
@Test
public void verifyInitializer() {
val servletContext = new MockServletContext();
val servletInitializer = new CasEurekaServerServletInitializer();
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
servletInitializer.onStartup(servletContext);
}
});
}
Aggregations