34 lines
936 B
Go
34 lines
936 B
Go
package storagevalue
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestCredentialCopiesPreserveOriginalAndNumbers 验证卡密、验证码及不同命名的密钥字段脱敏,不改动原始值或大整数。
|
|
func TestCredentialCopiesPreserveOriginalAndNumbers(t *testing.T) {
|
|
var (
|
|
original = map[string]any{
|
|
"card_key": "private-card",
|
|
"verification_code": "private-code",
|
|
"apiKey": "private-api",
|
|
"nested": `{"accessKey":"private-access","id":18446744073709551615}`,
|
|
}
|
|
result = Safe(original)
|
|
body, err = json.Marshal(result)
|
|
)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(body), "private-") {
|
|
t.Fatal("credential appeared in log copy")
|
|
}
|
|
if !strings.Contains(string(body), "18446744073709551615") {
|
|
t.Fatal("log copy rounded an identifier")
|
|
}
|
|
if original["card_key"] != "private-card" {
|
|
t.Fatal("redaction modified execution data")
|
|
}
|
|
}
|