Search in sources :

Example 31 with RegistrationExtensionClientOutput

use of com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput in project webauthn4j by webauthn4j.

the class RegistrationObjectTest method getter_test.

@Test
void getter_test() {
    CollectedClientData clientData = TestDataUtil.createClientData(ClientDataType.WEBAUTHN_CREATE);
    byte[] clientDataBytes = new CollectedClientDataConverter(objectConverter).convertToBytes(clientData);
    AttestationObject attestationObject = TestDataUtil.createAttestationObjectWithFIDOU2FAttestationStatement();
    byte[] attestationObjectBytes = new AttestationObjectConverter(objectConverter).convertToBytes(attestationObject);
    AuthenticatorData<RegistrationExtensionAuthenticatorOutput> authenticatorData = TestDataUtil.createAuthenticatorData();
    byte[] authenticatorDataBytes = new AuthenticatorDataConverter(objectConverter).convert(authenticatorData);
    Set<AuthenticatorTransport> transports = Collections.emptySet();
    AuthenticationExtensionsClientOutputs<RegistrationExtensionClientOutput> clientExtensions = new AuthenticationExtensionsClientOutputs<>();
    ServerProperty serverProperty = TestDataUtil.createServerProperty();
    Instant timestamp = Instant.now();
    RegistrationObject registrationObject = new RegistrationObject(attestationObject, attestationObjectBytes, clientData, clientDataBytes, clientExtensions, transports, serverProperty, timestamp);
    assertAll(() -> assertThat(registrationObject.getCollectedClientData()).isEqualTo(clientData), () -> assertThat(registrationObject.getCollectedClientDataBytes()).isEqualTo(clientDataBytes), () -> assertThat(registrationObject.getAttestationObject()).isEqualTo(attestationObject), () -> assertThat(registrationObject.getAttestationObjectBytes()).isEqualTo(attestationObjectBytes), () -> assertThat(registrationObject.getAuthenticatorDataBytes()).isEqualTo(authenticatorDataBytes), () -> assertThat(registrationObject.getTransports()).isEqualTo(transports), () -> assertThat(registrationObject.getClientExtensions()).isEqualTo(clientExtensions), () -> assertThat(registrationObject.getServerProperty()).isEqualTo(serverProperty), () -> assertThat(registrationObject.getTimestamp()).isEqualTo(timestamp));
}
Also used : AttestationObjectConverter(com.webauthn4j.converter.AttestationObjectConverter) AuthenticatorDataConverter(com.webauthn4j.converter.AuthenticatorDataConverter) ServerProperty(com.webauthn4j.server.ServerProperty) Instant(java.time.Instant) RegistrationExtensionAuthenticatorOutput(com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput) CollectedClientDataConverter(com.webauthn4j.converter.CollectedClientDataConverter) RegistrationExtensionClientOutput(com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AttestationObject(com.webauthn4j.data.attestation.AttestationObject) AuthenticationExtensionsClientOutputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs) AuthenticatorTransport(com.webauthn4j.data.AuthenticatorTransport) Test(org.junit.jupiter.api.Test)

Example 32 with RegistrationExtensionClientOutput

use of com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput in project webauthn4j-spring-security by webauthn4j.

the class WebAuthnRegistrationRequestValidationResponseTest method equals_hashCode_test.

@Test
public void equals_hashCode_test() {
    CollectedClientData clientData = TestDataUtil.createClientData(ClientDataType.WEBAUTHN_CREATE);
    AttestationObject attestationObject = TestDataUtil.createAttestationObjectWithFIDOU2FAttestationStatement();
    AuthenticationExtensionsClientOutputs<RegistrationExtensionClientOutput> clientExtensions = new AuthenticationExtensionsClientOutputs<>();
    Set<AuthenticatorTransport> transports = new HashSet<>();
    WebAuthnRegistrationRequestValidationResponse instanceA = new WebAuthnRegistrationRequestValidationResponse(clientData, attestationObject, clientExtensions, transports);
    WebAuthnRegistrationRequestValidationResponse instanceB = new WebAuthnRegistrationRequestValidationResponse(clientData, attestationObject, clientExtensions, transports);
    assertThat(instanceA).isEqualTo(instanceB);
    assertThat(instanceB).hasSameHashCodeAs(instanceB);
}
Also used : CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AttestationObject(com.webauthn4j.data.attestation.AttestationObject) AuthenticationExtensionsClientOutputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs) RegistrationExtensionClientOutput(com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput) AuthenticatorTransport(com.webauthn4j.data.AuthenticatorTransport) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 33 with RegistrationExtensionClientOutput

use of com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput in project webauthn4j-spring-security by webauthn4j.

the class WebAuthnRegistrationRequestValidatorTest method validate_with_transports_null_test.

@Test
public void validate_with_transports_null_test() {
    WebAuthnRegistrationRequestValidator target = new WebAuthnRegistrationRequestValidator(webAuthnManager, serverPropertyProvider);
    ServerProperty serverProperty = mock(ServerProperty.class);
    when(serverPropertyProvider.provide(any())).thenReturn(serverProperty);
    CollectedClientData collectedClientData = mock(CollectedClientData.class);
    AttestationObject attestationObject = mock(AttestationObject.class);
    AuthenticationExtensionsClientOutputs<RegistrationExtensionClientOutput> clientExtensionOutputs = new AuthenticationExtensionsClientOutputs<>();
    when(webAuthnManager.validate(any(RegistrationRequest.class), any(RegistrationParameters.class))).thenReturn(new RegistrationData(attestationObject, null, collectedClientData, null, clientExtensionOutputs, null));
    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
    mockHttpServletRequest.setScheme("https");
    mockHttpServletRequest.setServerName("example.com");
    mockHttpServletRequest.setServerPort(443);
    String clientDataBase64 = "clientDataBase64";
    String attestationObjectBase64 = "attestationObjectBase64";
    String clientExtensionsJSON = "clientExtensionsJSON";
    target.validate(mockHttpServletRequest, clientDataBase64, attestationObjectBase64, null, clientExtensionsJSON);
    ArgumentCaptor<RegistrationRequest> registrationRequestArgumentCaptor = ArgumentCaptor.forClass(RegistrationRequest.class);
    ArgumentCaptor<RegistrationParameters> registrationParametersArgumentCaptor = ArgumentCaptor.forClass(RegistrationParameters.class);
    verify(webAuthnManager).validate(registrationRequestArgumentCaptor.capture(), registrationParametersArgumentCaptor.capture());
    RegistrationRequest registrationRequest = registrationRequestArgumentCaptor.getValue();
    RegistrationParameters registrationParameters = registrationParametersArgumentCaptor.getValue();
    assertThat(registrationRequest.getClientDataJSON()).isEqualTo(Base64UrlUtil.decode(clientDataBase64));
    assertThat(registrationRequest.getAttestationObject()).isEqualTo(Base64UrlUtil.decode(attestationObjectBase64));
    assertThat(registrationRequest.getClientExtensionsJSON()).isEqualTo(clientExtensionsJSON);
    assertThat(registrationParameters.getServerProperty()).isEqualTo(serverProperty);
}
Also used : RegistrationData(com.webauthn4j.data.RegistrationData) ServerProperty(com.webauthn4j.server.ServerProperty) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RegistrationExtensionClientOutput(com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput) RegistrationRequest(com.webauthn4j.data.RegistrationRequest) CollectedClientData(com.webauthn4j.data.client.CollectedClientData) AttestationObject(com.webauthn4j.data.attestation.AttestationObject) AuthenticationExtensionsClientOutputs(com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs) RegistrationParameters(com.webauthn4j.data.RegistrationParameters) Test(org.junit.Test)

Aggregations

RegistrationExtensionClientOutput (com.webauthn4j.data.extension.client.RegistrationExtensionClientOutput)33 AttestationObject (com.webauthn4j.data.attestation.AttestationObject)20 CollectedClientData (com.webauthn4j.data.client.CollectedClientData)19 Test (org.junit.jupiter.api.Test)18 ServerProperty (com.webauthn4j.server.ServerProperty)17 AuthenticationExtensionsClientOutputs (com.webauthn4j.data.extension.client.AuthenticationExtensionsClientOutputs)16 Challenge (com.webauthn4j.data.client.challenge.Challenge)13 DefaultChallenge (com.webauthn4j.data.client.challenge.DefaultChallenge)13 AuthenticationExtensionsClientInputs (com.webauthn4j.data.extension.client.AuthenticationExtensionsClientInputs)10 RegistrationExtensionClientInput (com.webauthn4j.data.extension.client.RegistrationExtensionClientInput)10 AuthenticatorTransport (com.webauthn4j.data.AuthenticatorTransport)9 RegistrationObject (com.webauthn4j.validator.RegistrationObject)9 CoreRegistrationObject (com.webauthn4j.validator.CoreRegistrationObject)8 DCRegistrationObject (com.webauthn4j.appattest.validator.DCRegistrationObject)7 RegistrationData (com.webauthn4j.data.RegistrationData)4 Instant (java.time.Instant)4 Test (org.junit.Test)4 AttestationObjectConverter (com.webauthn4j.converter.AttestationObjectConverter)3 CollectedClientDataConverter (com.webauthn4j.converter.CollectedClientDataConverter)3 RegistrationExtensionAuthenticatorOutput (com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput)3