-
Notifications
You must be signed in to change notification settings - Fork 7
/
jwt_test.go
81 lines (68 loc) · 1.26 KB
/
jwt_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 devicecheck
import (
"reflect"
"testing"
)
func TestJWT_newJWT(t *testing.T) {
t.Parallel()
cases := map[string]struct {
issuer string
keyID string
want jwt
}{
"valid issuer/keyID": {
issuer: "issuer",
keyID: "keyID",
want: jwt{
issuer: "issuer",
keyID: "keyID",
},
},
}
for name, c := range cases {
c := c
t.Run(name, func(t *testing.T) {
t.Parallel()
got := newJWT(c.issuer, c.keyID)
if !reflect.DeepEqual(got, c.want) {
t.Errorf("want '%+v', got '%+v'", c.want, got)
}
})
}
}
func TestJWT_generate(t *testing.T) {
t.Parallel()
cases := map[string]struct {
filename string
jwt jwt
}{
"invalid filename": {
filename: "revoked_private_key.p8",
jwt: jwt{
issuer: "issuer",
keyID: "keyID",
},
},
}
for name, c := range cases {
c := c
t.Run(name, func(t *testing.T) {
t.Parallel()
cred := NewCredentialFile(c.filename)
key, err := cred.key()
if err != nil {
t.Error("want 'nil', got 'not nil'")
}
if key == nil {
t.Error("want 'not nil', got 'nil'")
}
token, err := c.jwt.generate(key)
if err != nil {
t.Errorf("want 'nil', got '%+v'", err)
}
if token == "" {
t.Error("want 'not empty', got 'empty'")
}
})
}
}