40
40
import com .webauthn4j .verifier .attestation .trustworthiness .self .DefaultSelfAttestationTrustworthinessVerifier ;
41
41
import org .junit .jupiter .api .Test ;
42
42
43
+ import java .io .ByteArrayInputStream ;
43
44
import java .util .Arrays ;
44
45
import java .util .Collections ;
45
46
import java .util .List ;
@@ -51,7 +52,9 @@ class RegistrationResponseJSONVerificationTest {
51
52
52
53
private final ObjectConverter objectConverter = new ObjectConverter ();
53
54
55
+ private final String rpId = "example.com" ;
54
56
private final Origin origin = new Origin ("http://localhost" );
57
+ private final Challenge challenge = new DefaultChallenge ();
55
58
private final WebAuthnAuthenticatorAdaptor webAuthnAuthenticatorAdaptor = new WebAuthnAuthenticatorAdaptor (EmulatorUtil .PACKED_AUTHENTICATOR );
56
59
private final ClientPlatform clientPlatform = new ClientPlatform (origin , webAuthnAuthenticatorAdaptor );
57
60
private final NoneAttestationStatementVerifier noneAttestationStatementValidator = new NoneAttestationStatementVerifier ();
@@ -71,9 +74,46 @@ class RegistrationResponseJSONVerificationTest {
71
74
);
72
75
73
76
@ Test
74
- void test () {
75
- String rpId = "example.com" ;
76
- Challenge challenge = new DefaultChallenge ();
77
+ void test_with_registrationResponseJSON_as_string () {
78
+ PublicKeyCredential <AuthenticatorAttestationResponse , RegistrationExtensionClientOutput > credential = createCredential ();
79
+ String registrationResponseJSON = objectConverter .getJsonConverter ().writeValueAsString (credential );
80
+ ServerProperty serverProperty = new ServerProperty (origin , rpId , challenge , null );
81
+ List <PublicKeyCredentialParameters > pubKeyCredParams = null ;
82
+ RegistrationParameters registrationParameters = new RegistrationParameters (
83
+ serverProperty ,
84
+ pubKeyCredParams ,
85
+ false
86
+ );
87
+
88
+ assertThatCode (()->target .parseRegistrationResponseJSON (registrationResponseJSON )).doesNotThrowAnyException ();
89
+
90
+ RegistrationData registrationData = target .parseRegistrationResponseJSON (registrationResponseJSON );
91
+ assertThatCode (()->target .verify (registrationData , registrationParameters )).doesNotThrowAnyException ();
92
+
93
+ assertThatCode (()->target .verifyRegistrationResponseJSON (registrationResponseJSON , registrationParameters )).doesNotThrowAnyException ();
94
+ }
95
+
96
+ @ Test
97
+ void test_with_registrationResponseJSON_as_InputStream () {
98
+ PublicKeyCredential <AuthenticatorAttestationResponse , RegistrationExtensionClientOutput > credential = createCredential ();
99
+ byte [] registrationResponseJSON = objectConverter .getJsonConverter ().writeValueAsBytes (credential );
100
+ ServerProperty serverProperty = new ServerProperty (origin , rpId , challenge , null );
101
+ List <PublicKeyCredentialParameters > pubKeyCredParams = null ;
102
+ RegistrationParameters registrationParameters = new RegistrationParameters (
103
+ serverProperty ,
104
+ pubKeyCredParams ,
105
+ false
106
+ );
107
+
108
+ assertThatCode (()->target .parseRegistrationResponseJSON (new ByteArrayInputStream (registrationResponseJSON ))).doesNotThrowAnyException ();
109
+
110
+ RegistrationData registrationData = target .parseRegistrationResponseJSON (new ByteArrayInputStream (registrationResponseJSON ));
111
+ assertThatCode (()->target .verify (registrationData , registrationParameters )).doesNotThrowAnyException ();
112
+
113
+ assertThatCode (()->target .verifyRegistrationResponseJSON (new ByteArrayInputStream (registrationResponseJSON ), registrationParameters )).doesNotThrowAnyException ();
114
+ }
115
+
116
+ private PublicKeyCredential <AuthenticatorAttestationResponse , RegistrationExtensionClientOutput > createCredential (){
77
117
AuthenticatorSelectionCriteria authenticatorSelectionCriteria =
78
118
new AuthenticatorSelectionCriteria (
79
119
AuthenticatorAttachment .CROSS_PLATFORM ,
@@ -97,21 +137,6 @@ void test() {
97
137
AttestationConveyancePreference .NONE ,
98
138
extensions
99
139
);
100
- PublicKeyCredential <AuthenticatorAttestationResponse , RegistrationExtensionClientOutput > credential = clientPlatform .create (credentialCreationOptions );
101
- String registrationResponseJSON = objectConverter .getJsonConverter ().writeValueAsString (credential );
102
- ServerProperty serverProperty = new ServerProperty (origin , rpId , challenge , null );
103
- List <PublicKeyCredentialParameters > pubKeyCredParams = null ;
104
- RegistrationParameters registrationParameters = new RegistrationParameters (
105
- serverProperty ,
106
- pubKeyCredParams ,
107
- false
108
- );
109
-
110
- assertThatCode (()->target .parseRegistrationResponseJSON (registrationResponseJSON )).doesNotThrowAnyException ();
111
-
112
- RegistrationData registrationData = target .parseRegistrationResponseJSON (registrationResponseJSON );
113
- assertThatCode (()->target .verify (registrationData , registrationParameters )).doesNotThrowAnyException ();
114
-
115
- assertThatCode (()->target .verifyRegistrationResponseJSON (registrationResponseJSON , registrationParameters )).doesNotThrowAnyException ();
140
+ return clientPlatform .create (credentialCreationOptions );
116
141
}
117
142
}
0 commit comments