|
1 | 1 | package com.yubico.fido.metadata
|
2 | 2 |
|
| 3 | +import com.yubico.fido.metadata.Generators.arbitrarySupportedCtapOptions |
3 | 4 | import com.yubico.internal.util.JacksonCodecs
|
4 | 5 | import com.yubico.webauthn.data.ByteArray
|
| 6 | +import org.scalacheck.Arbitrary |
| 7 | +import org.scalacheck.Gen |
5 | 8 | import org.scalatest.funspec.AnyFunSpec
|
6 | 9 | import org.scalatest.matchers.should.Matchers
|
7 | 10 | import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
|
8 | 11 |
|
| 12 | +import scala.jdk.CollectionConverters.SetHasAsScala |
| 13 | +import scala.jdk.OptionConverters.RichOptional |
| 14 | + |
9 | 15 | class MetadataBlobSpec
|
10 | 16 | extends AnyFunSpec
|
11 | 17 | with Matchers
|
@@ -50,4 +56,34 @@ class MetadataBlobSpec
|
50 | 56 | }
|
51 | 57 | }
|
52 | 58 |
|
| 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 | + } |
53 | 89 | }
|
0 commit comments