Skip to content

Commit 2a18e13

Browse files
committed
Add test
1 parent c8d4178 commit 2a18e13

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

web/src/test/java/org/springframework/security/web/webauthn/management/Webauthn4jRelyingPartyOperationsTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package org.springframework.security.web.webauthn.management;
1818

19+
import java.io.ByteArrayInputStream;
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.ObjectInputStream;
22+
import java.io.ObjectOutputStream;
1923
import java.nio.charset.StandardCharsets;
2024
import java.time.Duration;
2125
import java.util.Arrays;
@@ -60,6 +64,7 @@
6064
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialCreationOptions;
6165
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialUserEntity;
6266
import org.springframework.security.web.webauthn.api.UserVerificationRequirement;
67+
import org.springframework.util.SerializationUtils;
6368

6469
import static org.assertj.core.api.Assertions.assertThat;
6570
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -494,6 +499,30 @@ void createCredentialRequestOptionsThenUserVerificationSameAsCreation() {
494499
.isEqualTo(creationOptions.getAuthenticatorSelection().getUserVerification());
495500
}
496501

502+
@Test
503+
void convertParamToWebauthn4jPublicKeyComparison() throws Exception {
504+
505+
PublicKeyCredentialCreationOptions options = TestPublicKeyCredentialCreationOptions
506+
.createPublicKeyCredentialCreationOptions()
507+
.build();
508+
509+
// Simulate storage into external session storage: serialize/deserialize of the creation options
510+
ByteArrayOutputStream bo = new ByteArrayOutputStream();
511+
ObjectOutputStream oos = new ObjectOutputStream(bo);
512+
oos.writeObject(options);
513+
514+
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bo.toByteArray()));
515+
PublicKeyCredentialCreationOptions copiedOptions = (PublicKeyCredentialCreationOptions)ois.readObject() ;
516+
517+
// Check that the deep copied options are still valid
518+
PublicKeyCredential publicKey = TestPublicKeyCredential.createPublicKeyCredential().build();
519+
ImmutableRelyingPartyRegistrationRequest registrationRequest = new ImmutableRelyingPartyRegistrationRequest(
520+
copiedOptions, new RelyingPartyPublicKey(publicKey, this.label));
521+
522+
var test = this.rpOperations.registerCredential(registrationRequest);
523+
524+
}
525+
497526
private static AuthenticatorAttestationResponse setFlag(byte... flags) throws Exception {
498527
AuthenticatorAttestationResponseBuilder authAttResponseBldr = TestAuthenticatorAttestationResponse
499528
.createAuthenticatorAttestationResponse();

0 commit comments

Comments
 (0)