feat: 重建 Sense 认证权限与审计 (#64)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSanitizeAuditJSON(t *testing.T) {
|
||||
input := `{"username":"operator","password":"secret-value","nested":{"newPassword":"another-secret"},"token":"jwt-value"}`
|
||||
got := sanitizeAuditJSON(input)
|
||||
for _, secret := range []string{"secret-value", "another-secret", "jwt-value"} {
|
||||
if strings.Contains(got, secret) {
|
||||
t.Fatalf("sensitive value leaked: %s", got)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(got, "operator") {
|
||||
t.Fatalf("non-sensitive context was unexpectedly removed: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeAuditJSONRejectsUnstructuredBodies(t *testing.T) {
|
||||
if got := sanitizeAuditJSON("password=secret-value"); strings.Contains(got, "secret-value") {
|
||||
t.Fatalf("unstructured body leaked: %s", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user