Skip to content

Commit 77a8af8

Browse files
committed
Add test of SupportedCtapOptions serialization stability
This test will be needed later for a more focused view on why the sibling test of `MetadataBLOBPayload` serialization stability begins to fail.
1 parent f4981f2 commit 77a8af8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

webauthn-server-attestation/src/test/scala/com/yubico/fido/metadata/MetadataBlobSpec.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package com.yubico.fido.metadata
22

3+
import com.yubico.fido.metadata.Generators.arbitrarySupportedCtapOptions
34
import com.yubico.internal.util.JacksonCodecs
45
import com.yubico.webauthn.data.ByteArray
6+
import org.scalacheck.Arbitrary
7+
import org.scalacheck.Gen
58
import org.scalatest.funspec.AnyFunSpec
69
import org.scalatest.matchers.should.Matchers
710
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
811

12+
import scala.jdk.CollectionConverters.SetHasAsScala
13+
import scala.jdk.OptionConverters.RichOptional
14+
915
class MetadataBlobSpec
1016
extends AnyFunSpec
1117
with Matchers
@@ -50,4 +56,34 @@ class MetadataBlobSpec
5056
}
5157
}
5258

59+
describe("SupportedCtapOptions") {
60+
it(
61+
"are structurally identical after multiple (de)serialization round-trips."
62+
) {
63+
val json = JacksonCodecs.json()
64+
val blob = json
65+
.readValue(
66+
ByteArray
67+
.fromBase64Url(FidoMds3Examples.BlobPayloadBase64url)
68+
.getBytes,
69+
classOf[MetadataBLOBPayload],
70+
)
71+
val blobOptions = blob.getEntries.asScala
72+
.flatMap(entry => entry.getMetadataStatement.toScala)
73+
.flatMap(statement => statement.getAuthenticatorGetInfo.toScala)
74+
.flatMap(info => info.getOptions.toScala)
75+
forAll(Gen.oneOf(Arbitrary.arbitrary, Gen.oneOf(blobOptions))) {
76+
(options1: SupportedCtapOptions) =>
77+
val encoded1 = json.writeValueAsBytes(options1)
78+
val options2 = json.readValue(encoded1, classOf[SupportedCtapOptions])
79+
val encoded2 = json.writeValueAsBytes(options2)
80+
val options3 = json.readValue(encoded2, classOf[SupportedCtapOptions])
81+
82+
options2 should not be null
83+
options2 should equal(options1)
84+
options3 should not be null
85+
options3 should equal(options1)
86+
}
87+
}
88+
}
5389
}

0 commit comments

Comments
 (0)