@@ -59,6 +59,13 @@ func assertMessage(t *testing.T, body []byte, message string) {
59
59
assert .Equal (t , message , gjson .GetBytes (body , "ui.messages.0.text" ).String ())
60
60
}
61
61
62
+ func assertFieldMessage (t * testing.T , body []byte , fieldName string , message string ) {
63
+ t .Helper ()
64
+ messages := gjson .GetBytes (body , "ui.nodes.#(attributes.name==" + fieldName + ").messages" )
65
+ assert .Len (t , messages .Array (), 1 , "expected field %s to have one message, got %s" , fieldName , messages )
66
+ assert .Equal (t , message , messages .Get ("0.text" ).String ())
67
+ }
68
+
62
69
func extractCsrfToken (body []byte ) string {
63
70
return gjson .GetBytes (body , "ui.nodes.#(attributes.name==csrf_token).attributes.value" ).String ()
64
71
}
@@ -935,9 +942,30 @@ func TestRecovery(t *testing.T) {
935
942
// For good measure, check that the second code works!
936
943
body = submitRecoveryCode (t , c , body , RecoveryFlowTypeBrowser , recoveryCode2 , http .StatusOK )
937
944
assertMessage (t , []byte (body ), "You successfully recovered your account. Please change your password or set up an alternative login method (e.g. social sign in) within the next 60.00 minutes." )
938
-
939
945
})
940
946
947
+ t .Run ("description=should not show outdated validation message if newer message appears #2799" , func (t * testing.T ) {
948
+ recoveryEmail := strings .ToLower (testhelpers .RandomEmail ())
949
+ createIdentityToRecover (t , reg , recoveryEmail )
950
+
951
+ c := testhelpers .NewClientWithCookies (t )
952
+ body := expectSuccessfulRecovery (t , c , RecoveryFlowTypeBrowser , func (v url.Values ) {
953
+ v .Set ("email" , recoveryEmail )
954
+ })
955
+
956
+ action := gjson .Get (body , "ui.action" ).String ()
957
+ require .NotEmpty (t , action )
958
+ assert .Equal (t , recoveryEmail , gjson .Get (body , "ui.nodes.#(attributes.name==email).attributes.value" ).String ())
959
+
960
+ body = submitRecoveryCode (t , c , body , RecoveryFlowTypeBrowser , "123" , http .StatusOK ) // Send code that validates field schema
961
+
962
+ assertFieldMessage (t , []byte (body ), "code" , "does not match pattern \" ^\\ \\ d{8}$\" " )
963
+
964
+ body = submitRecoveryCode (t , c , body , RecoveryFlowTypeBrowser , "12312312" , http .StatusOK ) // Now send a wrong code that triggers "global" validation error
965
+
966
+ assert .Empty (t , gjson .Get (body , "ui.nodes.#(attributes.name==code).messages" ).Array ())
967
+ assertMessage (t , []byte (body ), "The recovery code is invalid or has already been used. Please try again." )
968
+ })
941
969
}
942
970
943
971
func TestDisabledStrategy (t * testing.T ) {
0 commit comments