@@ -122,6 +122,7 @@ func TestWebhookController_Enrich(t *testing.T) {
122
122
expectErr bool
123
123
expectTemplateData any
124
124
assertRequest func (t * testing.T , req * webhook.RequestBody )
125
+ assertError func (t * testing.T , err error )
125
126
}
126
127
tests := map [string ]test {
127
128
"ok/no enriching webhooks" : {
@@ -228,6 +229,28 @@ func TestWebhookController_Enrich(t *testing.T) {
228
229
responses : []* webhook.ResponseBody {{Allow : false }},
229
230
expectErr : true ,
230
231
expectTemplateData : x509util.TemplateData {},
232
+ assertError : func (t * testing.T , err error ) {
233
+ assert .Equal (t , ErrWebhookDenied , err )
234
+ },
235
+ },
236
+ "deny/with error" : {
237
+ ctl : & WebhookController {
238
+ client : http .DefaultClient ,
239
+ webhooks : []* Webhook {{Name : "people" , Kind : "ENRICHING" }},
240
+ TemplateData : x509util.TemplateData {},
241
+ },
242
+ ctx : withRequestID (t , context .Background (), "reqID" ),
243
+ req : & webhook.RequestBody {},
244
+ responses : []* webhook.ResponseBody {{Allow : false , Error : & webhook.Error {
245
+ Code : "theCode" , Message : "Some message" ,
246
+ }}},
247
+ expectErr : true ,
248
+ expectTemplateData : x509util.TemplateData {},
249
+ assertError : func (t * testing.T , err error ) {
250
+ assert .Equal (t , & webhook.Error {
251
+ Code : "theCode" , Message : "Some message" ,
252
+ }, err )
253
+ },
231
254
},
232
255
"fail/with options" : {
233
256
ctl : & WebhookController {
@@ -268,6 +291,9 @@ func TestWebhookController_Enrich(t *testing.T) {
268
291
if test .assertRequest != nil {
269
292
test .assertRequest (t , test .req )
270
293
}
294
+ if test .assertError != nil {
295
+ test .assertError (t , err )
296
+ }
271
297
})
272
298
}
273
299
}
@@ -283,6 +309,7 @@ func TestWebhookController_Authorize(t *testing.T) {
283
309
responses []* webhook.ResponseBody
284
310
expectErr bool
285
311
assertRequest func (t * testing.T , req * webhook.RequestBody )
312
+ assertError func (t * testing.T , err error )
286
313
}
287
314
tests := map [string ]test {
288
315
"ok/no enriching webhooks" : {
@@ -346,6 +373,26 @@ func TestWebhookController_Authorize(t *testing.T) {
346
373
req : & webhook.RequestBody {},
347
374
responses : []* webhook.ResponseBody {{Allow : false }},
348
375
expectErr : true ,
376
+ assertError : func (t * testing.T , err error ) {
377
+ assert .Equal (t , ErrWebhookDenied , err )
378
+ },
379
+ },
380
+ "deny/withError" : {
381
+ ctl : & WebhookController {
382
+ client : http .DefaultClient ,
383
+ webhooks : []* Webhook {{Name : "people" , Kind : "AUTHORIZING" }},
384
+ },
385
+ ctx : withRequestID (t , context .Background (), "reqID" ),
386
+ req : & webhook.RequestBody {},
387
+ responses : []* webhook.ResponseBody {{Allow : false , Error : & webhook.Error {
388
+ Code : "theCode" , Message : "Some message" ,
389
+ }}},
390
+ expectErr : true ,
391
+ assertError : func (t * testing.T , err error ) {
392
+ assert .Equal (t , & webhook.Error {
393
+ Code : "theCode" , Message : "Some message" ,
394
+ }, err )
395
+ },
349
396
},
350
397
"fail/with options" : {
351
398
ctl : & WebhookController {
@@ -383,6 +430,9 @@ func TestWebhookController_Authorize(t *testing.T) {
383
430
if test .assertRequest != nil {
384
431
test .assertRequest (t , test .req )
385
432
}
433
+ if test .assertError != nil {
434
+ test .assertError (t , err )
435
+ }
386
436
})
387
437
}
388
438
}
0 commit comments