From 6de7bdb75308701b07e81f5b21c067b49ce4f85e Mon Sep 17 00:00:00 2001 From: Kamuri Amorim <27641366+kamuridesu@users.noreply.github.com> Date: Tue, 27 Jun 2023 06:04:09 -0300 Subject: [PATCH] fix: add gitlab.SystemHookEvents to support Gitlab system events (#12547) * fix: add gitlab.SystemHookEvents to support Gitlab system events Closes [ISSUE #9625] Signed-off-by: Kamuri Amorim * tests(gitlab.SystemHookEvents): fix tests for gitlab.SystemHookEvents Signed-off-by: Kamuri Amorim --------- Signed-off-by: Kamuri Amorim Co-authored-by: pasha-codefresh --- util/webhook/webhook.go | 2 +- util/webhook/webhook_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/util/webhook/webhook.go b/util/webhook/webhook.go index b5b14c3e7d646..c47323f2cdbbb 100644 --- a/util/webhook/webhook.go +++ b/util/webhook/webhook.go @@ -441,7 +441,7 @@ func (a *ArgoCDWebhookHandler) Handler(w http.ResponseWriter, r *http.Request) { log.WithField(common.SecurityField, common.SecurityHigh).Infof("GitHub webhook HMAC verification failed") } case r.Header.Get("X-Gitlab-Event") != "": - payload, err = a.gitlab.Parse(r, gitlab.PushEvents, gitlab.TagEvents) + payload, err = a.gitlab.Parse(r, gitlab.PushEvents, gitlab.TagEvents, gitlab.SystemHookEvents) if errors.Is(err, gitlab.ErrGitLabTokenVerificationFailed) { log.WithField(common.SecurityField, common.SecurityHigh).Infof("GitLab webhook token verification failed") } diff --git a/util/webhook/webhook_test.go b/util/webhook/webhook_test.go index efd68fe25b9b9..899c3ecb73203 100644 --- a/util/webhook/webhook_test.go +++ b/util/webhook/webhook_test.go @@ -336,6 +336,22 @@ func TestGitLabPushEvent(t *testing.T) { hook.Reset() } +func TestGitLabSystemEvent(t *testing.T) { + hook := test.NewGlobal() + h := NewMockHandler(nil, []string{}) + req := httptest.NewRequest(http.MethodPost, "/api/webhook", nil) + req.Header.Set("X-Gitlab-Event", "System Hook") + eventJSON, err := os.ReadFile("testdata/gitlab-event.json") + assert.NoError(t, err) + req.Body = io.NopCloser(bytes.NewReader(eventJSON)) + w := httptest.NewRecorder() + h.Handler(w, req) + assert.Equal(t, w.Code, http.StatusOK) + expectedLogResult := "Received push event repo: https://gitlab/group/name, revision: master, touchedHead: true" + assert.Equal(t, expectedLogResult, hook.LastEntry().Message) + hook.Reset() +} + func TestInvalidMethod(t *testing.T) { hook := test.NewGlobal() h := NewMockHandler(nil, []string{})