| 79 | } |
| 80 | |
| 81 | func TestUnified_TransparentOnlyNoTLSConfig(t *testing.T) { |
| 82 | // 只有透明路由时不需要 TLSConfig |
| 83 | backend := startEchoTLS(t, "x.example.com") |
| 84 | proxy := &UnifiedProxy{Addr: "127.0.0.1:0"} |
| 85 | proxy.SetRoutes([]Route{{SNI: "x.example.com", Backend: backend, Mode: ModeTransparent}}) |
| 86 | |
| 87 | ln, _ := net.Listen("tcp", "127.0.0.1:0") |
| 88 | addr := ln.Addr().String() |
| 89 | _ = ln.Close() |
| 90 | proxy.Addr = addr |
| 91 | |
| 92 | ctx, cancel := context.WithCancel(context.Background()) |
| 93 | defer cancel() |
| 94 | var wg sync.WaitGroup |
| 95 | wg.Add(1) |
| 96 | go func() { defer wg.Done(); _ = proxy.Serve(ctx) }() |
| 97 | t.Cleanup(func() { cancel(); wg.Wait() }) |
| 98 | |
| 99 | waitForListen(t, addr) |
| 100 | |
| 101 | conn, err := net.Dial("tcp", addr) |
| 102 | if err != nil { |
| 103 | t.Fatal(err) |
| 104 | } |
| 105 | defer conn.Close() |
| 106 | tc := tls.Client(conn, &tls.Config{ServerName: "x.example.com", InsecureSkipVerify: true}) |
| 107 | _ = tc.SetDeadline(time.Now().Add(3 * time.Second)) |
| 108 | if err := tc.Handshake(); err != nil { |
| 109 | t.Fatalf("handshake: %v", err) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func TestUnified_HotReloadSwitchesMode(t *testing.T) { |
| 114 | // 先配成透明,再热切到终止 |