3939import static org .junit .jupiter .api .Assertions .assertThrows ;
4040import static org .mockito .Mockito .mock ;
4141
42+ @ Deprecated
4243class AuthenticatorImplTest {
4344
4445 @ Test
45- void constructor_test () {
46+ void shouldCreateAuthenticatorWithCorrectAttributes () {
47+ // Given
4648 AttestedCredentialData attestedCredentialData = TestDataUtil .createAttestedCredentialData ();
4749 AttestationStatement attestationStatement = TestAttestationStatementUtil .createFIDOU2FAttestationStatement ();
50+
51+ // When
4852 CredentialRecord authenticator = TestDataUtil .createCredentialRecord (attestedCredentialData , attestationStatement );
4953
54+ // Then
5055 assertAll (
5156 () -> assertThat (authenticator .getAttestedCredentialData ()).isEqualTo (attestedCredentialData ),
5257 () -> assertThat (authenticator .getAttestationStatement ()).isEqualTo (attestationStatement ),
@@ -55,15 +60,28 @@ void constructor_test() {
5560 }
5661
5762 @ Test
58- void createFromRegistrationData_test () {
63+ void shouldCreateAuthenticatorFromRegistrationData () {
64+ // Given
5965 AttestationObject attestationObject = TestDataUtil .createAttestationObjectWithFIDOU2FAttestationStatement ();
6066 byte [] attestationObjectBytes = new byte [32 ];
6167 CollectedClientData collectedClientData = mock (CollectedClientData .class );
6268 byte [] collectedClientDataBytes = new byte [128 ];
63- AuthenticationExtensionsClientOutputs <RegistrationExtensionClientOutput > authenticationExtensionsClientOutputs = new AuthenticationExtensionsClientOutputs .BuilderForRegistration ().build ();
69+ AuthenticationExtensionsClientOutputs <RegistrationExtensionClientOutput > authenticationExtensionsClientOutputs =
70+ new AuthenticationExtensionsClientOutputs .BuilderForRegistration ().build ();
6471 Set <AuthenticatorTransport > transports = Collections .emptySet ();
65- RegistrationData registrationData = new RegistrationData (attestationObject , attestationObjectBytes , collectedClientData , collectedClientDataBytes , authenticationExtensionsClientOutputs , transports );
72+ RegistrationData registrationData = new RegistrationData (
73+ attestationObject ,
74+ attestationObjectBytes ,
75+ collectedClientData ,
76+ collectedClientDataBytes ,
77+ authenticationExtensionsClientOutputs ,
78+ transports
79+ );
80+
81+ // When
6682 AuthenticatorImpl authenticator = AuthenticatorImpl .createFromRegistrationData (registrationData );
83+
84+ // Then
6785 assertThat (authenticator .getAttestedCredentialData ()).isEqualTo (attestationObject .getAuthenticatorData ().getAttestedCredentialData ());
6886 assertThat (authenticator .getAttestationStatement ()).isEqualTo (attestationObject .getAttestationStatement ());
6987 assertThat (authenticator .getTransports ()).isEqualTo (transports );
@@ -73,20 +91,30 @@ void createFromRegistrationData_test() {
7391 }
7492
7593 @ Test
76- void getter_setter_test () {
94+ void shouldUpdateAuthenticatorPropertiesCorrectly () {
95+ // Given
7796 AttestedCredentialData attestedCredentialData = TestDataUtil .createAttestedCredentialData ();
7897 AttestationStatement attestationStatement = TestAttestationStatementUtil .createFIDOU2FAttestationStatement ();
79- AuthenticatorImpl authenticator = new AuthenticatorImpl (TestDataUtil .createAttestedCredentialData (), TestAttestationStatementUtil .createBasicPackedAttestationStatement (), 0 );
80- AuthenticationExtensionsAuthenticatorOutputs <RegistrationExtensionAuthenticatorOutput > authenticatorExtensions = new AuthenticationExtensionsAuthenticatorOutputs <>();
81- AuthenticationExtensionsClientOutputs <RegistrationExtensionClientOutput > clientExtensions = new AuthenticationExtensionsClientOutputs <>();
98+ AuthenticatorImpl authenticator = new AuthenticatorImpl (
99+ TestDataUtil .createAttestedCredentialData (),
100+ TestAttestationStatementUtil .createBasicPackedAttestationStatement (),
101+ 0
102+ );
103+ AuthenticationExtensionsAuthenticatorOutputs <RegistrationExtensionAuthenticatorOutput > authenticatorExtensions =
104+ new AuthenticationExtensionsAuthenticatorOutputs <>();
105+ AuthenticationExtensionsClientOutputs <RegistrationExtensionClientOutput > clientExtensions =
106+ new AuthenticationExtensionsClientOutputs <>();
82107 Set <AuthenticatorTransport > transports = Collections .singleton (AuthenticatorTransport .USB );
108+
109+ // When
83110 authenticator .setAttestedCredentialData (attestedCredentialData );
84111 authenticator .setAttestationStatement (attestationStatement );
85112 authenticator .setTransports (transports );
86113 authenticator .setCounter (1 );
87114 authenticator .setAuthenticatorExtensions (authenticatorExtensions );
88115 authenticator .setClientExtensions (clientExtensions );
89116
117+ // Then
90118 assertAll (
91119 () -> assertThat (authenticator .getAttestedCredentialData ()).isEqualTo (attestedCredentialData ),
92120 () -> assertThat (authenticator .getAttestationStatement ()).isEqualTo (attestationStatement ),
@@ -98,24 +126,34 @@ void getter_setter_test() {
98126 }
99127
100128 @ Test
101- void setCounter_range_test () {
102- AuthenticatorImpl authenticator = new AuthenticatorImpl (TestDataUtil .createAttestedCredentialData (), TestAttestationStatementUtil .createBasicPackedAttestationStatement (), 0 );
129+ void shouldRejectInvalidCounterValues () {
130+ // Given
131+ AuthenticatorImpl authenticator = new AuthenticatorImpl (
132+ TestDataUtil .createAttestedCredentialData (),
133+ TestAttestationStatementUtil .createBasicPackedAttestationStatement (),
134+ 0
135+ );
103136
137+ // Then
104138 assertAll (
139+ // When counter is negative
105140 () -> assertThrows (IllegalArgumentException .class ,
106141 () -> authenticator .setCounter (-1 )
107142 ),
143+ // When counter exceeds maximum value
108144 () -> assertThrows (IllegalArgumentException .class ,
109145 () -> authenticator .setCounter (4294967296L )
110146 )
111147 );
112148 }
113149
114150 @ Test
115- void equals_hashCode_test () {
151+ void shouldHaveCorrectEqualsAndHashCodeImplementation () {
152+ // Given
116153 Authenticator authenticatorA = TestDataUtil .createCredentialRecord ();
117154 Authenticator authenticatorB = TestDataUtil .createCredentialRecord ();
118155
156+ // Then
119157 assertAll (
120158 () -> assertThat (authenticatorA ).isEqualTo (authenticatorB ),
121159 () -> assertThat (authenticatorA ).hasSameHashCodeAs (authenticatorB )
0 commit comments