mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-14 12:25:18 +08:00
- Added `applyCodexIdentityConfuse*` functions for remapping request and response payloads and headers to enhance security. - Updated WebSocket and HTTP logic to handle identity state transformations seamlessly. - Introduced unit tests to verify remapping and restoration of identity-related fields.
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadConfigOptional_CodexHeaderDefaults(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configPath := filepath.Join(dir, "config.yaml")
|
|
configYAML := []byte(`
|
|
codex-header-defaults:
|
|
user-agent: " my-codex-client/1.0 "
|
|
beta-features: " feature-a,feature-b "
|
|
`)
|
|
if err := os.WriteFile(configPath, configYAML, 0o600); err != nil {
|
|
t.Fatalf("failed to write config: %v", err)
|
|
}
|
|
|
|
cfg, err := LoadConfigOptional(configPath, false)
|
|
if err != nil {
|
|
t.Fatalf("LoadConfigOptional() error = %v", err)
|
|
}
|
|
|
|
if got := cfg.CodexHeaderDefaults.UserAgent; got != "my-codex-client/1.0" {
|
|
t.Fatalf("UserAgent = %q, want %q", got, "my-codex-client/1.0")
|
|
}
|
|
if got := cfg.CodexHeaderDefaults.BetaFeatures; got != "feature-a,feature-b" {
|
|
t.Fatalf("BetaFeatures = %q, want %q", got, "feature-a,feature-b")
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigOptional_CodexIdentityConfuse(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configPath := filepath.Join(dir, "config.yaml")
|
|
configYAML := []byte(`
|
|
codex:
|
|
identity-confuse: true
|
|
`)
|
|
if err := os.WriteFile(configPath, configYAML, 0o600); err != nil {
|
|
t.Fatalf("failed to write config: %v", err)
|
|
}
|
|
|
|
cfg, err := LoadConfigOptional(configPath, false)
|
|
if err != nil {
|
|
t.Fatalf("LoadConfigOptional() error = %v", err)
|
|
}
|
|
|
|
if !cfg.Codex.IdentityConfuse {
|
|
t.Fatalf("IdentityConfuse = false, want true")
|
|
}
|
|
}
|