mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-11 14:47:58 +08:00
- Preserve API key entries with empty `api_key` when `base_url` is configured, and extend config dedupe/ID logic to include base URL, proxy, prefix, and headers so identities are stable. - Update config/auth handling so `auth_kind=apikey` is treated as config API-key auth even without an `api_key` field, enabling base_url-only credential records. - Ensure Gemini/Codex/XAI request path clears `Authorization`/provider auth headers when token is empty to avoid leaking unrelated auth state.
36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func TestSanitizeGeminiKeys_AllowsEmptyAPIKeyWithBaseURL(t *testing.T) {
|
|
cfg := &Config{
|
|
GeminiKey: []GeminiKey{
|
|
{APIKey: ""}, // empty key without base URL, should be dropped
|
|
{APIKey: " "}, // whitespace key without base URL, should be dropped
|
|
{APIKey: "", BaseURL: "https://custom-gemini.example.com", Headers: map[string]string{"Header-A": "1"}},
|
|
{APIKey: "", BaseURL: "https://custom-gemini.example.com", Headers: map[string]string{"Header-B": "2"}},
|
|
{APIKey: "key-1", BaseURL: "https://custom-gemini.example.com"},
|
|
},
|
|
InteractionsKey: []GeminiKey{
|
|
{APIKey: ""}, // empty key without base URL, should be dropped
|
|
{APIKey: " "}, // whitespace key without base URL, should be dropped
|
|
{APIKey: "", BaseURL: "https://custom-interactions.example.com"},
|
|
},
|
|
}
|
|
cfg.SanitizeGeminiKeys()
|
|
cfg.SanitizeInteractionsKeys()
|
|
|
|
if len(cfg.GeminiKey) != 3 {
|
|
t.Fatalf("expected 3 GeminiKey entries, got %d", len(cfg.GeminiKey))
|
|
}
|
|
if cfg.GeminiKey[0].BaseURL != "https://custom-gemini.example.com" {
|
|
t.Fatalf("expected BaseURL https://custom-gemini.example.com, got %s", cfg.GeminiKey[0].BaseURL)
|
|
}
|
|
if len(cfg.InteractionsKey) != 1 {
|
|
t.Fatalf("expected 1 InteractionsKey entry, got %d", len(cfg.InteractionsKey))
|
|
}
|
|
if cfg.InteractionsKey[0].BaseURL != "https://custom-interactions.example.com" {
|
|
t.Fatalf("expected BaseURL https://custom-interactions.example.com, got %s", cfg.InteractionsKey[0].BaseURL)
|
|
}
|
|
}
|