webhook deliver: keep Bearer prefix in history

This commit is contained in:
oliverpool 2024-04-09 10:09:00 +02:00
parent 36f05e6f4e
commit 5d45545ca1
2 changed files with 8 additions and 2 deletions

View file

@ -78,7 +78,13 @@ func Deliver(ctx context.Context, t *webhook_model.HookTask) error {
} }
if authorization != "" { if authorization != "" {
req.Header.Set("Authorization", authorization) req.Header.Set("Authorization", authorization)
t.RequestInfo.Headers["Authorization"] = "******" redacted := "******"
if strings.HasPrefix(authorization, "Bearer ") {
redacted = "Bearer " + redacted
} else if strings.HasPrefix(authorization, "Basic ") {
redacted = "Basic " + redacted
}
t.RequestInfo.Headers["Authorization"] = redacted
} }
t.ResponseInfo = &webhook_model.HookResponse{ t.ResponseInfo = &webhook_model.HookResponse{

View file

@ -132,7 +132,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
} }
assert.True(t, hookTask.IsSucceed) assert.True(t, hookTask.IsSucceed)
assert.Equal(t, "******", hookTask.RequestInfo.Headers["Authorization"]) assert.Equal(t, "Bearer ******", hookTask.RequestInfo.Headers["Authorization"])
} }
func TestWebhookDeliverHookTask(t *testing.T) { func TestWebhookDeliverHookTask(t *testing.T) {