-
Notifications
You must be signed in to change notification settings - Fork 110
/
config_test.go
257 lines (235 loc) · 9.06 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package config
import (
"bytes"
"reflect"
"testing"
"github.com/xordataexchange/crypt/backend/mock"
)
var pubring = `-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: GPGTools - https://gpgtools.org
mQENBFRClxIBCACjlm8e2mI5TmeigPuF4HJqNxc6AFLoCsE3MQ6VtdEVqidXZ06L
m7uIXYc3IfvAlID+1KrUJnO2IgLEMmXKSDI5aOch7VaeoXLKMt7yAX+N6DHaZl4l
eUGlfyIuBGD7FY2rv4hHo2wOmlq/chnNA4T7wb2XzeaAjvvoxcedMZ2npVimjwsl
MNDxSxYPlHR6lJgfYJHAxcWn7ZQJW2Kllv9jMQwzGqW4fxuKRhe20KStE/4+K9gL
GWv6OoE2gcGLoXliIMchHobY0GEvVx+YUv5jAItRSXq4ajYjFLtsWLz6FYtK9CoO
Va6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Yo
PjPtEpcNatIHbOna4KANxwv1Rmc6XDxWIB0RIlbdZDUhEdLovLLWGjm4J++Cnn2n
OFdZyyUxwYTjDCMWwsYrG2oPZ0Yle6fKEXX30E+dN9NSV1i+dJAYQi0am6augpg+
LmFWxQ6JPmUJVDay9wo6g2D4KbJQybSh8lmqpenHnKD1m/gCGadPmMl6Rw==
=FKbO
-----END PGP PUBLIC KEY BLOCK-----`
var secring = `
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: GPGTools - https://gpgtools.org
lQOYBFRClxIBCACjlm8e2mI5TmeigPuF4HJqNxc6AFLoCsE3MQ6VtdEVqidXZ06L
m7uIXYc3IfvAlID+1KrUJnO2IgLEMmXKSDI5aOch7VaeoXLKMt7yAX+N6DHaZl4l
eUGlfyIuBGD7FY2rv4hHo2wOmlq/chnNA4T7wb2XzeaAjvvoxcedMZ2npVimjwsl
MNDxSxYPlHR6lJgfYJHAxcWn7ZQJW2Kllv9jMQwzGqW4fxuKRhe20KStE/4+K9gL
GWv6OoE2gcGLoXliIMchHobY0GEvVx+YUv5jAItRSXq4ajYjFLtsWLz6FYtK9CoO
Va6T5EGqozKST/olW/FMmKLOTzpAilyoKB/HABEBAAEAB/wKvEBo68JJaiH2nJ9P
qas92YVZMD9Al2rBoU2zOR4nsqW9SybGQP89aOHgQNyBcV1xG79lh8Eii+MsQUsZ
IMQcV2GKV5sjyDWScQ8yHjNi5SuBs85sMs5s5XB2nkvyU6JF9J5QETicprgw2x84
AIn1buvvGTs4vD6/h7Hcri5fRimBvh+dcH/48nXPH56cZEPl/53tJt/lWwlfFBX1
phZMIPoHT1kihEt//Hn4raw30R/bm0CJP/PtiyRkNeebzJsIJXtzG30B8YZb6c/h
TtobA4F4ZWtEEwotPBFtx4clS/+2amc+PY+ZGTKXjzvQChaz50gvtSUp9ns9X/G+
T/vRBADC3dNGE2Ut8DRE2C/MQ7DdZdHdxaHJSMV+08xI/OSDOxp3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RDVEaE
Nkbi/Aj3Shh2+w/jeYsUgrJkZY/UeoJt/mdUO1+loRoqTdlOOJLpPcyF6WzQQU+J
AR8EGAEKAAkFAlRClxICGwwACgkQPE8pgYSADbJFTwf/d6XIv8/BxaP5TB12FxRX
evOVenYexR6O0rXDKFkP54LHSh2uaJbjLHevF0tuiNLFWq9RPhVjC012OLdo+2yg
EFwNfikd1SMbUIkuZ6Nu2MvCdrpAwbcvLgeoe8bqf1B6EIb31/OxCmtHujpVw6cS
AnpAVyYoPjPtEpcNatIHbOna4KANxwv1Rmc6XDxWIB0RIlbdZDUhEdLovLLWGjm4
J++Cnn2nOFdZyyUxwYTjDCMWwsYrG2oPZ0Yle6fKEXX30E+dN9NSV1i+dJAYQi0a
m6augpg+LmFWxQ6JPmUJVDay9wo6g2D4KbJQybSh8lmqpenHnKD1m/gCGadPmMl6
Rw==
=RvPL
-----END PGP PRIVATE KEY BLOCK-----
`
func Test_StandardSet_BasePath(t *testing.T) {
key := "foo"
value := []byte("bar")
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewStandardConfigManager(store)
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
err = cm.Set(key, value)
if err != nil {
t.Errorf("Error adding key: %s\n", err.Error())
}
}
func Test_StandardGet_BasePath(t *testing.T) {
key := "foo"
value := []byte("bar")
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewStandardConfigManager(store)
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
storedValue, err := cm.Get(key)
if err != nil {
t.Errorf("Error getting key: %s\n", err.Error())
}
if !reflect.DeepEqual(storedValue, value) {
t.Errorf("Two values did not match: %s\n", err.Error())
}
}
func Test_StandardGet_AlternatePath_NoKey(t *testing.T) {
key := "doesnotexist"
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewStandardConfigManager(store)
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
_, err = cm.Get(key)
if err == nil {
t.Errorf("Did not get expected error\n")
}
}
func Test_StandardWatch_BasePath(t *testing.T) {
key := "foo"
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewStandardConfigManager(store)
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
timeout := make(chan bool, 0)
resp := cm.Watch(key, timeout)
select {
case r := <-resp:
if r.Error != nil {
t.Errorf("Error watching value: %s\n", r.Error.Error())
}
}
}
func Test_Set_BasePath(t *testing.T) {
key := "foo_enc"
value := []byte("bar_enc")
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewConfigManager(store, bytes.NewBufferString(pubring))
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
err = cm.Set(key, value)
if err != nil {
t.Errorf("Error adding key: %s\n", err.Error())
}
}
func Test_Get_BasePath(t *testing.T) {
key := "foo_enc"
value := []byte("bar_enc")
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewConfigManager(store, bytes.NewBufferString(secring))
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
storedValue, err := cm.Get(key)
if err != nil {
t.Errorf("Error getting key: %s\n", err.Error())
}
if !reflect.DeepEqual(storedValue, value) {
t.Errorf("Two values did not match: %s\n", err.Error())
}
}
func Test_Get_AlternatePath_NoKey(t *testing.T) {
key := "doesnotexist_enc"
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewConfigManager(store, bytes.NewBufferString(secring))
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
_, err = cm.Get(key)
if err == nil {
t.Errorf("Did not get expected error\n")
}
}
func Test_Watch_BasePath(t *testing.T) {
key := "foo_enc"
store, err := mock.New([]string{})
if err != nil {
t.Errorf("Error creating backend: %s\n", err.Error())
}
cm, err := NewConfigManager(store, bytes.NewBufferString(secring))
if err != nil {
t.Errorf("Error creating config manager: %s\n", err.Error())
}
timeout := make(chan bool, 0)
resp := cm.Watch(key, timeout)
select {
case r := <-resp:
if r.Error != nil {
t.Errorf("Error watching value: %s\n", r.Error.Error())
}
}
}