mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-05-13 21:22:14 +00:00
- Introduced `WithProxyURL` variants for `CodexAuth`, `ClaudeAuth`, `IFlowAuth`, and `DeviceFlowClient`. - Updated executors to use proxy-aware constructors for improved configurability. - Added unit tests to validate proxy override precedence and functionality. Closes: #2823
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package kimi
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
|
)
|
|
|
|
func TestNewDeviceFlowClientWithDeviceIDAndProxyURL_OverrideDirectDisablesProxy(t *testing.T) {
|
|
cfg := &config.Config{SDKConfig: config.SDKConfig{ProxyURL: "http://proxy.example.com:8080"}}
|
|
client := NewDeviceFlowClientWithDeviceIDAndProxyURL(cfg, "device-1", "direct")
|
|
|
|
transport, ok := client.httpClient.Transport.(*http.Transport)
|
|
if !ok || transport == nil {
|
|
t.Fatalf("expected http.Transport, got %T", client.httpClient.Transport)
|
|
}
|
|
if transport.Proxy != nil {
|
|
t.Fatal("expected direct transport to disable proxy function")
|
|
}
|
|
}
|
|
|
|
func TestNewDeviceFlowClientWithDeviceIDAndProxyURL_OverrideProxyTakesPrecedence(t *testing.T) {
|
|
cfg := &config.Config{SDKConfig: config.SDKConfig{ProxyURL: "http://global.example.com:8080"}}
|
|
client := NewDeviceFlowClientWithDeviceIDAndProxyURL(cfg, "device-1", "http://override.example.com:8081")
|
|
|
|
transport, ok := client.httpClient.Transport.(*http.Transport)
|
|
if !ok || transport == nil {
|
|
t.Fatalf("expected http.Transport, got %T", client.httpClient.Transport)
|
|
}
|
|
req, errReq := http.NewRequest(http.MethodGet, "https://example.com", nil)
|
|
if errReq != nil {
|
|
t.Fatalf("new request: %v", errReq)
|
|
}
|
|
proxyURL, errProxy := transport.Proxy(req)
|
|
if errProxy != nil {
|
|
t.Fatalf("proxy func: %v", errProxy)
|
|
}
|
|
if proxyURL == nil || proxyURL.String() != "http://override.example.com:8081" {
|
|
t.Fatalf("proxy URL = %v, want http://override.example.com:8081", proxyURL)
|
|
}
|
|
}
|