mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-19 15:17:43 +01:00
Merge pull request #13017 from chlins/fix/webhook-verify-cert
fix(webhook): fix the verify cert logic of webhook endpoint
This commit is contained in:
commit
8846011571
@ -31,11 +31,3 @@ func init() {
|
|||||||
Transport: commonhttp.GetHTTPTransport(commonhttp.InsecureTransport),
|
Transport: commonhttp.GetHTTPTransport(commonhttp.InsecureTransport),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHTTPInstance ...
|
|
||||||
func GetHTTPInstance(insec bool) *http.Client {
|
|
||||||
if insec {
|
|
||||||
return httpHelper.clients[insecure]
|
|
||||||
}
|
|
||||||
return httpHelper.clients[secure]
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
package notification
|
package notification
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHttpHelper(t *testing.T) {
|
func TestHttpHelper(t *testing.T) {
|
||||||
c1 := GetHTTPInstance(true)
|
c1 := httpHelper.clients[insecure]
|
||||||
assert.NotNil(t, c1)
|
assert.NotNil(t, c1)
|
||||||
|
|
||||||
c2 := GetHTTPInstance(false)
|
c2 := httpHelper.clients[secure]
|
||||||
assert.NotNil(t, c2)
|
assert.NotNil(t, c2)
|
||||||
|
|
||||||
_, ok := httpHelper.clients["notExists"]
|
_, ok := httpHelper.clients["notExists"]
|
||||||
|
@ -93,13 +93,12 @@ func (sj *SlackJob) Run(ctx job.Context, params job.Parameters) error {
|
|||||||
func (sj *SlackJob) init(ctx job.Context, params map[string]interface{}) error {
|
func (sj *SlackJob) init(ctx job.Context, params map[string]interface{}) error {
|
||||||
sj.logger = ctx.GetLogger()
|
sj.logger = ctx.GetLogger()
|
||||||
|
|
||||||
// default use insecure transport
|
// default use secure transport
|
||||||
sj.client = GetHTTPInstance(true)
|
sj.client = httpHelper.clients[secure]
|
||||||
if v, ok := params["skip_cert_verify"]; ok {
|
if v, ok := params["skip_cert_verify"]; ok {
|
||||||
if insecure, ok := v.(bool); ok {
|
if skipCertVerify, ok := v.(bool); ok && skipCertVerify {
|
||||||
if insecure {
|
// if skip cert verify is true, it means not verify remote cert, use insecure client
|
||||||
sj.client = GetHTTPInstance(false)
|
sj.client = httpHelper.clients[insecure]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -71,13 +71,12 @@ func (wj *WebhookJob) init(ctx job.Context, params map[string]interface{}) error
|
|||||||
wj.logger = ctx.GetLogger()
|
wj.logger = ctx.GetLogger()
|
||||||
wj.ctx = ctx
|
wj.ctx = ctx
|
||||||
|
|
||||||
// default use insecure transport
|
// default use secure transport
|
||||||
wj.client = GetHTTPInstance(true)
|
wj.client = httpHelper.clients[secure]
|
||||||
if v, ok := params["skip_cert_verify"]; ok {
|
if v, ok := params["skip_cert_verify"]; ok {
|
||||||
if insecure, ok := v.(bool); ok {
|
if skipCertVerify, ok := v.(bool); ok && skipCertVerify {
|
||||||
if insecure {
|
// if skip cert verify is true, it means not verify remote cert, use insecure client
|
||||||
wj.client = GetHTTPInstance(false)
|
wj.client = httpHelper.clients[insecure]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user