fix(admin): 渠道代理 - 校验代理地址并拒绝无效出口

PR: #717
PR 标题: feat(admin): 渠道管理 - 模型供应商支持渠道级 SOCKS5/HTTP 代理

校验渠道级代理地址并在历史无效配置下拒绝出站请求,保留空代理回退全局代理的行为,同时补充管理端和出站层回归测试。

Co-authored-by: ddcat666 <26564566+ddcat666@users.noreply.github.com>
This commit is contained in:
dxiaomandddcat666 authored and ddcat666 committed 2026-10-10 05:44:48 +08:00
1 parent 524d2910ca
commit d13e1dcaa3
9 files changed
+88 -9

No files matched your search

@@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"
)
@@ -46,6 +47,24 @@ func TestConfiguredProxyHostIsTrustedAsDeploymentEgress(t *testing.T) {
}
}
func TestOutboundHTTPClientWithProxyFailsClosedForInvalidURL(t *testing.T) {
client := OutboundHTTPClientWithProxy(time.Second, "ftp://127.0.0.1:1080")
request, err := http.NewRequest(http.MethodGet, "https://example.com", nil)
if err != nil {
t.Fatal(err)
}
if _, err := client.Do(request); err == nil || !strings.Contains(err.Error(), "渠道代理地址无效") {
t.Fatalf("invalid proxy should fail closed, got %v", err)
}
}
func TestOutboundHTTPClientWithProxyFallsBackForEmptyURL(t *testing.T) {
client := OutboundHTTPClientWithProxy(time.Second, " \t")
if client.Transport != outboundTransport {
t.Fatal("empty proxy URL should use the global outbound transport")
}
}
func TestNormalizeOutboundHeadersAllowsCustomUserAgent(t *testing.T) {
headers, err := NormalizeOutboundHeaders([]OutboundHeader{{Name: "user-agent", Value: "Custom Gateway/2.0"}, {Name: "X-Gateway-Tenant", Value: "tenant-a"}})
if err != nil {