use of test.TestUserDetailsImpl in project webauthn4j-spring-security by webauthn4j.
the class WebAuthnAuthenticationProviderTest method authenticate_test.
/**
* Verifies that authentication process passes successfully if input is correct.
*/
@Test
public void authenticate_test() {
// Given
byte[] credentialId = new byte[32];
GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ROLE_ADMIN");
UserDetails webAuthnPrincipal = new TestUserDetailsImpl("dummy", Collections.singletonList(grantedAuthority));
WebAuthnAuthenticator webAuthnAuthenticator = mock(WebAuthnAuthenticator.class, RETURNS_DEEP_STUBS);
when(webAuthnAuthenticator.getUserPrincipal()).thenReturn(webAuthnPrincipal);
when(webAuthnAuthenticator.getAttestedCredentialData().getCredentialId()).thenReturn(credentialId);
// When
WebAuthnAuthenticationRequest request = mock(WebAuthnAuthenticationRequest.class);
WebAuthnAuthenticationParameters parameters = mock(WebAuthnAuthenticationParameters.class);
when(request.getCredentialId()).thenReturn(credentialId);
when(authenticatorService.loadAuthenticatorByCredentialId(credentialId)).thenReturn(webAuthnAuthenticator);
when(parameters.getServerProperty()).thenReturn(mock(ServerProperty.class));
Authentication token = new WebAuthnAssertionAuthenticationToken(request, parameters, null);
Authentication authenticatedToken = authenticationProvider.authenticate(token);
ArgumentCaptor<AuthenticationRequest> requestCaptor = ArgumentCaptor.forClass(AuthenticationRequest.class);
ArgumentCaptor<AuthenticationParameters> parameterCaptor = ArgumentCaptor.forClass(AuthenticationParameters.class);
verify(webAuthnManager).validate(requestCaptor.capture(), parameterCaptor.capture());
assertThat(authenticatedToken.getPrincipal()).isEqualTo(webAuthnPrincipal);
assertThat(authenticatedToken.getCredentials()).isEqualTo(request);
assertThat(authenticatedToken.getAuthorities().toArray()).containsExactly(grantedAuthority);
}
use of test.TestUserDetailsImpl in project webauthn4j-spring-security by webauthn4j.
the class WebAuthnAuthenticationTokenTest method getter_methods.
@Test
public void getter_methods() {
WebAuthnAuthenticationRequest credential = mock(WebAuthnAuthenticationRequest.class);
UserDetails principal = new TestUserDetailsImpl("username");
WebAuthnAuthenticationToken webAuthnAuthenticationToken = new WebAuthnAuthenticationToken(principal, credential, null);
assertThat(webAuthnAuthenticationToken.getPrincipal()).isEqualTo(principal);
Assertions.assertThat(webAuthnAuthenticationToken.getCredentials()).isEqualTo(credential);
}
use of test.TestUserDetailsImpl in project webauthn4j-spring-security by webauthn4j.
the class WebAuthnAuthenticationTokenTest method equals_hashCode_test.
@Test
public void equals_hashCode_test() {
WebAuthnAuthenticationRequest credential = mock(WebAuthnAuthenticationRequest.class);
WebAuthnAuthenticationToken tokenA = new WebAuthnAuthenticationToken(new TestUserDetailsImpl("username"), credential, null);
WebAuthnAuthenticationToken tokenB = new WebAuthnAuthenticationToken(new TestUserDetailsImpl("username"), credential, null);
assertThat(tokenA).isEqualTo(tokenB).hasSameHashCodeAs(tokenB);
}
Aggregations