forked from gofiber/jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
84 lines (68 loc) · 1.53 KB
/
config_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
package jwtware
import (
"testing"
)
func TestPanicOnMissingConfiguration(t *testing.T) {
t.Parallel()
defer func() {
// Assert
if err := recover(); err == nil {
t.Fatalf("Middleware should panic on missing configuration")
}
}()
// Arrange
config := make([]Config, 0)
// Act
makeCfg(config)
}
func TestDefaultConfiguration(t *testing.T) {
t.Parallel()
defer func() {
// Assert
if err := recover(); err != nil {
t.Fatalf("Middleware should not panic")
}
}()
// Arrange
config := append(make([]Config, 0), Config{
SigningKey: "",
})
// Act
cfg := makeCfg(config)
// Assert
if cfg.SigningMethod != HS256 {
t.Fatalf("Default signing method should be 'HS256'")
}
if cfg.ContextKey != "user" {
t.Fatalf("Default context key should be 'user'")
}
if cfg.Claims == nil {
t.Fatalf("Default claims should not be 'nil'")
}
if cfg.TokenLookup != defaultTokenLookup {
t.Fatalf("Default token lookup should be '%v'", defaultTokenLookup)
}
if cfg.AuthScheme != "Bearer" {
t.Fatalf("Default auth scheme should be 'Bearer'")
}
}
func TestExtractorsInitialization(t *testing.T) {
t.Parallel()
defer func() {
// Assert
if err := recover(); err != nil {
t.Fatalf("Middleware should not panic")
}
}()
// Arrange
cfg := Config{
SigningKey: "",
TokenLookup: defaultTokenLookup + ",query:token,param:token,cookie:token,something:something",
}
// Act
extractors := cfg.getExtractors()
// Assert
if len(extractors) != 4 {
t.Fatalf("Extractors should not be created for invalid lookups")
}
}