@@ -41,12 +41,13 @@ import com.yubico.webauthn.extension.appid.Generators._
41
41
import org .junit .runner .RunWith
42
42
import org .scalacheck .Arbitrary
43
43
import org .scalacheck .Arbitrary .arbitrary
44
- import org .scalacheck .Gen
45
44
import org .scalatest .funspec .AnyFunSpec
46
45
import org .scalatest .matchers .should .Matchers
47
46
import org .scalatestplus .junit .JUnitRunner
48
47
import org .scalatestplus .scalacheck .ScalaCheckDrivenPropertyChecks
49
48
49
+ import scala .jdk .OptionConverters .RichOptional
50
+
50
51
@ RunWith (classOf [JUnitRunner ])
51
52
class JsonIoSpec
52
53
extends AnyFunSpec
@@ -351,15 +352,16 @@ class JsonIoSpec
351
352
)
352
353
}
353
354
354
- it(" allows and ignores an authenticatorAttachment attribute." ) {
355
+ it(
356
+ " allows an authenticatorAttachment attribute, but ignores unknown values."
357
+ ) {
355
358
def test [P <: PublicKeyCredential [_, _]](tpe : TypeReference [P ])(implicit
356
359
a : Arbitrary [P ]
357
360
): Unit = {
358
361
forAll(
359
362
a.arbitrary,
360
- Gen .oneOf(
361
- arbitrary[AuthenticatorAttachment ].map(_.getValue),
362
- arbitrary[String ],
363
+ arbitrary[String ].suchThat(s =>
364
+ ! AuthenticatorAttachment .values.map(_.getValue).contains(s)
363
365
),
364
366
) { (value : P , authenticatorAttachment : String ) =>
365
367
val tree : ObjectNode = json.valueToTree(value)
@@ -370,8 +372,37 @@ class JsonIoSpec
370
372
val encoded = json.writeValueAsString(tree)
371
373
println(authenticatorAttachment)
372
374
val decoded = json.readValue(encoded, tpe)
375
+ decoded.getAuthenticatorAttachment.asScala should be(None )
376
+ }
377
+
378
+ forAll(
379
+ a.arbitrary,
380
+ arbitrary[AuthenticatorAttachment ],
381
+ ) { (value : P , authenticatorAttachment : AuthenticatorAttachment ) =>
382
+ val tree : ObjectNode = json.valueToTree(value)
383
+ tree.set(
384
+ " authenticatorAttachment" ,
385
+ new TextNode (authenticatorAttachment.getValue),
386
+ )
387
+ val encoded = json.writeValueAsString(tree)
388
+ println(authenticatorAttachment)
389
+ val decoded = json.readValue(encoded, tpe)
390
+
391
+ decoded.getAuthenticatorAttachment.asScala should equal(
392
+ Some (authenticatorAttachment)
393
+ )
394
+ }
395
+
396
+ forAll(
397
+ a.arbitrary
398
+ ) { (value : P ) =>
399
+ val tree : ObjectNode = json.valueToTree(
400
+ value.toBuilder.authenticatorAttachment(null ).build()
401
+ )
402
+ val encoded = json.writeValueAsString(tree)
403
+ val decoded = json.readValue(encoded, tpe)
373
404
374
- decoded should equal(value )
405
+ decoded.getAuthenticatorAttachment.asScala should be( None )
375
406
}
376
407
}
377
408
0 commit comments