Skip to content

Commit

Permalink
fix: add gitlab.SystemHookEvents to support Gitlab system events (arg…
Browse files Browse the repository at this point in the history
…oproj#12547)

* fix: add gitlab.SystemHookEvents to support Gitlab system events

Closes [ISSUE argoproj#9625]

Signed-off-by: Kamuri Amorim <myk.gata14@gmail.com>

* tests(gitlab.SystemHookEvents): fix tests for gitlab.SystemHookEvents

Signed-off-by: Kamuri Amorim <myk.gata14@gmail.com>

---------

Signed-off-by: Kamuri Amorim <myk.gata14@gmail.com>
Co-authored-by: pasha-codefresh <pavel@codefresh.io>
  • Loading branch information
2 people authored and xiaowu.zhu committed Aug 9, 2023
1 parent 446c728 commit 6de7bdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
16 changes: 16 additions & 0 deletions util/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down

0 comments on commit 6de7bdb

Please sign in to comment.