mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 04:14:15 +00:00
58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Autumn-27/norma/llm"
|
|
)
|
|
|
|
// Proxy validation errors from NewProvider / quotaAwareHTTPClient are returned
|
|
// to callers and logged: they must never quote the proxy address, its scheme,
|
|
// or url.Parse's raw error (which quotes the input), since the proxy URL may
|
|
// carry credentials.
|
|
func TestQuotaAwareHTTPClientProxyErrorsOmitAddress(t *testing.T) {
|
|
cases := []string{
|
|
"http://user:pw-secret@", // missing host
|
|
"user:pw-secret@proxy.example:3128", // missing scheme, url.Parse reads scheme "user"
|
|
"pw-secret:pass@proxy.example:3128", // missing scheme, url.Parse reads scheme "pw-secret"
|
|
"http://user:pw-secret@bad host:3128", // url.Parse error quotes raw URL
|
|
"ftp://user:pw-secret@proxy.example:21", // unsupported scheme
|
|
"//user:pw-secret@proxy.example:3128", // missing scheme
|
|
}
|
|
for _, raw := range cases {
|
|
_, err := quotaAwareHTTPClient(raw, "", "")
|
|
if err == nil {
|
|
t.Errorf("quotaAwareHTTPClient(%q) expected error, got nil", raw)
|
|
continue
|
|
}
|
|
if strings.Contains(err.Error(), "pw-secret") || strings.Contains(err.Error(), "user") || strings.Contains(err.Error(), "proxy.example") {
|
|
t.Errorf("quotaAwareHTTPClient(%q) error leaks proxy address: %v", raw, err)
|
|
}
|
|
|
|
cfg := Config{Format: llm.FormatOpenAI, APIKey: "sk-test", Model: "gpt-4o", Proxy: raw}
|
|
_, err = cfg.NewProvider()
|
|
if err == nil {
|
|
t.Errorf("NewProvider(%q) expected error, got nil", raw)
|
|
continue
|
|
}
|
|
if strings.Contains(err.Error(), "pw-secret") || strings.Contains(err.Error(), "user") || strings.Contains(err.Error(), "proxy.example") {
|
|
t.Errorf("NewProvider(%q) error leaks proxy address: %v", raw, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestQuotaAwareHTTPClientAcceptsValidProxy(t *testing.T) {
|
|
for _, raw := range []string{
|
|
"",
|
|
" ",
|
|
"http://127.0.0.1:8080",
|
|
"https://proxy.example.com:3128",
|
|
"socks5://user:pass@10.0.0.1:1080",
|
|
} {
|
|
if _, err := quotaAwareHTTPClient(raw, "", ""); err != nil {
|
|
t.Fatalf("quotaAwareHTTPClient(%q) unexpected error: %v", raw, err)
|
|
}
|
|
}
|
|
}
|