Search in sources :

Example 6 with DuoSecurityUserAccount

use of org.apereo.cas.adaptors.duo.DuoSecurityUserAccount in project cas by apereo.

the class DuoSecurityUserAccountStatusEndpointTests method verifyOperation.

@Test
public void verifyOperation() {
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val account = new DuoSecurityUserAccount("casuser");
    account.setMessage("User is valid");
    account.setStatus(DuoSecurityUserAccountStatus.AUTH);
    val duoService = mock(DuoSecurityAuthenticationService.class);
    when(duoService.ping()).thenReturn(true);
    val props = new DuoSecurityMultifactorAuthenticationProperties().setDuoApiHost("https://api.duosecurity.com");
    when(duoService.getProperties()).thenReturn(props);
    when(duoService.getUserAccount(eq("casuser"))).thenReturn(account);
    val bean = mock(DuoSecurityMultifactorAuthenticationProvider.class);
    when(bean.getId()).thenReturn(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
    when(bean.getDuoAuthenticationService()).thenReturn(duoService);
    when(bean.matches(eq(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER))).thenReturn(true);
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, bean, "duoProvider");
    val indicator = new DuoSecurityUserAccountStatusEndpoint(casProperties, this.applicationContext);
    val result = indicator.fetchAccountStatus("casuser", DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
    assertNotNull(result);
    assertTrue(result.containsKey(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER));
}
Also used : lombok.val(lombok.val) DuoSecurityMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.DuoSecurityMultifactorAuthenticationProperties) DuoSecurityUserAccount(org.apereo.cas.adaptors.duo.DuoSecurityUserAccount) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)6 DuoSecurityUserAccount (org.apereo.cas.adaptors.duo.DuoSecurityUserAccount)6 Operation (io.swagger.v3.oas.annotations.Operation)2 Parameter (io.swagger.v3.oas.annotations.Parameter)2 ParameterIn (io.swagger.v3.oas.annotations.enums.ParameterIn)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 StringUtils (org.apache.commons.lang3.StringUtils)2 DuoSecurityMultifactorAuthenticationProvider (org.apereo.cas.adaptors.duo.authn.DuoSecurityMultifactorAuthenticationProvider)2 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)2 BaseCasActuatorEndpoint (org.apereo.cas.web.BaseCasActuatorEndpoint)2 Unchecked (org.jooq.lambda.Unchecked)2 RestControllerEndpoint (org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint)2 ApplicationContext (org.springframework.context.ApplicationContext)2 MediaType (org.springframework.http.MediaType)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 PathVariable (org.springframework.web.bind.annotation.PathVariable)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2