diff --git a/internal/interactor/interactor.go b/internal/interactor/interactor.go index bc3d7d8a..9c491777 100644 --- a/internal/interactor/interactor.go +++ b/internal/interactor/interactor.go @@ -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) @@ -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" +} diff --git a/internal/interactor/interactor_test.go b/internal/interactor/interactor_test.go index 114947df..63cdf094 100644 --- a/internal/interactor/interactor_test.go +++ b/internal/interactor/interactor_test.go @@ -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) + } + }) +}