use of org.springframework.webflow.test.MockFlowSession in project cas by apereo.
the class AcceptPasswordlessAuthenticationActionTests method verifyMissingTokenAction.
@Test
public void verifyMissingTokenAction() throws Exception {
val exec = new MockFlowExecutionContext(new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN)));
val context = new MockRequestContext(exec);
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
val account = PasswordlessUserAccount.builder().email("email").phone("phone").username("casuser").name("casuser").build();
WebUtils.putPasswordlessAuthenticationAccount(context, account);
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, acceptPasswordlessAuthenticationAction.execute(context).getId());
}
use of org.springframework.webflow.test.MockFlowSession in project cas by apereo.
the class WebUtilsTests method verifyOperation.
@Test
public void verifyOperation() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val flow = new Flow("mockFlow");
val flowSession = new MockFlowSession(flow);
flowSession.setParent(new MockFlowSession(flow));
val mockExecutionContext = new MockFlowExecutionContext(flowSession);
context.setFlowExecutionContext(mockExecutionContext);
WebUtils.putLogoutRedirectUrl(context, URL);
assertNotNull(WebUtils.getLogoutRedirectUrl(context, String.class));
WebUtils.removeLogoutRedirectUrl(context);
assertNull(WebUtils.getLogoutRedirectUrl(context, String.class));
assertNull(WebUtils.getHttpServletRequestUserAgentFromRequestContext(context));
assertNull(WebUtils.getHttpServletRequestUserAgentFromRequestContext(request));
assertNull(WebUtils.getAuthenticationResult(context));
assertNull(WebUtils.getHttpServletRequestGeoLocationFromRequestContext());
assertNull(WebUtils.getAcceptableUsagePolicyTermsFromFlowScope(context, Object.class));
assertFalse(WebUtils.hasSurrogateAuthenticationRequest(context));
assertNotNull(WebUtils.produceUnauthorizedErrorView(new RuntimeException()));
assertNotNull(WebUtils.produceErrorView(new IllegalArgumentException()));
assertNotNull(WebUtils.produceErrorView("error-view", new IllegalArgumentException()));
assertNotNull(WebUtils.getHttpRequestFullUrl(context));
request.setQueryString("param=value");
assertNotNull(WebUtils.getHttpRequestFullUrl(request));
assertFalse(WebUtils.isGraphicalUserAuthenticationEnabled(context));
assertTrue(WebUtils.getDelegatedAuthenticationProviderConfigurations(context).isEmpty());
assertNull(WebUtils.getAvailableAuthenticationHandleNames(context));
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
WebUtils.putYubiKeyMultipleDeviceRegistrationEnabled(context, true);
WebUtils.putInitialHttpRequestPostParameters(context);
WebUtils.putExistingSingleSignOnSessionAvailable(context, true);
WebUtils.putExistingSingleSignOnSessionPrincipal(context, CoreAuthenticationTestUtils.getPrincipal());
WebUtils.putAvailableAuthenticationHandleNames(context, List.of());
WebUtils.putPasswordManagementEnabled(context, true);
WebUtils.putRecaptchaPropertiesFlowScope(context, new GoogleRecaptchaProperties().setEnabled(true));
WebUtils.putLogoutUrls(context, Map.of());
val ac = OneTimeTokenAccount.builder().validationCode(123456).username("casuser").name("Example").build();
WebUtils.putOneTimeTokenAccount(context, ac);
assertNotNull(WebUtils.getOneTimeTokenAccount(context, OneTimeTokenAccount.class));
WebUtils.putOneTimeTokenAccounts(context, List.of(ac));
WebUtils.putWarnCookieIfRequestParameterPresent(null, context);
WebUtils.putTicketGrantingTicketInScopes(context, "ticket-id");
}
});
WebUtils.putCredential(context, new UsernamePasswordCredential("casuser", "password"));
assertThrows(ClassCastException.class, () -> WebUtils.getCredential(context, OneTimeTokenCredential.class));
WebUtils.putTicketGrantingTicketInScopes(context, StringUtils.EMPTY);
WebUtils.putTicketGrantingTicketInScopes(context, (TicketGrantingTicket) null);
WebUtils.putTicketGrantingTicketInScopes(context, (String) null);
assertNull(WebUtils.getTicketGrantingTicket(context));
assertThrows(IllegalArgumentException.class, () -> WebUtils.getPrincipalFromRequestContext(context, null));
request.addParameter(WebUtils.PUBLIC_WORKSTATION_ATTRIBUTE, "true");
WebUtils.putPublicWorkstationToFlowIfRequestParameterPresent(context);
assertTrue(WebUtils.isAuthenticatingAtPublicWorkstation(context));
val ticketRegistrySupport = mock(TicketRegistrySupport.class);
WebUtils.putTicketGrantingTicketInScopes(context, "TGT-XYZ123");
assertNull(WebUtils.getPrincipalFromRequestContext(context, ticketRegistrySupport));
WebUtils.putLogoutPostUrl(context, URL);
assertEquals(URL, WebUtils.getLogoutPostUrl(context));
val data = new HashMap<String, Object>();
data.put("SAMLResponse", "xxx");
WebUtils.putLogoutPostData(context, data);
assertEquals(data, WebUtils.getLogoutPostData(context));
}
use of org.springframework.webflow.test.MockFlowSession in project cas by apereo.
the class PrepareMultifactorProviderSelectionActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val flowSession = new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN));
flowSession.setState(new ViewState(flowSession.getDefinitionInternal(), "viewState", mock(ViewFactory.class)));
val exec = new MockFlowExecutionContext(flowSession);
val context = new MockRequestContext(exec);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val chain = new DefaultChainingMultifactorAuthenticationProvider(new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties));
val provider = new TestMultifactorAuthenticationProvider();
provider.setBypassEvaluator(new DefaultChainingMultifactorAuthenticationBypassProvider());
chain.addMultifactorAuthenticationProvider(provider);
val attributes = new LocalAttributeMap(RegisteredService.class.getName(), RegisteredServiceTestUtils.getRegisteredService());
attributes.put(MultifactorAuthenticationProvider.class.getName(), chain);
val event = new EventFactorySupport().event(this, ChainingMultifactorAuthenticationProvider.DEFAULT_IDENTIFIER, attributes);
context.setCurrentEvent(event);
assertNull(action.execute(context));
assertNotNull(WebUtils.getSelectableMultifactorAuthenticationProviders(context));
}
use of org.springframework.webflow.test.MockFlowSession in project cas by apereo.
the class DuoSecurityPrepareWebLoginFormActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val applicationContext = new StaticApplicationContext();
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
val flowSession = new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN));
flowSession.setState(new ViewState(flowSession.getDefinitionInternal(), "viewState", mock(ViewFactory.class)));
val exec = new MockFlowExecutionContext(flowSession);
val context = new MockRequestContext(exec);
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 duoService = mock(DuoSecurityAuthenticationService.class);
when(duoService.getProperties()).thenReturn(casProperties.getAuthn().getMfa().getDuo().get(0));
val provider = mock(DuoSecurityMultifactorAuthenticationProvider.class);
when(provider.getId()).thenReturn(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
when(provider.getDuoAuthenticationService()).thenReturn(duoService);
when(provider.matches(anyString())).thenReturn(Boolean.TRUE);
WebUtils.putCredential(context, new DuoSecurityCredential(authentication.getPrincipal().getId(), UUID.randomUUID().toString(), provider.getId()));
WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, provider);
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider);
val action = new DuoSecurityPrepareWebLoginFormAction();
val event = action.execute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, event.getId());
}
use of org.springframework.webflow.test.MockFlowSession in project cas by apereo.
the class RadiusAuthenticationWebflowEventResolverFailureTests method initialize.
@BeforeEach
public void initialize() {
this.context = mock(RequestContext.class);
when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
when(context.getRequestParameters()).thenReturn(new MockParameterMap());
when(context.getRequestParameters()).thenReturn(new MockParameterMap());
val request = new MockHttpServletRequest();
when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
when(context.getFlowExecutionContext()).thenReturn(new MockFlowExecutionContext(new MockFlowSession(new Flow("mockFlow"))));
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
val authentication = CoreAuthenticationTestUtils.getAuthentication();
WebUtils.putAuthentication(authentication, context);
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(authentication));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
}
Aggregations