MCPcopy
hub / github.com/golang-jwt/jwt / Test_Validator_Validate

Function Test_Validator_Validate

validator_test.go:23–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21}
22
23func Test_Validator_Validate(t *testing.T) {
24 type fields struct {
25 leeway time.Duration
26 timeFunc func() time.Time
27 verifyIat bool
28 expectedAud []string
29 expectAllAud bool
30 expectedIss string
31 expectedSub string
32 }
33 type args struct {
34 claims Claims
35 }
36 tests := []struct {
37 name string
38 fields fields
39 args args
40 wantErr error
41 }{
42 {
43 name: "expected iss mismatch",
44 fields: fields{expectedIss: "me"},
45 args: args{RegisteredClaims{Issuer: "not_me"}},
46 wantErr: ErrTokenInvalidIssuer,
47 },
48 {
49 name: "expected iss is missing",
50 fields: fields{expectedIss: "me"},
51 args: args{RegisteredClaims{}},
52 wantErr: ErrTokenRequiredClaimMissing,
53 },
54 {
55 name: "expected sub mismatch",
56 fields: fields{expectedSub: "me"},
57 args: args{RegisteredClaims{Subject: "not-me"}},
58 wantErr: ErrTokenInvalidSubject,
59 },
60 {
61 name: "expected sub is missing",
62 fields: fields{expectedSub: "me"},
63 args: args{RegisteredClaims{}},
64 wantErr: ErrTokenRequiredClaimMissing,
65 },
66 {
67 name: "custom validator",
68 fields: fields{},
69 args: args{MyCustomClaims{Foo: "not-bar"}},
70 wantErr: ErrFooBar,
71 },
72 }
73 for _, tt := range tests {
74 t.Run(tt.name, func(t *testing.T) {
75 v := &Validator{
76 leeway: tt.fields.leeway,
77 timeFunc: tt.fields.timeFunc,
78 verifyIat: tt.fields.verifyIat,
79 expectedAud: tt.fields.expectedAud,
80 expectAllAud: tt.fields.expectAllAud,

Callers

nothing calls this directly

Calls 1

ValidateMethod · 0.95

Tested by

no test coverage detected