2525package com .yubico .webauthn .data
2626
2727import com .fasterxml .jackson .core .`type` .TypeReference
28+ import com .fasterxml .jackson .databind .JsonNode
2829import com .fasterxml .jackson .databind .ObjectMapper
2930import com .fasterxml .jackson .databind .exc .ValueInstantiationException
3031import com .fasterxml .jackson .databind .json .JsonMapper
3132import com .fasterxml .jackson .databind .node .BooleanNode
33+ import com .fasterxml .jackson .databind .node .JsonNodeFactory
3234import com .fasterxml .jackson .databind .node .ObjectNode
3335import com .fasterxml .jackson .databind .node .TextNode
3436import com .fasterxml .jackson .datatype .jdk8 .Jdk8Module
@@ -44,6 +46,7 @@ import com.yubico.webauthn.extension.appid.Generators._
4446import org .junit .runner .RunWith
4547import org .scalacheck .Arbitrary
4648import org .scalacheck .Arbitrary .arbitrary
49+ import org .scalacheck .Gen
4750import org .scalatest .funspec .AnyFunSpec
4851import org .scalatest .matchers .should .Matchers
4952import org .scalatestplus .junit .JUnitRunner
@@ -62,6 +65,7 @@ class JsonIoSpec
6265 .builder()
6366 .addModule(new Jdk8Module ())
6467 .build()
68+ val jf : JsonNodeFactory = JsonNodeFactory .instance
6569
6670 describe(" The class" ) {
6771
@@ -392,6 +396,44 @@ class JsonIoSpec
392396 ]]() {}
393397 )
394398 }
399+
400+ describe(""" tolerates and ignores the "response" sub-attribute:""" ) {
401+ def test [T <: JsonNode ](attrName : String , genAttrValue : Gen [T ]): Unit = {
402+ type P = PublicKeyCredential [
403+ AuthenticatorAttestationResponse ,
404+ ClientRegistrationExtensionOutputs ,
405+ ]
406+ it(s " ${attrName}. " ) {
407+ forAll(
408+ arbitrary[P ],
409+ genAttrValue,
410+ ) { (value : P , attrValue : T ) =>
411+ val tree : ObjectNode = json.valueToTree(value)
412+ tree
413+ .get(" response" )
414+ .asInstanceOf [ObjectNode ]
415+ .set(attrName, attrValue)
416+ val encoded = json.writeValueAsString(tree)
417+ val decoded =
418+ PublicKeyCredential .parseRegistrationResponseJson(encoded)
419+ val recoded : ObjectNode = json.valueToTree[ObjectNode ](decoded)
420+ recoded.has(attrName) should be(false )
421+ }
422+ }
423+ }
424+
425+ test(
426+ " publicKeyAlgorithm" ,
427+ arbitraryCOSEAlgorithmIdentifier.arbitrary.map(i =>
428+ jf.numberNode(i.getId)
429+ ),
430+ )
431+
432+ test(
433+ " publicKey" ,
434+ arbitrary[String ].map(new TextNode (_)),
435+ )
436+ }
395437 }
396438
397439 describe(" The function PublicKeyCredential.parseAssertionResponseJson" ) {
0 commit comments