-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator_test.go
More file actions
86 lines (81 loc) · 1.64 KB
/
Copy pathvalidator_test.go
File metadata and controls
86 lines (81 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package nwt
import (
"errors"
"fmt"
"testing"
"time"
)
func TestStrictValidator(t *testing.T) {
tests := []struct {
token Token
err error
}{
{
token: Token{},
err: ErrEmptyID,
},
{
token: Token{ID: "id"},
err: ErrInvalidIssuedAt,
},
{
token: Token{
ID: "id",
IssuedAt: time.Unix(420, 0).UTC(),
Expiration: time.Unix(69, 0).UTC(),
NotBefore: time.Unix(420, 0).UTC(),
},
err: ErrInvalidTimeWindow,
},
{
token: Token{
ID: "id",
IssuedAt: time.Now().UTC(),
Expiration: MaxTime,
NotBefore: time.Now().Add(time.Hour).UTC(),
},
err: ErrNotYetValid,
},
{
token: Token{
ID: "id",
IssuedAt: time.Now().UTC(),
Expiration: time.Now().Add(-time.Hour).UTC(),
NotBefore: MinTime,
},
err: ErrExpired,
},
{
token: Token{
ID: "id",
IssuedAt: time.Now().UTC(),
Audience: []string{"other-identifier"},
Expiration: time.Now().Add(time.Hour).UTC(),
NotBefore: time.Now().Add(-time.Hour).UTC(),
},
err: ErrInvalidAudience,
},
{
token: Token{
ID: "id",
IssuedAt: time.Now().UTC(),
Audience: []string{"identifier"},
Expiration: time.Now().Add(time.Hour).UTC(),
NotBefore: time.Now().Add(-time.Hour).UTC(),
},
err: nil,
},
}
for i, test := range tests {
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
validator := StrictValidator{
Identifier: "identifier",
ClockSkew: time.Minute,
}
err := validator.Validate(test.token)
if !errors.Is(err, test.err) {
t.Fatalf("expected error %v, got %v", test.err, err)
}
})
}
}