Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 797fe9f

Browse files
author
Noah Lee
authored
Fix the bug of 'WebhookSSL' (#370)
1 parent 3088d95 commit 797fe9f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Diff for: internal/interactor/interactor.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func NewInteractor(c *InteractorConfig) *Interactor {
8484
i.RepoInteractor = &RepoInteractor{
8585
service: i.common,
8686
WebhookURL: c.BuildWebhookURL(),
87-
WebhookSSL: c.ServerProxyProto == "https",
87+
WebhookSSL: c.CheckWebhookSSL(),
8888
WebhookSecret: c.WebhookSecret,
8989
}
9090
i.ReviewInteractor = (*ReviewInteractor)(i.common)
@@ -120,3 +120,11 @@ func (c *InteractorConfig) BuildWebhookURL() string {
120120

121121
return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
122122
}
123+
124+
func (c *InteractorConfig) CheckWebhookSSL() bool {
125+
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
126+
return c.ServerProxyProto == "https"
127+
}
128+
129+
return c.ServerProto == "https"
130+
}

Diff for: internal/interactor/interactor_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,28 @@ func TestInteractorConfig_BuildWebhookURL(t *testing.T) {
2929
}
3030
})
3131
}
32+
33+
func TestInteractorConfig_CheckWebhookURL(t *testing.T) {
34+
t.Run("Return true when the proxy has SSL verification.", func(t *testing.T) {
35+
c := &i.InteractorConfig{
36+
ServerProxyHost: "hook.cloud.gitploy.io",
37+
ServerProxyProto: "https",
38+
ServerProto: "http",
39+
}
40+
wanted := true
41+
if ret := c.CheckWebhookSSL(); ret != wanted {
42+
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
43+
}
44+
})
45+
46+
t.Run("Return true when the server has SSL verification.", func(t *testing.T) {
47+
c := &i.InteractorConfig{
48+
ServerHost: "cloud.gitploy.io",
49+
ServerProto: "https",
50+
}
51+
wanted := true
52+
if ret := c.CheckWebhookSSL(); ret != wanted {
53+
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
54+
}
55+
})
56+
}

0 commit comments

Comments
 (0)