重构:完成架构一致性整改与生命周期收口
This commit is contained in:
1 parent
55904cc409
commit
9eb6be2875
344 files changed
+15961
-13926
No files matched your search
@@ -17,21 +17,21 @@ var sensitiveValuePattern = regexp.MustCompile(`(?i)(\b(?:cookie|set-cookie|x5se
|
||||
var embeddedURLPattern = regexp.MustCompile(`(?i)\b(?:https?|wss?|mysql|postgres(?:ql)?):\/\/[^\s"'<>]+`)
|
||||
|
||||
// ID returns a short stable fingerprint for a sensitive identifier.
|
||||
// ID 负责标识相关处理。
|
||||
// ID 封装标识业务协调。
|
||||
func ID(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
// sum 保存sum,供当前处理流程使用
|
||||
// sum 用于本次流程后续判断的sum
|
||||
sum := sha256.Sum256([]byte(s))
|
||||
return hex.EncodeToString(sum[:])[:12]
|
||||
}
|
||||
|
||||
// URL returns origin + path for URLs that may contain session tokens.
|
||||
// URL 负责URL相关处理。
|
||||
// URL 封装URL业务协调。
|
||||
func URL(raw string) string {
|
||||
// u、err 保存u、err,供当前处理流程使用
|
||||
// u、err 用于本次流程后续判断的u、err
|
||||
u, err := url.Parse(strings.TrimSpace(raw))
|
||||
if err != nil || u.Scheme == "" || u.Host == "" {
|
||||
return "<redacted>"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestRedactionHelpers 负责TestRedactionHelpers相关处理。
|
||||
// TestRedactionHelpers 封装TestRedactionHelpers业务协调。
|
||||
func TestRedactionHelpers(t *testing.T) {
|
||||
if ID(" secret ") != ID("secret") || len(ID("secret")) != 12 {
|
||||
t.Fatal("ID should be trimmed, stable, and short")
|
||||
@@ -14,11 +14,11 @@ func TestRedactionHelpers(t *testing.T) {
|
||||
if ID("") != "" {
|
||||
t.Fatal("empty ID should remain empty")
|
||||
}
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := URL("https://example.com/path?q=token#secret"); got != "https://example.com/path" {
|
||||
t.Fatalf("URL leaked query or fragment: %q", got)
|
||||
}
|
||||
if // got 保存got,供当前处理流程使用
|
||||
if // got 用于本次流程后续判断的got
|
||||
got := URL("not-a-url"); got != "<redacted>" {
|
||||
t.Fatalf("invalid URL = %q", got)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user