use of org.apereo.cas.adaptors.duo.authn.DuoSecurityCredential 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());
}
Aggregations