Skip to content

Commit

Permalink
fixes gitlab hook ssl verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Nevin committed Oct 8, 2019
1 parent 71b214b commit 4bb8a23
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scm/driver/gitlab/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *repositoryService) CreateHook(ctx context.Context, repo string, input *
params.Set("token", input.Secret)
}
if input.SkipVerify {
params.Set("enable_ssl_verification", "true")
params.Set("enable_ssl_verification", "false")
}
if input.Events.Branch {
// no-op
Expand Down
43 changes: 41 additions & 2 deletions scm/driver/gitlab/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ func TestRepositoryHookCreate(t *testing.T) {

gock.New("https://gitlab.com").
Post("/api/v4/projects/diaspora/diaspora/hooks").
MatchParam("enable_ssl_verification", "true").
MatchParam("token", "topsecret").
MatchParam("url", "https://ci.example.com/hook").
Reply(201).
Expand All @@ -315,7 +314,7 @@ func TestRepositoryHookCreate(t *testing.T) {
Name: "drone",
Target: "https://ci.example.com/hook",
Secret: "topsecret",
SkipVerify: true,
SkipVerify: false,
}

client := NewDefault()
Expand All @@ -338,6 +337,46 @@ func TestRepositoryHookCreate(t *testing.T) {
t.Run("Rate", testRate(res))
}

func TestRepositoryHookCreate_SkipVerification(t *testing.T) {
defer gock.Off()

gock.New("https://gitlab.com").
Post("/api/v4/projects/diaspora/diaspora/hooks").
MatchParam("enable_ssl_verification", "false").
MatchParam("token", "topsecret").
MatchParam("url", "https://ci.example.com/hook").
Reply(201).
Type("application/json").
SetHeaders(mockHeaders).
File("testdata/hook_skip_verification.json")

in := &scm.HookInput{
Name: "drone",
Target: "https://ci.example.com/hook",
Secret: "topsecret",
SkipVerify: true,
}

client := NewDefault()
got, res, err := client.Repositories.CreateHook(context.Background(), "diaspora/diaspora", in)
if err != nil {
t.Error(err)
return
}

want := new(scm.Hook)
raw, _ := ioutil.ReadFile("testdata/hook_skip_verification.json.golden")
json.Unmarshal(raw, want)

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}

t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
}

func TestConvertState(t *testing.T) {
tests := []struct {
src string
Expand Down
15 changes: 15 additions & 0 deletions scm/driver/gitlab/testdata/hook_skip_verification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": 1,
"url": "http://example.com/hook",
"project_id": 3,
"push_events": true,
"issues_events": true,
"merge_requests_events": true,
"tag_push_events": true,
"note_events": true,
"job_events": true,
"pipeline_events": true,
"wiki_page_events": true,
"enable_ssl_verification": false,
"created_at": "2012-10-12T17:04:47Z"
}
14 changes: 14 additions & 0 deletions scm/driver/gitlab/testdata/hook_skip_verification.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ID": "1",
"Name": "",
"Target": "http://example.com/hook",
"Events": [
"issues",
"tag",
"push",
"comment",
"merge"
],
"Active": true,
"SkipVerify": true
}

0 comments on commit 4bb8a23

Please sign in to comment.