(t *testing.T)
| 263 | } |
| 264 | |
| 265 | func Test_Validator_requireNotBefore(t *testing.T) { |
| 266 | type fields struct { |
| 267 | leeway time.Duration |
| 268 | timeFunc func() time.Time |
| 269 | requireNbf bool |
| 270 | } |
| 271 | type args struct { |
| 272 | claims Claims |
| 273 | cmp time.Time |
| 274 | required bool |
| 275 | } |
| 276 | tests := []struct { |
| 277 | name string |
| 278 | fields fields |
| 279 | args args |
| 280 | wantErr error |
| 281 | }{ |
| 282 | { |
| 283 | name: "good claim without nbf", |
| 284 | fields: fields{requireNbf: false}, |
| 285 | args: args{claims: MapClaims{}, required: false}, |
| 286 | wantErr: nil, |
| 287 | }, |
| 288 | { |
| 289 | name: "good claim with nbf", |
| 290 | fields: fields{requireNbf: true}, |
| 291 | args: args{ |
| 292 | claims: RegisteredClaims{NotBefore: NewNumericDate(time.Now().Add(time.Minute * -10))}, |
| 293 | cmp: time.Now().Add(10 * time.Minute), |
| 294 | required: true, |
| 295 | }, |
| 296 | wantErr: nil, |
| 297 | }, |
| 298 | { |
| 299 | name: "token nbf time is in future", |
| 300 | fields: fields{requireNbf: true, timeFunc: time.Now}, |
| 301 | args: args{ |
| 302 | claims: RegisteredClaims{NotBefore: NewNumericDate(time.Now().Add(time.Minute * +10))}, |
| 303 | cmp: time.Now().Add(10 * time.Minute), |
| 304 | required: true, |
| 305 | }, |
| 306 | wantErr: ErrTokenNotValidYet, |
| 307 | }, |
| 308 | } |
| 309 | for _, tt := range tests { |
| 310 | t.Run(tt.name, func(t *testing.T) { |
| 311 | opts := []ParserOption{ |
| 312 | WithLeeway(tt.fields.leeway), |
| 313 | } |
| 314 | |
| 315 | if tt.fields.requireNbf { |
| 316 | opts = append(opts, WithNotBeforeRequired()) |
| 317 | } |
| 318 | |
| 319 | if tt.fields.timeFunc != nil { |
| 320 | opts = append(opts, WithTimeFunc(tt.fields.timeFunc)) |
| 321 | } |
| 322 |
nothing calls this directly
no test coverage detected