forked from dgrijalva/jwt-go
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
claims_test.go
81 lines (71 loc) · 2.28 KB
/
claims_test.go
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
package jwt
import (
"testing"
"time"
)
func Test_StandardClaims_VerifyExpiresAt_empty(t *testing.T) {
c := StandardClaims{}
if !c.VerifyExpiresAt(time.Now(), false) {
t.Fatalf("Failed to verify exp claim, wanted: %v got %v", true, false)
}
}
func Test_StandardClaims_VerifyExpiresAt_expired(t *testing.T) {
c := StandardClaims{
ExpiresAt: float64(time.Now().Add(-1*time.Hour).Unix()) + 0.123,
}
if c.VerifyExpiresAt(time.Now(), true) {
t.Fatalf("Failed to verify exp claim, wanted: %v got %v", false, true)
}
}
func Test_StandardClaims_VerifyExpiresAt_not_expired(t *testing.T) {
c := StandardClaims{
ExpiresAt: float64(time.Now().Add(1*time.Hour).Unix()) + 0.123,
}
if !c.VerifyExpiresAt(time.Now(), true) {
t.Fatalf("Failed to verify exp claim, wanted: %v got %v", true, false)
}
}
func Test_StandardClaims_VerifyIssuedAt_empty(t *testing.T) {
c := StandardClaims{}
if !c.VerifyIssuedAt(time.Now(), false) {
t.Fatalf("Failed to verify iat claim, wanted: %v got %v", true, false)
}
}
func Test_StandardClaims_VerifyIssuedAt_expired(t *testing.T) {
c := StandardClaims{
IssuedAt: float64(time.Now().Add(1*time.Hour).Unix()) + 0.123,
}
if c.VerifyIssuedAt(time.Now(), true) {
t.Fatalf("Failed to verify iat claim, wanted: %v got %v", false, true)
}
}
func Test_StandardClaims_VerifyIssuedAt_past(t *testing.T) {
c := StandardClaims{
IssuedAt: float64(time.Now().Add(-1*time.Hour).Unix()) + 0.123,
}
if !c.VerifyIssuedAt(time.Now(), true) {
t.Fatalf("Failed to verify iat claim, wanted: %v got %v", true, false)
}
}
func Test_StandardClaims_VerifyNotBefore_empty(t *testing.T) {
c := StandardClaims{}
if !c.VerifyNotBefore(time.Now(), false) {
t.Fatalf("Failed to verify nbf claim, wanted: %v got %v", true, false)
}
}
func Test_StandardClaims_VerifyNotBefore_expired(t *testing.T) {
c := StandardClaims{
NotBefore: float64(time.Now().Add(1*time.Hour).Unix()) + 0.123,
}
if c.VerifyNotBefore(time.Now(), true) {
t.Fatalf("Failed to verify nbf claim, wanted: %v got %v", false, true)
}
}
func Test_StandardClaims_VerifyNotBefore_passed(t *testing.T) {
c := StandardClaims{
NotBefore: float64(time.Now().Add(-1*time.Hour).Unix()) + 0.123,
}
if !c.VerifyNotBefore(time.Now(), true) {
t.Fatalf("Failed to verify nbf claim, wanted: %v got %v", true, false)
}
}