Files
MeshPort/engines/singbox/bridge/probe_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

49 lines
1.4 KiB
Go

package bridge
import (
"bufio"
"context"
"fmt"
"net"
"net/http"
"testing"
)
func TestDraftHTTPProbeIsIsolated(t *testing.T) {
proxy, count := socksFixture(t, func(c net.Conn) {
request, err := http.ReadRequest(bufio.NewReader(c))
if err != nil {
t.Error(err)
return
}
if request.Host != "203.0.113.7" || request.Method != "GET" {
t.Error("unexpected draft request")
}
fmt.Fprint(c, "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n")
})
defer proxy.Close()
l, port := reservePort(t)
l.Close()
var running Engine
if err := running.Start(context.Background(), Config{ListenPort: port, MeshSOCKS: "127.0.0.1:9", MeshCIDRs: []string{"10.77.0.0/24"}}); err != nil {
t.Fatal(err)
}
defer running.Close()
node := map[string]any{"type": "socks", "server": "127.0.0.1", "server_port": proxy.Addr().(*net.TCPAddr).Port}
result, err := ProbeNode(context.Background(), node, "", "http://203.0.113.7/probe")
if err != nil {
t.Fatal(err)
}
if result.StatusCode != 204 || result.ElapsedMS <= 0 || count.Load() != 1 {
t.Fatal("probe did not use selected draft node")
}
if running.Snapshot().State != "Running" {
t.Fatal("probe changed running engine")
}
canceled, cancel := context.WithCancel(context.Background())
cancel()
if _, err := ProbeNode(canceled, node, "", "http://203.0.113.7/probe"); err == nil {
t.Fatal("canceled probe accepted")
}
}