sing-tun creates its utun control socket without SOCK_CLOEXEC (tun_darwin.go), so any child the unified helper spawns while the engine runs - the DnsGuard scutil process, route commands - inherits that socket and pins the utun interface past engine stop. The announcement-driven rebuild then fails with "desktop TUN address already in use" and tears down the whole VPN session. Mark every utun socket in the process close-on-exec as soon as the engine starts. Stop now only warns when Darwin still holds the retiring address (classified via cleanupFailure), and Start waits bounded for an address this engine itself retained while failing fast on any other owner. Adds a root-only drain diagnostic with a real-profile pass, a child-guard regression test that reproduced the production failure before the fix, and a --self-test-unified-rebuild helper self-test that forces stop/start cycles in combined mode end to end. Co-Authored-By: Claude Code <noreply@anthropic.com>
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
package bridge
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestStartupDiagnosticsDoNotExposeUpstreamCredentials(t *testing.T) {
|
|
for _, message := range []string{
|
|
"unknown option password=test-secret https://example.test/sub?token=test-token",
|
|
"rule-set download https://user:test-secret@example.test/sub?token=test-token",
|
|
"unclassified failure with test-secret and test-token",
|
|
} {
|
|
result := startupFailure("initialize_engine", errors.New(message)).Error()
|
|
if strings.Contains(result, "test-secret") || strings.Contains(result, "test-token") || strings.Contains(result, "example.test") {
|
|
t.Fatalf("diagnostic exposed upstream contents: %s", result)
|
|
}
|
|
if !strings.Contains(result, "stage=initialize_engine") {
|
|
t.Fatal("diagnostic omitted failing stage")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCleanupDiagnosticsClassifyStopFailuresWithoutUpstreamText(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
cause error
|
|
code string
|
|
}{
|
|
{fmt.Errorf("%w: %v", errTunAddressInspect, errors.New("interface test-secret")), "tun_address_inspect_failed"},
|
|
{errors.New("remove route 10.9.0.0/16 test-secret: not in table"), "route_cleanup_failed"},
|
|
{errors.New("unexpected close test-secret"), "engine_close_failed"},
|
|
} {
|
|
result := cleanupFailure(tc.cause).Error()
|
|
if !strings.Contains(result, "code="+tc.code) {
|
|
t.Fatalf("expected code %s, got %s", tc.code, result)
|
|
}
|
|
if strings.Contains(result, "test-secret") || strings.Contains(result, "10.9.0.0") {
|
|
t.Fatalf("cleanup diagnostic exposed upstream contents: %s", result)
|
|
}
|
|
}
|
|
}
|