use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class RemoveGoogleAnalyticsCookieActionTests 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());
assertNull(removeGoogleAnalyticsCookieAction.execute(context));
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAuthenticationWebflowActionTests method verifyAction.
@Test
public void verifyAction() {
val resolver = mock(CasWebflowEventResolver.class);
when(resolver.resolveSingle(any())).thenReturn(new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_SUCCESS));
val action = new OneTimeTokenAuthenticationWebflowAction(resolver);
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_SUCCESS, action.doExecute(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAccountSaveRegistrationActionTests method verifyCreateAccount.
@Test
public void verifyCreateAccount() {
val props = new CasConfigurationProperties();
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);
val action = new OneTimeTokenAccountSaveRegistrationAction(repository, props);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter(OneTimeTokenAccountSaveRegistrationAction.REQUEST_PARAMETER_ACCOUNT_NAME, "ExampleAccount");
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);
context.getFlowScope().put(OneTimeTokenAccountCreateRegistrationAction.FLOW_SCOPE_ATTR_ACCOUNT, account);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.doExecute(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAuthenticationWebflowEventResolverTests method verifyResolver.
@Test
public void verifyResolver() {
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());
val authn = RegisteredServiceTestUtils.getAuthentication("casuser");
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(authn));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
WebUtils.putAuthentication(authn, context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, resolver.resolveSingle(context).getId());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class OneTimeTokenAccountConfirmSelectionRegistrationActionTests method verifyOperation.
@Test
public void verifyOperation() {
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(anyLong())).thenReturn(account);
val action = new OneTimeTokenAccountConfirmSelectionRegistrationAction(repository);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter(OneTimeTokenAccountConfirmSelectionRegistrationAction.REQUEST_PARAMETER_ACCOUNT_ID, String.valueOf(account.getId()));
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.doExecute(context).getId());
}
Aggregations