use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAccountCheckRegistrationActionTests method verifyExistingAccount.
@Test
public void verifyExistingAccount() {
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.get(anyString())).thenReturn((Collection) List.of(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_SUCCESS, action.doExecute(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAccountCreateRegistrationActionTests 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 OneTimeTokenAccountCreateRegistrationAction(repository, "CAS", "CAS");
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());
assertTrue(context.getFlowScope().contains(OneTimeTokenAccountCreateRegistrationAction.FLOW_SCOPE_ATTR_ACCOUNT));
assertTrue(context.getFlowScope().contains(OneTimeTokenAccountCreateRegistrationAction.FLOW_SCOPE_ATTR_QR_IMAGE_BASE64));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAccountSaveRegistrationActionTests method verifyMissingAccount.
@Test
public void verifyMissingAccount() {
val props = new CasConfigurationProperties();
val repository = mock(OneTimeTokenCredentialRepository.class);
val action = new OneTimeTokenAccountSaveRegistrationAction(repository, props);
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());
assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, action.doExecute(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DefaultLogoutRedirectionStrategyTests method getMockRequestContext.
private static MockRequestContext getMockRequestContext(final MockHttpServletRequest request) {
val context = new MockRequestContext();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
request.setRequestURI(CasProtocolConstants.ENDPOINT_LOGOUT);
return context;
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class DefaultCaptchaActivationStrategyTests method getRequestContext.
private static MockRequestContext getRequestContext(final HttpServletRequest request) {
val context = new MockRequestContext();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
return context;
}
Aggregations