-
Notifications
You must be signed in to change notification settings - Fork 17
/
hmac_test.go
39 lines (31 loc) · 796 Bytes
/
hmac_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
package jwt
import (
"testing"
)
var testToken = []byte("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImthdGFyYXMifQ.HX22uANEy1qEG0m0utORW4YYfyNeuG9FzvRPMxpSaTc")
func TestEncodeDecodeTokenHMAC(t *testing.T) {
key := testSecret
expectedToken := testToken
testEncodeDecodeToken(t, HS256, key, key, expectedToken)
}
func TestMustLoadHMAC(t *testing.T) {
catchPanic(t, false, func() {
MustLoadHMAC("./_testfiles/hmac.key")
MustLoadHMAC(string(testSecret))
})
}
func catchPanic(t *testing.T, shouldPanic bool, fn func()) {
t.Helper()
got := false
var val interface{}
prevHandler := panicHandler
panicHandler = func(v interface{}) {
got = true
val = v
}
fn()
panicHandler = prevHandler
if shouldPanic != got {
t.Fatalf("expected panic: %v: %v", got, val)
}
}