use of com.yubico.data.AssertionRequestWrapper in project cas by apereo.
the class WebAuthnControllerTests method verifyStartAuthentication.
@Test
public void verifyStartAuthentication() throws Exception {
val server = mock(WebAuthnServer.class);
val controller = new WebAuthnController(server);
when(server.startAuthentication(any())).thenReturn(Either.left(List.of("failed")));
var result = controller.startAuthentication("casuser");
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
val publicKeyRequest = PublicKeyCredentialRequestOptions.builder().challenge(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8))).rpId("localhost").timeout(100).build();
val assertionRequest = AssertionRequest.builder().publicKeyCredentialRequestOptions(publicKeyRequest).username("casuser").build();
val assertion = new AssertionRequestWrapper(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8)), assertionRequest);
when(server.startAuthentication(any())).thenReturn(Either.right(assertion));
result = controller.startAuthentication("casuser");
assertEquals(HttpStatus.OK, result.getStatusCode());
}
use of com.yubico.data.AssertionRequestWrapper in project cas by apereo.
the class WebAuthnControllerTests method verifyFinishAuthentication.
@Test
public void verifyFinishAuthentication() throws Exception {
val authn = RegisteredServiceTestUtils.getAuthentication();
val server = mock(WebAuthnServer.class);
val controller = new WebAuthnController(server);
when(server.finishAuthentication(any())).thenReturn(Either.left(List.of("fails")));
var result = controller.finishAuthentication("casuser");
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
val registration = CredentialRegistration.builder().registrationTime(Instant.now(Clock.systemUTC())).credential(RegisteredCredential.builder().credentialId(ByteArray.fromBase64Url(authn.getPrincipal().getId())).userHandle(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8))).publicKeyCose(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8))).build()).userIdentity(UserIdentity.builder().name("casuser").displayName("CAS").id(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8))).build()).build();
val publicKeyRequest = PublicKeyCredentialRequestOptions.builder().challenge(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8))).rpId("localhost").timeout(100).build();
val assertionRequest = AssertionRequest.builder().publicKeyCredentialRequestOptions(publicKeyRequest).username("casuser").build();
val assertion = new AssertionRequestWrapper(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8)), assertionRequest);
val assertionJson = "{\"id\":\"ibE9wQddsF806g8uL9hDzgwLJipKhS9esD07Jmj0N98\"," + "\"response\":{\"authenticatorData\":\"SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MBAAAFOQ\"," + "\"clientDataJSON\":\"eyJjaGFsbGVuZ2UiOiJOM0xqSTJKNXlseVdlM0VENU9UNFhITFJxSHdtX0o0OF9EX2hvSk9GZjMwIiwib3JpZ2" + "luIjoiaHR0cHM6Ly9sb2NhbGhvc3QiLCJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwidG9rZW5CaW5kaW5nIjp7InN0YXR1cyI6InN1cHBvcnRlZCJ9LCJjbGllbnRFeHRlbnNpb25zIjp7fX0\"," + "\"signature\":\"-8AKZkFZSNUemUihJhsUp8LqXFHgVTjfCuKVvf1kbIkuwz5ClZK2u562C8rkUnIorxtzD7ujYh1z4FstXKyRDg\"}," + "\"clientExtensionResults\":{},\"type\":\"public-key\"}";
val publicKeyCredential = PublicKeyCredential.parseAssertionResponseJson(assertionJson);
val response = new AssertionResponse(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8)), publicKeyCredential);
val authnResult = new WebAuthnServer.SuccessfulAuthenticationResult(assertion, response, List.of(registration), "casuser", ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8)));
when(server.finishAuthentication(any())).thenReturn(Either.right(authnResult));
result = controller.finishAuthentication("casuser");
assertEquals(HttpStatus.OK, result.getStatusCode());
}
Aggregations