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

Fix the bug of WebhookSSL #370

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/interactor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewInteractor(c *InteractorConfig) *Interactor {
i.RepoInteractor = &RepoInteractor{
service: i.common,
WebhookURL: c.BuildWebhookURL(),
WebhookSSL: c.ServerProxyProto == "https",
WebhookSSL: c.CheckWebhookSSL(),
WebhookSecret: c.WebhookSecret,
}
i.ReviewInteractor = (*ReviewInteractor)(i.common)
Expand Down Expand Up @@ -120,3 +120,11 @@ func (c *InteractorConfig) BuildWebhookURL() string {

return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
}

func (c *InteractorConfig) CheckWebhookSSL() bool {
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
return c.ServerProxyProto == "https"
}

return c.ServerProto == "https"
}
25 changes: 25 additions & 0 deletions internal/interactor/interactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@ func TestInteractorConfig_BuildWebhookURL(t *testing.T) {
}
})
}

func TestInteractorConfig_CheckWebhookURL(t *testing.T) {
t.Run("Return true when the proxy has SSL verification.", func(t *testing.T) {
c := &i.InteractorConfig{
ServerProxyHost: "hook.cloud.gitploy.io",
ServerProxyProto: "https",
ServerProto: "http",
}
wanted := true
if ret := c.CheckWebhookSSL(); ret != wanted {
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
}
})

t.Run("Return true when the server has SSL verification.", func(t *testing.T) {
c := &i.InteractorConfig{
ServerHost: "cloud.gitploy.io",
ServerProto: "https",
}
wanted := true
if ret := c.CheckWebhookSSL(); ret != wanted {
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
}
})
}