@@ -10787,6 +10787,42 @@ func TestJSONValidation(t *testing.T) {
1078710787 }, "Bad field type int" )
1078810788}
1078910789
10790+ func TestJWTValidation (t * testing.T ) {
10791+ tests := []struct {
10792+ param string
10793+ expected bool
10794+ }{
10795+ {"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiZ29waGVyIn0.O_bROM_szPq9qBql-XDHMranHwP48ODdoLICWzqBr_U" , true },
10796+ {"acb123-_.def456-_.ghi789-_" , true },
10797+ {"eyJhbGciOiJOT05FIn0.e30." , true },
10798+ {"eyJhbGciOiJOT05FIn0.e30.\n " , false },
10799+ {"\x00 .\x00 .\x00 " , false },
10800+ {"" , false },
10801+ }
10802+
10803+ validate := New ()
10804+
10805+ for i , test := range tests {
10806+
10807+ errs := validate .Var (test .param , "jwt" )
10808+
10809+ if test .expected {
10810+ if ! IsEqual (errs , nil ) {
10811+ t .Fatalf ("Index: %d jwt failed Error: %s" , i , errs )
10812+ }
10813+ } else {
10814+ if IsEqual (errs , nil ) {
10815+ t .Fatalf ("Index: %d jwt failed Error: %s" , i , errs )
10816+ } else {
10817+ val := getError (errs , "" , "" )
10818+ if val .Tag () != "jwt" {
10819+ t .Fatalf ("Index: %d jwt failed Error: %s" , i , errs )
10820+ }
10821+ }
10822+ }
10823+ }
10824+ }
10825+
1079010826func Test_hostnameport_validator (t * testing.T ) {
1079110827 type Host struct {
1079210828 Addr string `validate:"hostname_port"`
0 commit comments