Files
artex/agent/proxyenv_test.go
T
dela 0335d572de
ci / go (push) Waiting to run
ci / go-db (agent) (push) Waiting to run
ci / go-db (config) (push) Waiting to run
ci / go-db (db) (push) Waiting to run
ci / go-db (evidence) (push) Waiting to run
ci / go-db (llmrec) (push) Waiting to run
ci / go-db (server) (push) Waiting to run
web / web (push) Waiting to run
docs / links (push) Canceled after 0s
detections / detections (push) Canceled after 0s
First Commit
2026-10-09 08:38:16 +08:00

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)
}
}
}