-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_test.go
134 lines (126 loc) · 2.52 KB
/
generate_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package jwt
import (
"bytes"
"errors"
//"fmt"
//"strings"
"testing"
)
func TestKeySlicePickKey(t *testing.T) {
k := []KeySlice{
{"1a9s8n8", "1K9l89853"},
{"abcdefg"},
}
//if k.valid
//fmt.Println("len(keysplice):", len(k))
tests := []struct {
keys KeySlice
err error
}{
{k[0], nil},
{k[1], nil},
//{k[1], errors.New("jwt/keySlice.pickKey : no keys stored in this slice")},
}
//fmt.Println("len(tests):", len(tests))
for _, v := range tests {
//fmt.Println("test:", i)
key, keyid, err := v.keys.pickKey()
if v.err != err {
t.Error("errors mismatch,", "expected:", v.err, "received:", err)
} else {
if !bytes.Equal(key, []byte(v.keys[keyid])) {
t.Error("the key does not match any possible key")
}
}
}
}
func TestGenerate(t *testing.T) {
/*var liste keySlice
liste = []string{"1a9s8n8", "1K9l89853"}*/
liste := KeySlice{"1a9s8n8", "1K9l89853", "l2a9h0s1s8e8n", "aeiouy"}
type parameters struct {
keypicker KeyPicker
algo string
issuer string
username string
role string
accesslevel string
audience []string
tokenId string
}
tests := []struct {
params parameters
token string
erreur error
}{
{
parameters{
liste,
"BcRYPT",
"test.com",
"@laahs",
"standard",
"private",
[]string{"test.com"},
"",
},
"",
nil,
},
{
parameters{
nil,
"BcRYPT",
"test.com",
"@laahs",
"standard",
"private",
[]string{"test.com"},
"",
},
"",
errors.New("jwt.Generate: no valid KeyPicker provided"),
},
{
parameters{
KeySlice{},
"BcRYPT",
"test.com",
"@laahs",
"standard",
"private",
[]string{"test.com"},
"",
},
"",
errors.New("jwt.Generate: no valid KeyPicker provided"),
},
{
parameters{
KeySlice{"klk"},
"BcRYPT",
"test.com",
"@laahs",
"standard",
"private",
[]string{"test.com"},
"",
},
"",
nil,
},
}
//fmt.Printf("tests : \n%v\n", tests)
for index, v := range tests {
_, err := Generate(v.params.keypicker, v.params.algo, v.params.issuer, v.params.username, v.params.role, v.params.accesslevel, v.params.audience, v.params.tokenId)
//fmt.Println(index, token)
if v.erreur != nil && err != nil {
if v.erreur.Error() != err.Error() {
t.Error("cas", index, ": errors mismatch,", "expected:", v.erreur, "received:", err)
}
} else if v.erreur == nil && err == nil {
} else {
t.Error("cas", index, ": errors mismatch,", "expected:", v.erreur, "received:", err)
}
}
}