@@ -2,6 +2,7 @@ package apiclient
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"encoding/json"
6
7
"fmt"
7
8
"io"
@@ -72,6 +73,7 @@ func initBasicMuxMock(t *testing.T, mux *http.ServeMux, path string) {
72
73
*/
73
74
func TestWatcherRegister (t * testing.T ) {
74
75
ctx := t .Context ()
76
+
75
77
log .SetLevel (log .DebugLevel )
76
78
77
79
mux , urlx , teardown := setup ()
@@ -110,6 +112,7 @@ func TestWatcherRegister(t *testing.T) {
110
112
111
113
func TestWatcherAuth (t * testing.T ) {
112
114
ctx := t .Context ()
115
+
113
116
log .SetLevel (log .DebugLevel )
114
117
115
118
mux , urlx , teardown := setup ()
@@ -122,22 +125,29 @@ func TestWatcherAuth(t *testing.T) {
122
125
apiURL , err := url .Parse (urlx + "/" )
123
126
require .NoError (t , err )
124
127
128
+ updateScenario := func (_ context.Context ) ([]string , error ) {
129
+ return []string {"crowdsecurity/test" }, nil
130
+ }
131
+
125
132
// ok auth
126
133
clientConfig := & Config {
127
- MachineID : "test_login" ,
128
- Password : "test_password" ,
129
- URL : apiURL ,
130
- VersionPrefix : "v1" ,
131
- Scenarios : [] string { "crowdsecurity/test" } ,
134
+ MachineID : "test_login" ,
135
+ Password : "test_password" ,
136
+ URL : apiURL ,
137
+ VersionPrefix : "v1" ,
138
+ UpdateScenario : updateScenario ,
132
139
}
133
140
134
141
client , err := NewClient (clientConfig )
135
142
require .NoError (t , err )
136
143
144
+ scenarios , err := clientConfig .UpdateScenario (ctx )
145
+ require .NoError (t , err )
146
+
137
147
_ , _ , err = client .Auth .AuthenticateWatcher (ctx , models.WatcherAuthRequest {
138
148
MachineID : & clientConfig .MachineID ,
139
149
Password : & clientConfig .Password ,
140
- Scenarios : clientConfig . Scenarios ,
150
+ Scenarios : scenarios ,
141
151
})
142
152
require .NoError (t , err )
143
153
@@ -171,6 +181,7 @@ func TestWatcherAuth(t *testing.T) {
171
181
172
182
func TestWatcherUnregister (t * testing.T ) {
173
183
ctx := t .Context ()
184
+
174
185
log .SetLevel (log .DebugLevel )
175
186
176
187
mux , urlx , teardown := setup ()
@@ -205,12 +216,16 @@ func TestWatcherUnregister(t *testing.T) {
205
216
apiURL , err := url .Parse (urlx + "/" )
206
217
require .NoError (t , err )
207
218
219
+ updateScenario := func (_ context.Context ) ([]string , error ) {
220
+ return []string {"crowdsecurity/test" }, nil
221
+ }
222
+
208
223
mycfg := & Config {
209
- MachineID : "test_login" ,
210
- Password : "test_password" ,
211
- URL : apiURL ,
212
- VersionPrefix : "v1" ,
213
- Scenarios : [] string { "crowdsecurity/test" } ,
224
+ MachineID : "test_login" ,
225
+ Password : "test_password" ,
226
+ URL : apiURL ,
227
+ VersionPrefix : "v1" ,
228
+ UpdateScenario : updateScenario ,
214
229
}
215
230
216
231
client , err := NewClient (mycfg )
@@ -224,6 +239,7 @@ func TestWatcherUnregister(t *testing.T) {
224
239
225
240
func TestWatcherEnroll (t * testing.T ) {
226
241
ctx := t .Context ()
242
+
227
243
log .SetLevel (log .DebugLevel )
228
244
229
245
mux , urlx , teardown := setup ()
@@ -260,12 +276,16 @@ func TestWatcherEnroll(t *testing.T) {
260
276
apiURL , err := url .Parse (urlx + "/" )
261
277
require .NoError (t , err )
262
278
279
+ updateScenario := func (_ context.Context ) ([]string , error ) {
280
+ return []string {"crowdsecurity/test" }, nil
281
+ }
282
+
263
283
mycfg := & Config {
264
- MachineID : "test_login" ,
265
- Password : "test_password" ,
266
- URL : apiURL ,
267
- VersionPrefix : "v1" ,
268
- Scenarios : [] string { "crowdsecurity/test" } ,
284
+ MachineID : "test_login" ,
285
+ Password : "test_password" ,
286
+ URL : apiURL ,
287
+ VersionPrefix : "v1" ,
288
+ UpdateScenario : updateScenario ,
269
289
}
270
290
271
291
client , err := NewClient (mycfg )
0 commit comments