use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class CasConfigurationServerServletInitializerTests method verifyInitializer.
@Test
public void verifyInitializer() {
val servletContext = new MockServletContext();
val servletInitializer = new CasConfigurationServerServletInitializer();
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
servletInitializer.onStartup(servletContext);
}
});
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class CasWebApplicationServletInitializerTests method verifyInitializr.
@Test
public void verifyInitializr() {
val servletInitializer = new CasWebApplicationServletInitializer();
val context = new MockServletContext();
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Exception {
servletInitializer.onStartup(context);
}
});
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class U2FStartAuthenticationActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val id = UUID.randomUUID().toString();
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(id), context);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, u2fMultifactorAuthenticationProvider);
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val cert = CertUtils.readCertificate(new ClassPathResource("cert.crt"));
val reg1 = new DeviceRegistration("keyhandle11", "publickey1", cert, 1);
val record = U2FDeviceRegistration.builder().record(deviceRepository.getCipherExecutor().encode(reg1.toJsonWithAttestationCert())).username(id).build();
deviceRepository.registerDevice(record);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, u2fStartAuthenticationAction.execute(context).getId());
assertNotNull(context.getFlowScope().get("u2fAuth"));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DuoSecurityDetermineUserAccountActionTests method verifyOperation.
@SneakyThrows
private static void verifyOperation(final DuoSecurityUserAccountStatus status, final String eventId) {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
val authentication = CoreAuthenticationTestUtils.getAuthentication();
WebUtils.putAuthentication(authentication, context);
val account = new DuoSecurityUserAccount(authentication.getPrincipal().getId());
account.setStatus(status);
account.setEnrollPortalUrl("https://example.org");
val duoService = mock(DuoSecurityAuthenticationService.class);
when(duoService.getUserAccount(anyString())).thenReturn(account);
val provider = mock(DuoSecurityMultifactorAuthenticationProvider.class);
when(provider.getId()).thenReturn(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
when(provider.getDuoAuthenticationService()).thenReturn(duoService);
when(provider.getRegistrationUrl()).thenReturn("https://registration.duo.com");
when(provider.matches(anyString())).thenReturn(Boolean.TRUE);
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, provider);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider);
val action = new DuoSecurityDetermineUserAccountAction();
val event = action.execute(context);
assertEquals(eventId, event.getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAccountCheckRegistrationActionTests method verifyCreateAccount.
@Test
public void verifyCreateAccount() {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val account = OneTimeTokenAccount.builder().username("casuser").secretKey(UUID.randomUUID().toString()).validationCode(123456).scratchCodes(List.of()).name(UUID.randomUUID().toString()).build();
val repository = mock(OneTimeTokenCredentialRepository.class);
when(repository.create(anyString())).thenReturn(account);
val action = new OneTimeTokenAccountCheckRegistrationAction(repository);
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.putAuthentication(RegisteredServiceTestUtils.getAuthentication("casuser"), context);
assertEquals(CasWebflowConstants.TRANSITION_ID_REGISTER, action.doExecute(context).getId());
}
Aggregations