@@ -16,6 +16,7 @@ import (
1616 auth_model "code.gitea.io/gitea/models/auth"
1717 "code.gitea.io/gitea/models/repo"
1818 "code.gitea.io/gitea/models/unittest"
19+ "code.gitea.io/gitea/models/webhook"
1920 "code.gitea.io/gitea/modules/gitrepo"
2021 "code.gitea.io/gitea/modules/json"
2122 api "code.gitea.io/gitea/modules/structs"
@@ -66,6 +67,19 @@ func testAPICreateWebhookForRepo(t *testing.T, session *TestSession, userName, r
6667 MakeRequest (t , req , http .StatusCreated )
6768}
6869
70+ func testCreateWebhookForRepo (t * testing.T , session * TestSession , webhookType , userName , repoName , url , eventKind string ) {
71+ csrf := GetUserCSRFToken (t , session )
72+ req := NewRequestWithValues (t , "POST" , "/" + userName + "/" + repoName + "/settings/hooks/" + webhookType + "/new" , map [string ]string {
73+ "_csrf" : csrf ,
74+ "payload_url" : url ,
75+ "events" : eventKind ,
76+ "active" : "true" ,
77+ "content_type" : fmt .Sprintf ("%d" , webhook .ContentTypeJSON ),
78+ "http_method" : "POST" ,
79+ })
80+ session .MakeRequest (t , req , http .StatusSeeOther )
81+ }
82+
6983func testAPICreateWebhookForOrg (t * testing.T , session * TestSession , userName , url , event string ) {
7084 token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeAll )
7185 req := NewRequestWithJSON (t , "POST" , "/api/v1/orgs/" + userName + "/hooks" , api.CreateHookOption {
@@ -562,3 +576,28 @@ func Test_WebhookStatus(t *testing.T) {
562576 assert .EqualValues (t , commitID , payloads [0 ].SHA )
563577 })
564578}
579+
580+ func Test_WebhookStatus_NoWrongTrigger (t * testing.T ) {
581+ var trigger string
582+ provider := newMockWebhookProvider (func (r * http.Request ) {
583+ assert .NotContains (t , r .Header ["X-Github-Event-Type" ], "status" , "X-GitHub-Event-Type should not contain status" )
584+ assert .NotContains (t , r .Header ["X-Gitea-Event-Type" ], "status" , "X-Gitea-Event-Type should not contain status" )
585+ assert .NotContains (t , r .Header ["X-Gogs-Event-Type" ], "status" , "X-Gogs-Event-Type should not contain status" )
586+ trigger = "push"
587+ }, http .StatusOK )
588+ defer provider .Close ()
589+
590+ onGiteaRun (t , func (t * testing.T , giteaURL * url.URL ) {
591+ // 1. create a new webhook with special webhook for repo1
592+ session := loginUser (t , "user2" )
593+
594+ // create a push_only webhook from web UI
595+ testCreateWebhookForRepo (t , session , "gitea" , "user2" , "repo1" , provider .URL (), "push_only" )
596+
597+ // 2. trigger the webhook with a push action
598+ testCreateFile (t , session , "user2" , "repo1" , "master" , "test_webhook_push.md" , "# a test file for webhook push" )
599+
600+ // 3. validate the webhook is triggered with right event
601+ assert .EqualValues (t , "push" , trigger )
602+ })
603+ }
0 commit comments