use of com.duosecurity.model.Token in project cas by apereo.
the class UniversalPromptDuoSecurityAuthenticationServiceTests method verifyAuth.
@Test
public void verifyAuth() throws Exception {
val state = UUID.randomUUID().toString();
val credential = new DuoSecurityUniversalPromptCredential(state, RegisteredServiceTestUtils.getAuthentication("casuser"));
val duoClient = mock(Client.class);
val token = new Token();
token.setAud("aud");
token.setIat(123456D);
token.setExp(123456);
token.setAuth_time(123456789);
token.setIss("issuer");
token.setSub("casuser");
token.setPreferred_username("CAS");
val authContext = new AuthContext();
val accessDevice = new AccessDevice();
accessDevice.setLocation(new Location());
accessDevice.setHostname("hostname");
authContext.setAccess_device(accessDevice);
val authDevice = new AuthDevice();
authDevice.setLocation(new Location());
authContext.setAuth_device(authDevice);
authContext.setUser(new User());
authContext.setApplication(new Application());
token.setAuth_context(authContext);
token.setAuth_result(new AuthResult());
when(duoClient.exchangeAuthorizationCodeFor2FAResult(anyString(), anyString())).thenReturn(token);
val duoProperties = new DuoSecurityMultifactorAuthenticationProperties();
val service = new UniversalPromptDuoSecurityAuthenticationService(duoProperties, mock(HttpClient.class), duoClient, List.of(MultifactorAuthenticationPrincipalResolver.identical()), Caffeine.newBuilder().build());
val result = service.authenticate(credential);
assertNotNull(result);
assertTrue(result.isSuccess());
assertEquals("CAS", result.getUsername());
assertNotNull(result.getAttributes());
}
Aggregations