-
Notifications
You must be signed in to change notification settings - Fork 4
/
adapter_test.go
124 lines (116 loc) · 2.81 KB
/
adapter_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
package adapter
import (
"testing"
)
func TestNewServer(t *testing.T) {
String := func(s string) *string {
return &s
}
dummyProvider := map[string]map[string]interface{}{"development": {}}
testcases := []struct {
err bool
c Config
}{
// fail with "provider configure not found" error.
{
err: true,
c: Config{},
},
// test "the session authentication key is empty" error.
{
err: false, // just warn in running.
c: Config{
Providers: dummyProvider,
},
},
{
err: true, // fail in testing the config.
c: Config{
Providers: dummyProvider,
ConfigTest: true,
},
},
// check session authentication key length.
{
err: false, // the secret is 32 bytes, and it's valid.
c: Config{
Providers: dummyProvider,
Secrets: []*string{String("dummy-session-authentication-key")},
},
},
{
err: true, // the secret is 33 bytes, and it's invalid.
c: Config{
Providers: dummyProvider,
Secrets: []*string{String("dummy-session-authentication-key+")},
},
},
{
err: false, // valid hex string
c: Config{
Providers: dummyProvider,
Secrets: []*string{String("8e26ea01bd8805788bcb4660c7c15692e4771b5d6a22635eede025ca544ad4a00bcd17295f1ca8a5d573899fc7a641a25f488c9a5e839368cd79c2ffe1028031")},
},
},
{
err: true, // invalid hex string
c: Config{
Providers: dummyProvider,
Secrets: []*string{String("INVALID-HEX-05788bcb4660c7c15692e4771b5d6a22635eede025ca544ad4a00bcd17295f1ca8a5d573899fc7a641a25f488c9a5e839368cd79c2ffe1028031")},
},
},
// check session encryption key length.
{
err: false, // the secret is 32 bytes, and it's valid.
c: Config{
Providers: dummyProvider,
Secrets: []*string{nil, String("**dummy-session-encryption-key**")},
},
},
{
err: true, // the secret is 33 bytes, and it's invalid.
c: Config{
Providers: dummyProvider,
Secrets: []*string{nil, String("dummy-session-encryption-key")},
},
},
{
err: false, // valid hex string
c: Config{
Providers: dummyProvider,
Secrets: []*string{nil, String("5c9ea31b400099a521f934f8a4c2c88758ca59e0a34479775aea86404921658e")},
},
},
{
err: true, // invalid hex string
c: Config{
Providers: dummyProvider,
Secrets: []*string{nil, String("INVALID-HEX-5c9ea31b400099a521f934f8a4c2c88758ca59e0a34479775aea")},
},
},
// invalid duration.
{
err: true,
c: Config{
Providers: dummyProvider,
AppRefreshInterval: "hoge",
},
},
}
for i, tc := range testcases {
s, err := NewServer(tc.c)
t.Logf("%d %#v: %v, %v", i, tc.c, s, err)
if tc.err {
if err == nil {
t.Errorf("%v: expected error, got no error", tc.c)
}
} else {
if err != nil {
t.Errorf("%v: expected no error, got %v", tc.c, err)
}
}
if err != nil {
continue
}
}
}