Files
MeshPort/engines/singbox/bridge/tun_config_test.go
T
shenleiandClaude Haiku 5.5 2f185f914d Snapshot uncommitted work: proxy UI, sing-box integration, socks bridge
- Lab app: proxy panel, node editor, configuration and detail pages,
  responsive layout, and related tests
- Add meshport-socks crate and sing-box bridge scripts/docs
- Add singbox_flutter binding and meshport_client_core package
- FFI, VPN helper (unified mac path), and Android/macOS runner updates
- Docs for architecture, client runtime, UI design, and validation
- UI design output artifacts under outputs/ui

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-10-12 10:06:15 +09:00

47 lines
1.7 KiB
Go

package bridge
import (
"encoding/json"
"testing"
)
func TestDesktopTunCaptureRoutesDoNotDuplicateProtection(t *testing.T) {
data, err := (Config{ListenPort: 10818, Feature: "mesh", MeshSOCKS: "127.0.0.1:19001", MeshCIDRs: []string{"10.253.88.0/25"}, ProtectedCIDRs: []string{"10.253.88.0/25", "10.253.88.128/25"}, DesktopTun: true, PhysicalInterface: "en0"}).managedJSON()
if err != nil {
t.Fatal(err)
}
var config map[string]any
if err := json.Unmarshal(data, &config); err != nil {
t.Fatal(err)
}
inbounds := config["inbounds"].([]any)
addresses := inbounds[1].(map[string]any)["address"].([]any)
if len(addresses) != 1 || addresses[0] != "172.19.0.1/30" {
t.Fatalf("mesh-only TUN must not create implicit IPv6 default routes: %v", addresses)
}
routes := inbounds[1].(map[string]any)["route_address"].([]any)
if len(routes) != 2 || routes[0] != "10.253.88.0/25" || routes[1] != "10.253.88.128/25" {
t.Fatalf("unsafe capture routes: %v", routes)
}
}
func TestTraceCannotLogOrdinaryNetworkProfiles(t *testing.T) {
t.Setenv("MESHPORT_SELF_TEST_TRACE", "1")
fixture := Config{Feature: "mesh", DesktopTun: true, MeshCIDRs: []string{"10.253.88.0/25"}}
for _, change := range []func(*Config){
func(c *Config) { c.MeshCIDRs = []string{"192.168.20.0/24"} },
func(c *Config) { c.ProtectedCIDRs = []string{"192.168.21.0/24"} },
func(c *Config) { c.MeshCIDRs = []string{"10.253.0.0/16"} },
func(c *Config) { c.Feature = "combined" },
func(c *Config) { c.DesktopTun = false },
func(c *Config) { c.Proxy = map[string]any{"type": "socks"} },
func(c *Config) { c.MeshCIDRs = nil },
} {
config := fixture
change(&config)
if config.selfTestTrace() {
t.Fatal("self-test tracing accepted an ordinary network profile")
}
}
}