Search in sources :

Example 1 with DuoSecurityCredential

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());
}
Also used : lombok.val(lombok.val) MockFlowSession(org.springframework.webflow.test.MockFlowSession) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ViewState(org.springframework.webflow.engine.ViewState) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.apereo.cas.util.MockServletContext) Flow(org.springframework.webflow.engine.Flow) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DuoSecurityCredential(org.apereo.cas.adaptors.duo.authn.DuoSecurityCredential) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)1 DuoSecurityCredential (org.apereo.cas.adaptors.duo.authn.DuoSecurityCredential)1 MockServletContext (org.apereo.cas.util.MockServletContext)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 Flow (org.springframework.webflow.engine.Flow)1 ViewState (org.springframework.webflow.engine.ViewState)1 MockFlowExecutionContext (org.springframework.webflow.test.MockFlowExecutionContext)1 MockFlowSession (org.springframework.webflow.test.MockFlowSession)1 MockRequestContext (org.springframework.webflow.test.MockRequestContext)1