|
|
@@ -122,6 +122,7 @@ func TestWebhookController_Enrich(t *testing.T) {
|
|
|
expectErr bool
|
|
|
expectTemplateData any
|
|
|
assertRequest func(t *testing.T, req *webhook.RequestBody)
|
|
|
+ assertError func(t *testing.T, err error)
|
|
|
}
|
|
|
tests := map[string]test{
|
|
|
"ok/no enriching webhooks": {
|
|
|
@@ -228,6 +229,28 @@ func TestWebhookController_Enrich(t *testing.T) {
|
|
|
responses: []*webhook.ResponseBody{{Allow: false}},
|
|
|
expectErr: true,
|
|
|
expectTemplateData: x509util.TemplateData{},
|
|
|
+ assertError: func(t *testing.T, err error) {
|
|
|
+ assert.Equal(t, ErrWebhookDenied, err)
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "deny/with error": {
|
|
|
+ ctl: &WebhookController{
|
|
|
+ client: http.DefaultClient,
|
|
|
+ webhooks: []*Webhook{{Name: "people", Kind: "ENRICHING"}},
|
|
|
+ TemplateData: x509util.TemplateData{},
|
|
|
+ },
|
|
|
+ ctx: withRequestID(t, context.Background(), "reqID"),
|
|
|
+ req: &webhook.RequestBody{},
|
|
|
+ responses: []*webhook.ResponseBody{{Allow: false, Error: &webhook.Error{
|
|
|
+ Code: "theCode", Message: "Some message",
|
|
|
+ }}},
|
|
|
+ expectErr: true,
|
|
|
+ expectTemplateData: x509util.TemplateData{},
|
|
|
+ assertError: func(t *testing.T, err error) {
|
|
|
+ assert.Equal(t, &webhook.Error{
|
|
|
+ Code: "theCode", Message: "Some message",
|
|
|
+ }, err)
|
|
|
+ },
|
|
|
},
|
|
|
"fail/with options": {
|
|
|
ctl: &WebhookController{
|
|
|
@@ -268,6 +291,9 @@ func TestWebhookController_Enrich(t *testing.T) {
|
|
|
if test.assertRequest != nil {
|
|
|
test.assertRequest(t, test.req)
|
|
|
}
|
|
|
+ if test.assertError != nil {
|
|
|
+ test.assertError(t, err)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -283,6 +309,7 @@ func TestWebhookController_Authorize(t *testing.T) {
|
|
|
responses []*webhook.ResponseBody
|
|
|
expectErr bool
|
|
|
assertRequest func(t *testing.T, req *webhook.RequestBody)
|
|
|
+ assertError func(t *testing.T, err error)
|
|
|
}
|
|
|
tests := map[string]test{
|
|
|
"ok/no enriching webhooks": {
|
|
|
@@ -346,6 +373,26 @@ func TestWebhookController_Authorize(t *testing.T) {
|
|
|
req: &webhook.RequestBody{},
|
|
|
responses: []*webhook.ResponseBody{{Allow: false}},
|
|
|
expectErr: true,
|
|
|
+ assertError: func(t *testing.T, err error) {
|
|
|
+ assert.Equal(t, ErrWebhookDenied, err)
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "deny/withError": {
|
|
|
+ ctl: &WebhookController{
|
|
|
+ client: http.DefaultClient,
|
|
|
+ webhooks: []*Webhook{{Name: "people", Kind: "AUTHORIZING"}},
|
|
|
+ },
|
|
|
+ ctx: withRequestID(t, context.Background(), "reqID"),
|
|
|
+ req: &webhook.RequestBody{},
|
|
|
+ responses: []*webhook.ResponseBody{{Allow: false, Error: &webhook.Error{
|
|
|
+ Code: "theCode", Message: "Some message",
|
|
|
+ }}},
|
|
|
+ expectErr: true,
|
|
|
+ assertError: func(t *testing.T, err error) {
|
|
|
+ assert.Equal(t, &webhook.Error{
|
|
|
+ Code: "theCode", Message: "Some message",
|
|
|
+ }, err)
|
|
|
+ },
|
|
|
},
|
|
|
"fail/with options": {
|
|
|
ctl: &WebhookController{
|
|
|
@@ -383,6 +430,9 @@ func TestWebhookController_Authorize(t *testing.T) {
|
|
|
if test.assertRequest != nil {
|
|
|
test.assertRequest(t, test.req)
|
|
|
}
|
|
|
+ if test.assertError != nil {
|
|
|
+ test.assertError(t, err)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|