Skip to content

Commit 5b32569

Browse files
committed
Add --proxy-auth flag for SOCKS authentication in e2e tests
Allows passing user:pass credentials to the SOCKS proxy via curl --proxy-user for dnstt, slipstream, and DoH e2e tunnel tests.
1 parent a2e6f4c commit 5b32569

7 files changed

Lines changed: 43 additions & 27 deletions

File tree

cmd/chain.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ func buildStep(cfg stepConfig, defaultTimeout, defaultCount int, ports chan int,
101101
if v, ok := cfg.params["test-url"]; ok {
102102
testURL = v
103103
}
104-
return scanner.Step{Name: "e2e/dnstt", Timeout: dur, Check: scanner.DnsttCheckBin(binPaths["dnstt-client"], domain, pubkey, testURL, ports), SortBy: "e2e_ms"}, nil
104+
proxyAuth := cfg.params["proxy-auth"]
105+
return scanner.Step{Name: "e2e/dnstt", Timeout: dur, Check: scanner.DnsttCheckBin(binPaths["dnstt-client"], domain, pubkey, testURL, proxyAuth, ports), SortBy: "e2e_ms"}, nil
105106

106107
case "e2e/slipstream":
107108
domain, ok := cfg.params["domain"]
@@ -113,7 +114,8 @@ func buildStep(cfg stepConfig, defaultTimeout, defaultCount int, ports chan int,
113114
if v, ok := cfg.params["test-url"]; ok {
114115
testURL = v
115116
}
116-
return scanner.Step{Name: "e2e/slipstream", Timeout: dur, Check: scanner.SlipstreamCheckBin(binPaths["slipstream-client"], domain, cert, testURL, ports), SortBy: "e2e_ms"}, nil
117+
proxyAuth := cfg.params["proxy-auth"]
118+
return scanner.Step{Name: "e2e/slipstream", Timeout: dur, Check: scanner.SlipstreamCheckBin(binPaths["slipstream-client"], domain, cert, testURL, proxyAuth, ports), SortBy: "e2e_ms"}, nil
117119

118120
case "nxdomain":
119121
return scanner.Step{Name: "nxdomain", Timeout: dur, Check: scanner.NXDomainCheck(stepCount), SortBy: "hijack"}, nil
@@ -152,7 +154,8 @@ func buildStep(cfg stepConfig, defaultTimeout, defaultCount int, ports chan int,
152154
if v, ok := cfg.params["test-url"]; ok {
153155
testURL = v
154156
}
155-
return scanner.Step{Name: "doh/e2e", Timeout: dur, Check: scanner.DoHDnsttCheckBin(binPaths["dnstt-client"], domain, pubkey, testURL, ports), SortBy: "e2e_ms"}, nil
157+
proxyAuth := cfg.params["proxy-auth"]
158+
return scanner.Step{Name: "doh/e2e", Timeout: dur, Check: scanner.DoHDnsttCheckBin(binPaths["dnstt-client"], domain, pubkey, testURL, proxyAuth, ports), SortBy: "e2e_ms"}, nil
156159

157160
default:
158161
return scanner.Step{}, fmt.Errorf("unknown step type %q", cfg.name)

cmd/doh_e2e.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func init() {
1717
dohE2ECmd.Flags().String("domain", "", "DNSTT tunnel domain")
1818
dohE2ECmd.Flags().String("pubkey", "", "DNSTT server public key")
1919
dohE2ECmd.Flags().String("test-url", "https://httpbin.org/ip", "URL to fetch through tunnel")
20+
dohE2ECmd.Flags().String("proxy-auth", "", "SOCKS proxy auth as user:pass")
2021
dohE2ECmd.MarkFlagRequired("domain")
2122
dohE2ECmd.MarkFlagRequired("pubkey")
2223
dohCmd.AddCommand(dohE2ECmd)
@@ -26,6 +27,7 @@ func runDoHE2E(cmd *cobra.Command, args []string) error {
2627
domain, _ := cmd.Flags().GetString("domain")
2728
pubkey, _ := cmd.Flags().GetString("pubkey")
2829
testURL, _ := cmd.Flags().GetString("test-url")
30+
proxyAuth, _ := cmd.Flags().GetString("proxy-auth")
2931

3032
bin, err := findBinary("dnstt-client")
3133
if err != nil {
@@ -39,7 +41,7 @@ func runDoHE2E(cmd *cobra.Command, args []string) error {
3941

4042
dur := time.Duration(e2eTimeout) * time.Second
4143
ports := scanner.PortPool(30000, workers)
42-
check := scanner.DoHDnsttCheckBin(bin, domain, pubkey, testURL, ports)
44+
check := scanner.DoHDnsttCheckBin(bin, domain, pubkey, testURL, proxyAuth, ports)
4345

4446
start := time.Now()
4547
results := scanner.RunPool(urls, workers, dur, check, newProgress("doh/e2e"))

cmd/e2e_dnstt.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func init() {
1717
e2eDnsttCmd.Flags().String("domain", "", "DNSTT tunnel domain")
1818
e2eDnsttCmd.Flags().String("pubkey", "", "DNSTT server public key")
1919
e2eDnsttCmd.Flags().String("test-url", "https://httpbin.org/ip", "URL to fetch through tunnel")
20+
e2eDnsttCmd.Flags().String("proxy-auth", "", "SOCKS proxy auth as user:pass")
2021
e2eDnsttCmd.MarkFlagRequired("domain")
2122
e2eDnsttCmd.MarkFlagRequired("pubkey")
2223
e2eCmd.AddCommand(e2eDnsttCmd)
@@ -26,6 +27,7 @@ func runE2EDnstt(cmd *cobra.Command, args []string) error {
2627
domain, _ := cmd.Flags().GetString("domain")
2728
pubkey, _ := cmd.Flags().GetString("pubkey")
2829
testURL, _ := cmd.Flags().GetString("test-url")
30+
proxyAuth, _ := cmd.Flags().GetString("proxy-auth")
2931

3032
bin, err := findBinary("dnstt-client")
3133
if err != nil {
@@ -39,7 +41,7 @@ func runE2EDnstt(cmd *cobra.Command, args []string) error {
3941

4042
dur := time.Duration(e2eTimeout) * time.Second
4143
ports := scanner.PortPool(30000, workers)
42-
check := scanner.DnsttCheckBin(bin, domain, pubkey, testURL, ports)
44+
check := scanner.DnsttCheckBin(bin, domain, pubkey, testURL, proxyAuth, ports)
4345

4446
start := time.Now()
4547
results := scanner.RunPool(ips, workers, dur, check, newProgress("e2e/dnstt"))

cmd/e2e_slipstream.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func init() {
1717
e2eSlipstreamCmd.Flags().String("domain", "", "Slipstream tunnel domain")
1818
e2eSlipstreamCmd.Flags().String("cert", "", "path to Slipstream certificate for cert pinning (optional)")
1919
e2eSlipstreamCmd.Flags().String("test-url", "https://httpbin.org/ip", "URL to fetch through tunnel")
20+
e2eSlipstreamCmd.Flags().String("proxy-auth", "", "SOCKS proxy auth as user:pass")
2021
e2eSlipstreamCmd.MarkFlagRequired("domain")
2122
e2eCmd.AddCommand(e2eSlipstreamCmd)
2223
}
@@ -25,6 +26,7 @@ func runE2ESlipstream(cmd *cobra.Command, args []string) error {
2526
domain, _ := cmd.Flags().GetString("domain")
2627
certPath, _ := cmd.Flags().GetString("cert")
2728
testURL, _ := cmd.Flags().GetString("test-url")
29+
proxyAuth, _ := cmd.Flags().GetString("proxy-auth")
2830

2931
bin, err := findBinary("slipstream-client")
3032
if err != nil {
@@ -38,7 +40,7 @@ func runE2ESlipstream(cmd *cobra.Command, args []string) error {
3840

3941
dur := time.Duration(e2eTimeout) * time.Second
4042
ports := scanner.PortPool(30000, workers)
41-
check := scanner.SlipstreamCheckBin(bin, domain, certPath, testURL, ports)
43+
check := scanner.SlipstreamCheckBin(bin, domain, certPath, testURL, proxyAuth, ports)
4244

4345
start := time.Now()
4446
results := scanner.RunPool(ips, workers, dur, check, newProgress("e2e/slipstream"))

cmd/scan.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func init() {
4444
scanCmd.Flags().String("pubkey", "", "DNSTT public key (enables e2e test)")
4545
scanCmd.Flags().String("cert", "", "Slipstream cert path (enables slipstream e2e test)")
4646
scanCmd.Flags().String("test-url", "https://httpbin.org/ip", "URL to test through tunnel")
47+
scanCmd.Flags().String("proxy-auth", "", "SOCKS proxy auth as user:pass (for e2e tests)")
4748
scanCmd.Flags().Bool("doh", false, "scan DoH resolvers instead of UDP")
4849
scanCmd.Flags().Bool("skip-ping", false, "skip ICMP ping step")
4950
scanCmd.Flags().Bool("skip-nxdomain", false, "skip NXDOMAIN hijack check")
@@ -56,6 +57,7 @@ func runScan(cmd *cobra.Command, args []string) error {
5657
pubkey, _ := cmd.Flags().GetString("pubkey")
5758
certPath, _ := cmd.Flags().GetString("cert")
5859
testURL, _ := cmd.Flags().GetString("test-url")
60+
proxyAuth, _ := cmd.Flags().GetString("proxy-auth")
5961
dohMode, _ := cmd.Flags().GetBool("doh")
6062
skipPing, _ := cmd.Flags().GetBool("skip-ping")
6163
skipNXD, _ := cmd.Flags().GetBool("skip-nxdomain")
@@ -115,7 +117,7 @@ func runScan(cmd *cobra.Command, args []string) error {
115117
if domain != "" && pubkey != "" {
116118
steps = append(steps, scanner.Step{
117119
Name: "doh/e2e", Timeout: time.Duration(e2eTimeout) * time.Second,
118-
Check: scanner.DoHDnsttCheckBin(dnsttBin, domain, pubkey, testURL, ports), SortBy: "e2e_ms",
120+
Check: scanner.DoHDnsttCheckBin(dnsttBin, domain, pubkey, testURL, proxyAuth, ports), SortBy: "e2e_ms",
119121
})
120122
}
121123
} else {
@@ -148,13 +150,13 @@ func runScan(cmd *cobra.Command, args []string) error {
148150
if domain != "" && pubkey != "" {
149151
steps = append(steps, scanner.Step{
150152
Name: "e2e/dnstt", Timeout: time.Duration(e2eTimeout) * time.Second,
151-
Check: scanner.DnsttCheckBin(dnsttBin, domain, pubkey, testURL, ports), SortBy: "e2e_ms",
153+
Check: scanner.DnsttCheckBin(dnsttBin, domain, pubkey, testURL, proxyAuth, ports), SortBy: "e2e_ms",
152154
})
153155
}
154156
if domain != "" && certPath != "" {
155157
steps = append(steps, scanner.Step{
156158
Name: "e2e/slipstream", Timeout: time.Duration(e2eTimeout) * time.Second,
157-
Check: scanner.SlipstreamCheckBin(slipstreamBin, domain, certPath, testURL, ports), SortBy: "e2e_ms",
159+
Check: scanner.SlipstreamCheckBin(slipstreamBin, domain, certPath, testURL, proxyAuth, ports), SortBy: "e2e_ms",
158160
})
159161
}
160162
}

internal/scanner/doh.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,16 @@ func DoHTunnelCheck(domain string, count int) CheckFunc {
175175
}
176176

177177
// DoHDnsttCheckBin is like DoHDnsttCheck but uses an explicit binary path.
178-
func DoHDnsttCheckBin(bin, domain, pubkey, testURL string, ports chan int) CheckFunc {
179-
return dohDnsttCheck(bin, domain, pubkey, testURL, ports)
178+
func DoHDnsttCheckBin(bin, domain, pubkey, testURL, proxyAuth string, ports chan int) CheckFunc {
179+
return dohDnsttCheck(bin, domain, pubkey, testURL, proxyAuth, ports)
180180
}
181181

182182
// DoHDnsttCheck runs an e2e test using dnstt-client in DoH mode.
183183
func DoHDnsttCheck(domain, pubkey, testURL string, ports chan int) CheckFunc {
184-
return dohDnsttCheck("dnstt-client", domain, pubkey, testURL, ports)
184+
return dohDnsttCheck("dnstt-client", domain, pubkey, testURL, "", ports)
185185
}
186186

187-
func dohDnsttCheck(bin, domain, pubkey, testURL string, ports chan int) CheckFunc {
187+
func dohDnsttCheck(bin, domain, pubkey, testURL, proxyAuth string, ports chan int) CheckFunc {
188188
return func(url string, timeout time.Duration) (bool, Metrics) {
189189
ctx, cancel := context.WithTimeout(context.Background(), timeout)
190190
defer cancel()
@@ -226,7 +226,7 @@ func dohDnsttCheck(bin, domain, pubkey, testURL string, ports chan int) CheckFun
226226
return false, nil
227227
}
228228

229-
if !testSOCKS(ctx, port, testURL) {
229+
if !testSOCKS(ctx, port, testURL, proxyAuth) {
230230
return false, nil
231231
}
232232
ms := roundMs(float64(time.Since(start).Microseconds()) / 1000.0)

internal/scanner/e2e.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ func execCommandContext(ctx context.Context, name string, args ...string) *exec.
2323
}
2424

2525
// DnsttCheckBin is like DnsttCheck but uses an explicit binary path.
26-
func DnsttCheckBin(bin, domain, pubkey, testURL string, ports chan int) CheckFunc {
27-
return dnsttCheck(bin, domain, pubkey, testURL, ports)
26+
func DnsttCheckBin(bin, domain, pubkey, testURL, proxyAuth string, ports chan int) CheckFunc {
27+
return dnsttCheck(bin, domain, pubkey, testURL, proxyAuth, ports)
2828
}
2929

3030
func DnsttCheck(domain, pubkey, testURL string, ports chan int) CheckFunc {
31-
return dnsttCheck("dnstt-client", domain, pubkey, testURL, ports)
31+
return dnsttCheck("dnstt-client", domain, pubkey, testURL, "", ports)
3232
}
3333

34-
func dnsttCheck(bin, domain, pubkey, testURL string, ports chan int) CheckFunc {
34+
func dnsttCheck(bin, domain, pubkey, testURL, proxyAuth string, ports chan int) CheckFunc {
3535
return func(ip string, timeout time.Duration) (bool, Metrics) {
3636
ctx, cancel := context.WithTimeout(context.Background(), timeout)
3737
defer cancel()
@@ -74,7 +74,7 @@ func dnsttCheck(bin, domain, pubkey, testURL string, ports chan int) CheckFunc {
7474
return false, nil
7575
}
7676

77-
if !testSOCKS(ctx, port, testURL) {
77+
if !testSOCKS(ctx, port, testURL, proxyAuth) {
7878
return false, nil
7979
}
8080
ms := roundMs(float64(time.Since(start).Microseconds()) / 1000.0)
@@ -83,15 +83,15 @@ func dnsttCheck(bin, domain, pubkey, testURL string, ports chan int) CheckFunc {
8383
}
8484

8585
// SlipstreamCheckBin is like SlipstreamCheck but uses an explicit binary path.
86-
func SlipstreamCheckBin(bin, domain, certPath, testURL string, ports chan int) CheckFunc {
87-
return slipstreamCheck(bin, domain, certPath, testURL, ports)
86+
func SlipstreamCheckBin(bin, domain, certPath, testURL, proxyAuth string, ports chan int) CheckFunc {
87+
return slipstreamCheck(bin, domain, certPath, testURL, proxyAuth, ports)
8888
}
8989

9090
func SlipstreamCheck(domain, certPath, testURL string, ports chan int) CheckFunc {
91-
return slipstreamCheck("slipstream-client", domain, certPath, testURL, ports)
91+
return slipstreamCheck("slipstream-client", domain, certPath, testURL, "", ports)
9292
}
9393

94-
func slipstreamCheck(bin, domain, certPath, testURL string, ports chan int) CheckFunc {
94+
func slipstreamCheck(bin, domain, certPath, testURL, proxyAuth string, ports chan int) CheckFunc {
9595
return func(ip string, timeout time.Duration) (bool, Metrics) {
9696
ctx, cancel := context.WithTimeout(context.Background(), timeout)
9797
defer cancel()
@@ -137,7 +137,7 @@ func slipstreamCheck(bin, domain, certPath, testURL string, ports chan int) Chec
137137
return false, nil
138138
}
139139

140-
if !testSOCKS(ctx, port, testURL) {
140+
if !testSOCKS(ctx, port, testURL, proxyAuth) {
141141
return false, nil
142142
}
143143
ms := roundMs(float64(time.Since(start).Microseconds()) / 1000.0)
@@ -152,11 +152,16 @@ func nullDevice() string {
152152
return "/dev/null"
153153
}
154154

155-
func testSOCKS(ctx context.Context, port int, testURL string) bool {
156-
cmd := execCommandContext(ctx, "curl",
155+
func testSOCKS(ctx context.Context, port int, testURL, proxyAuth string) bool {
156+
args := []string{
157157
"-x", fmt.Sprintf("socks5h://127.0.0.1:%d", port),
158158
"-s", "-o", nullDevice(), "-w", "%{http_code}",
159-
testURL)
159+
}
160+
if proxyAuth != "" {
161+
args = append(args, "--proxy-user", proxyAuth)
162+
}
163+
args = append(args, testURL)
164+
cmd := execCommandContext(ctx, "curl", args...)
160165
output, err := cmd.Output()
161166
if err != nil {
162167
return false

0 commit comments

Comments
 (0)