mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-10-28 01:03:50 +08:00
所有目标流量可经统一的全局代理出网(http/https/socks5,支持 user:pass): - 开启流量捕获时,作为 MITM 记录代理的上游(流量照录再经代理出网); 拦截与透传两条路径都走上游,不泄露源 IP。 - 关闭捕获时,直接注入 agent 的 bash 环境与 WebFetch;proxyEnv 增加 ALL_PROXY 以支持 socks5。 配置存于 settings KV 表(无需迁移),前端系统配置页新增「全局代理」卡片。 与网络搜索代理、LLM 代理相互独立。
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestProxyEnvEmptyIsNil(t *testing.T) {
|
|
if env := proxyEnv("", ""); env != nil {
|
|
t.Fatalf("proxyEnv(\"\", \"\") = %v, want nil (direct)", env)
|
|
}
|
|
}
|
|
|
|
func TestProxyEnvSetsAllProxyForSocks5(t *testing.T) {
|
|
// Capture-off egress path: a socks5 proxy, no MITM CA. ALL_PROXY must be set
|
|
// (curl reads socks5 only from there), and no CA vars should appear.
|
|
env := proxyEnv("socks5://10.0.0.1:1080", "")
|
|
has := func(prefix string) bool {
|
|
for _, e := range env {
|
|
if strings.HasPrefix(e, prefix) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
for _, want := range []string{"HTTP_PROXY=", "HTTPS_PROXY=", "ALL_PROXY=", "all_proxy="} {
|
|
if !has(want) {
|
|
t.Errorf("proxyEnv missing %s: %v", want, env)
|
|
}
|
|
}
|
|
if has("SSL_CERT_FILE=") || has("CURL_CA_BUNDLE=") {
|
|
t.Errorf("proxyEnv without CA must not inject CA vars: %v", env)
|
|
}
|
|
}
|
|
|
|
func TestProxyEnvInjectsCAWhenRecording(t *testing.T) {
|
|
env := proxyEnv("http://127.0.0.1:8788", "/data/ca.pem")
|
|
has := func(prefix string) bool {
|
|
for _, e := range env {
|
|
if strings.HasPrefix(e, prefix) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
for _, want := range []string{"SSL_CERT_FILE=", "CURL_CA_BUNDLE=", "REQUESTS_CA_BUNDLE=", "NODE_EXTRA_CA_CERTS="} {
|
|
if !has(want) {
|
|
t.Errorf("proxyEnv with CA missing %s: %v", want, env)
|
|
}
|
|
}
|
|
}
|