48 lines
1.6 KiB
Go
48 lines
1.6 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, "connection opened")
|
|
for i := 0; i < 140; i++ {
|
|
logs.WriteMessage(log.LevelError, "failure secret-uuid secret-password https://u:p@example.test/?token=secret-token")
|
|
}
|
|
events := logs.snapshot()
|
|
if len(events) != 128 || events[0].Sequence != 14 {
|
|
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")
|
|
}
|
|
}
|
|
|
|
func TestRuntimeLogsCaptureConnectionsButSkipDebug(t *testing.T) {
|
|
var logs runtimeLogs
|
|
logs.configure(map[string]any{"password": "example-secret"})
|
|
logs.WriteMessage(log.LevelDebug, "debug packet")
|
|
logs.WriteMessage(log.LevelInfo, "outbound connection example-secret")
|
|
events := logs.snapshot()
|
|
if len(events) != 1 || strings.Contains(events[0].Message, "example-secret") {
|
|
t.Fatal("connection logs missing or credentials exposed")
|
|
}
|
|
}
|