Files
free-turn-proxy-orig/internal/transport/turndial/turndial_test.go
T
samosvalishe 31e35efbf3 refactor: переименовать флаги и поля CLI/конфига
- wrap → obf: -wrap/-wrap-key/-gen-wrap-key → -obf/-obf-key/-gen-obf-key;
  ObfOpts.WrapMode/WrapKey/GenWrapKey → Mode/Key/GenKey
- vless → mode: -vless/-vless-bond → -mode tcp / -bond;
  clientProxyMode/serverProxyMode принимают string вместо bool
- -udp → -transport tcp|udp; TURNOpts.UDP → TransportUDP (везде)
- -vk-link → -link; -dns → -dns-mode; DNSModeUDP → DNSModePlain ("plain")
- KCP: убрать LoadProfileFromEnv/LoadFECFromEnv — хардкодить DefaultProfile/FEC{}
- Добавить валидацию -transport/-mode/-bond/-dns-mode в ParseClient/ParseServer
2026-05-21 19:19:40 +03:00

37 lines
1.2 KiB
Go

package turndial
import (
"context"
"net"
"strings"
"testing"
"time"
)
// Open dialing a bogus address must surface a wrapped resolve/dial error.
func TestOpen_BadAddress(t *testing.T) {
peer := &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1}
_, err := Open(context.Background(), Config{}, peer, "u", "p", "not-a-host-port")
if err == nil {
t.Fatal("expected error for malformed addr")
}
if !strings.Contains(err.Error(), "parse TURN addr") {
t.Fatalf("unexpected error: %v", err)
}
}
// Open with overrides resolves the override host:port (still fails because
// there's no TURN server, but the dial error must mention the override).
func TestOpen_HostOverrideApplied(t *testing.T) {
peer := &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 1}
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
_, err := Open(ctx, Config{HostOverride: "127.0.0.1", PortOverride: "1", TransportUDP: false,DialTimeout: 200 * time.Millisecond}, peer, "u", "p", "8.8.8.8:443")
if err == nil {
t.Fatal("expected dial error against unreachable :1")
}
if !strings.Contains(err.Error(), "dial TURN") {
t.Fatalf("expected dial error, got: %v", err)
}
}