Files
MeshPort/engines/singbox/bridge/runtime_logs_test.go
T
shenandshen c7cc2aa865 Fix VPN internet connectivity and simplify client setup
Initialize Android physical interfaces and preserve macOS scoped routes. Add redacted diagnostics, default DNS, ordered auto-save, simplified controls, scanner rotation settings, and native regression coverage. Restore vendored build sources and document validation and stability checks.
2026-10-12 06:51:25 -07:00

37 lines
1.2 KiB
Go

package bridge
import (
"github.com/sagernet/sing-box/log"
"strings"
"testing"
)
func TestRuntimeLogsBoundedAndRedacted(t *testing.T) {
var logs runtimeLogs
logs.configure(map[string]any{"uuid": "secret-uuid", "password": "secret-password"})
logs.WriteMessage(log.LevelInfo, "ignored")
for i := 0; i < 40; i++ {
logs.WriteMessage(log.LevelError, "failure secret-uuid secret-password https://u:p@example.test/?token=secret-token")
}
events := logs.snapshot()
if len(events) != 32 || events[0].Sequence != 9 {
t.Fatal("unbounded or incorrect log sequence")
}
for _, e := range events {
for _, secret := range []string{"secret-uuid", "secret-password", "secret-token", "u:p"} {
if strings.Contains(e.Message, secret) {
t.Fatal("runtime log exposed credential")
}
}
}
}
func TestRuntimeLogsRedactOverlappingCredentialValues(t *testing.T) {
var logs runtimeLogs
logs.configure(map[string]any{"username": "secret", "password": "secret-credential"})
logs.WriteMessage(log.LevelError, "authentication failed for secret-credential")
if strings.Contains(logs.snapshot()[0].Message, "credential") {
t.Fatal("short credential prevented full password redaction")
}
}