|
|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"os"
|
|
|
+ "slices"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
|
|
|
@@ -612,6 +613,29 @@ func TestInjectAmneziawgnetSocks_CreatesRelayTaggedWithInboundsOwnTag(t *testing
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Without routeOnly the sniffed SNI replaces the dial target, so Telegram's
|
|
|
+// FakeTLS to 194.221.250.50 (SNI www.google.com) lands on real Google.
|
|
|
+func TestInjectAmneziawgnetSocks_SniffingRouteOnly(t *testing.T) {
|
|
|
+ cfg := egressTestConfig()
|
|
|
+ injectAmneziawgnetSocks(cfg, []*model.Inbound{amneziawgInbound(7, "awg-7", []model.Client{
|
|
|
+ {Email: "a@x", Enable: true, PublicKey: "pub-a", AllowedIPs: []string{"10.8.1.2/32"}},
|
|
|
+ })})
|
|
|
+ var sniffing struct {
|
|
|
+ Enabled bool `json:"enabled"`
|
|
|
+ DestOverride []string `json:"destOverride"`
|
|
|
+ RouteOnly bool `json:"routeOnly"`
|
|
|
+ }
|
|
|
+ if err := json.Unmarshal(cfg.InboundConfigs[1].Sniffing, &sniffing); err != nil {
|
|
|
+ t.Fatalf("relay inbound must carry a sniffing block, got %q: %v", cfg.InboundConfigs[1].Sniffing, err)
|
|
|
+ }
|
|
|
+ if !sniffing.Enabled || !sniffing.RouteOnly {
|
|
|
+ t.Fatalf("sniffing must be enabled with routeOnly, got %+v", sniffing)
|
|
|
+ }
|
|
|
+ if want := []string{"http", "tls", "quic", "fakedns"}; !slices.Equal(sniffing.DestOverride, want) {
|
|
|
+ t.Fatalf("destOverride = %v, want %v", sniffing.DestOverride, want)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestInjectAmneziawgnetSocks_MultipleInboundsEachGetOwnRelay(t *testing.T) {
|
|
|
cfg := egressTestConfig()
|
|
|
inbound1 := amneziawgInbound(1, "awg-1", []model.Client{
|
|
|
@@ -757,6 +781,7 @@ type v6EgressRouting struct {
|
|
|
Rules []struct {
|
|
|
InboundTag []string `json:"inboundTag"`
|
|
|
User []string `json:"user"`
|
|
|
+ IP []string `json:"ip"`
|
|
|
OutboundTag string `json:"outboundTag"`
|
|
|
Type string `json:"type"`
|
|
|
} `json:"rules"`
|
|
|
@@ -815,6 +840,10 @@ func TestInjectAmneziawgV6Egress_CreatesOutboundAndRuleForV6Peer(t *testing.T) {
|
|
|
len(rule.InboundTag) != 1 || rule.InboundTag[0] != "awg-7" {
|
|
|
t.Fatalf("rule must match this peer's email and inbound tag, got %+v", rule)
|
|
|
}
|
|
|
+ // A v6 sendThrough cannot dial an IPv4 target, so only v6 destinations may take this outbound.
|
|
|
+ if !slices.Equal(rule.IP, []string{"::/0"}) {
|
|
|
+ t.Fatalf("rule must be limited to IPv6 destinations, got ip %v", rule.IP)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func TestInjectAmneziawgV6Egress_SkipsPeerWithoutV6Address(t *testing.T) {
|