mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 21:11:50 +08:00
fix: 代理池无健康成员走暂停不直连、单飞探测、热切覆盖 capture-off 与浏览器 MCP、脱敏与 UI 补全
This commit is contained in:
1 parent
0bb954e0a4
commit
45514b3586
10 files changed
+599
-157
No files matched your search
@@ -2,8 +2,13 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/artex/traffic"
|
||||
)
|
||||
|
||||
func TestParseProxyBatchValidationAndDedup(t *testing.T) {
|
||||
@@ -54,3 +59,49 @@ func TestProxyPoolPersistenceKeepsRawURL(t *testing.T) {
|
||||
t.Fatalf("bad persistence encoding: %s", b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyPoolURLKeyNormalizesHostCase(t *testing.T) {
|
||||
a, _ := traffic.ValidateProxyURL("http://user:pass@HOST:8080")
|
||||
b, _ := traffic.ValidateProxyURL("http://user:pass@host:8080")
|
||||
if proxyURLKey(a) != proxyURLKey(b) {
|
||||
t.Fatalf("keys differ: %q %q", proxyURLKey(a), proxyURLKey(b))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeMaskedProxyURLPreservesOnlyPassword(t *testing.T) {
|
||||
got, err := mergeMaskedProxyURL("http://newuser:***@NEW.example:9090", "http://old:[email protected]:8080")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != "http://newuser:[email protected]:9090" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeMaskedProxyURLErrorIsMasked(t *testing.T) {
|
||||
_, err := mergeMaskedProxyURL("http://user:secret@", "")
|
||||
if err == nil || strings.Contains(err.Error(), "secret") {
|
||||
t.Fatalf("unmasked error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDynamicForwardProxyUsesCurrentUpstream(t *testing.T) {
|
||||
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("ok")) }))
|
||||
defer target.Close()
|
||||
up := ""
|
||||
fp, err := newDynamicForwardProxy(func() string { return up })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fp.Close()
|
||||
pu, _ := url.Parse(fp.Addr())
|
||||
c := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(pu)}}
|
||||
resp, err := c.Get(target.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("status %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user