@@ -27,6 +27,7 @@ package com.yubico.webauthn
27
27
import com .fasterxml .jackson .core .`type` .TypeReference
28
28
import com .fasterxml .jackson .databind .node .JsonNodeFactory
29
29
import com .fasterxml .jackson .databind .node .ObjectNode
30
+ import com .fasterxml .jackson .databind .node .TextNode
30
31
import com .upokecenter .cbor .CBORObject
31
32
import com .yubico .internal .util .JacksonCodecs
32
33
import com .yubico .webauthn .data .AssertionExtensionInputs
@@ -179,6 +180,7 @@ class RelyingPartyAssertionSpec
179
180
credentialId : ByteArray = Defaults .credentialId,
180
181
credentialKey : KeyPair = Defaults .credentialKey,
181
182
credentialRepository : Option [CredentialRepository ] = None ,
183
+ isSecurePaymentConfirmation : Option [Boolean ] = None ,
182
184
origins : Option [Set [String ]] = None ,
183
185
requestedExtensions : AssertionExtensionInputs =
184
186
Defaults .requestedExtensions,
@@ -283,6 +285,10 @@ class RelyingPartyAssertionSpec
283
285
.response(response)
284
286
.callerTokenBindingId(callerTokenBindingId.toJava)
285
287
288
+ isSecurePaymentConfirmation foreach { isSpc =>
289
+ fao.isSecurePaymentConfirmation(isSpc)
290
+ }
291
+
286
292
builder
287
293
.build()
288
294
._finishAssertion(fao.build())
@@ -941,14 +947,18 @@ class RelyingPartyAssertionSpec
941
947
step.validations shouldBe a[Success [_]]
942
948
}
943
949
944
- def assertFails (typeString : String ): Unit = {
950
+ def assertFails (
951
+ typeString : String ,
952
+ isSecurePaymentConfirmation : Option [Boolean ] = None ,
953
+ ): Unit = {
945
954
val steps = finishAssertion(
946
955
clientDataJson = JacksonCodecs .json.writeValueAsString(
947
956
JacksonCodecs .json
948
957
.readTree(Defaults .clientDataJson)
949
958
.asInstanceOf [ObjectNode ]
950
959
.set(" type" , jsonFactory.textNode(typeString))
951
- )
960
+ ),
961
+ isSecurePaymentConfirmation = isSecurePaymentConfirmation,
952
962
)
953
963
val step : FinishAssertionSteps # Step11 =
954
964
steps.begin.next.next.next.next.next
@@ -973,6 +983,72 @@ class RelyingPartyAssertionSpec
973
983
it(""" The string "webauthn.create" fails.""" ) {
974
984
assertFails(" webauthn.create" )
975
985
}
986
+
987
+ it(""" The string "payment.get" fails.""" ) {
988
+ assertFails(" payment.get" )
989
+ }
990
+
991
+ describe(" If the isSecurePaymentConfirmation option is set," ) {
992
+ it(" the default test case fails." ) {
993
+ val steps =
994
+ finishAssertion(isSecurePaymentConfirmation = Some (true ))
995
+ val step : FinishAssertionSteps # Step11 =
996
+ steps.begin.next.next.next.next.next
997
+
998
+ step.validations shouldBe a[Failure [_]]
999
+ step.validations.failed.get shouldBe an[IllegalArgumentException ]
1000
+ }
1001
+
1002
+ it(""" the default test case succeeds if type is overwritten with the value "payment.get".""" ) {
1003
+ val json = JacksonCodecs .json()
1004
+ val steps = finishAssertion(
1005
+ isSecurePaymentConfirmation = Some (true ),
1006
+ clientDataJson = json.writeValueAsString(
1007
+ json
1008
+ .readTree(Defaults .clientDataJson)
1009
+ .asInstanceOf [ObjectNode ]
1010
+ .set[ObjectNode ](" type" , new TextNode (" payment.get" ))
1011
+ ),
1012
+ )
1013
+ val step : FinishAssertionSteps # Step11 =
1014
+ steps.begin.next.next.next.next.next
1015
+
1016
+ step.validations shouldBe a[Success [_]]
1017
+ }
1018
+
1019
+ it(""" any value other than "payment.get" fails.""" ) {
1020
+ forAll { (typeString : String ) =>
1021
+ whenever(typeString != " payment.get" ) {
1022
+ assertFails(
1023
+ typeString,
1024
+ isSecurePaymentConfirmation = Some (true ),
1025
+ )
1026
+ }
1027
+ }
1028
+ forAll(Gen .alphaNumStr) { (typeString : String ) =>
1029
+ whenever(typeString != " payment.get" ) {
1030
+ assertFails(
1031
+ typeString,
1032
+ isSecurePaymentConfirmation = Some (true ),
1033
+ )
1034
+ }
1035
+ }
1036
+ }
1037
+
1038
+ it(""" the string "webauthn.create" fails.""" ) {
1039
+ assertFails(
1040
+ " webauthn.create" ,
1041
+ isSecurePaymentConfirmation = Some (true ),
1042
+ )
1043
+ }
1044
+
1045
+ it(""" the string "webauthn.get" fails.""" ) {
1046
+ assertFails(
1047
+ " webauthn.get" ,
1048
+ isSecurePaymentConfirmation = Some (true ),
1049
+ )
1050
+ }
1051
+ }
976
1052
}
977
1053
978
1054
it(" 12. Verify that the value of C.challenge equals the base64url encoding of options.challenge." ) {
0 commit comments