mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-27 04:54:45 +03:00
d04dbbe834
The HTTP-mode outbound test builds a throwaway Xray instance whose config carried no dns section, so an outbound whose server name only the panel's configured resolvers know (a split-DNS name, a hosts entry) failed the test with a lookup against the OS resolver, while the same outbound worked through the running core. The test endpoints now pass the stored template's dns section to the probe instance. Its tag, which names routing the probe config does not have, and its script are left out; every resolution setting rides along. Fixes #7131
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
package outbound
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/xray"
|
|
)
|
|
|
|
// A direct, DNS, loopback or blackhole outbound is not a tunnel, so the probe
|
|
// rejects it whatever the spelling: the core resolves "Freedom" to freedom.
|
|
func TestTestOutboundsRejectsCaseVariantUntestableIDs(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
withStubProcess(t, func(cfg *xray.Config, configPath string) batchProcess {
|
|
return &stubProcess{cfg: cfg, serveSocks: true}
|
|
})
|
|
withEgressTraceProbe(t, func(*url.URL) *TestEgressResult {
|
|
return &TestEgressResult{IPv4: "198.51.100.2", Country: "ZZ", Warp: "off"}
|
|
})
|
|
|
|
tests := []struct {
|
|
name string
|
|
protocol string
|
|
wantErr string
|
|
}{
|
|
{"freedom", "freedom", "Direct/DNS outbound cannot be tested"},
|
|
{"Freedom", "Freedom", "Direct/DNS outbound cannot be tested"},
|
|
{"FREEDOM", "FREEDOM", "Direct/DNS outbound cannot be tested"},
|
|
{"DNS", "DNS", "Direct/DNS outbound cannot be tested"},
|
|
{"Blackhole", "Blackhole", "Blocked/blackhole outbound cannot be tested"},
|
|
{"Loopback", "Loopback", "Loopback outbound cannot be tested"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
batch := mustJSON(t, []any{map[string]any{"tag": "probe", "protocol": tt.protocol}})
|
|
results, err := (&OutboundService{}).TestOutbounds(batch, srv.URL, "", "http", nil)
|
|
if err != nil {
|
|
t.Fatalf("TestOutbounds: %v", err)
|
|
}
|
|
r := results[0]
|
|
if r.Success || r.Error != tt.wantErr {
|
|
t.Errorf("%q = success=%v err=%q egress=%+v, want the rejection %q",
|
|
tt.protocol, r.Success, r.Error, r.Egress, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|