@@ -2887,3 +2887,82 @@ func TestRestoreClaudeOAuthToolNamesFromStreamLine_MixedCaseWithPrefix(t *testin
28872887 t .Fatalf ("Glob should be restored to glob, got: %s" , string (out ))
28882888 }
28892889}
2890+
2891+ func TestClaudeCredsUsesGlobalBaseURLWhenAuthHasNoBaseURL (t * testing.T ) {
2892+ apiKey , baseURL := claudeCredsWithConfig (& config.Config {ClaudeBaseURL : "http://127.0.0.1:18081" }, & cliproxyauth.Auth {
2893+ Metadata : map [string ]any {"access_token" : "oauth-token" },
2894+ })
2895+ if apiKey != "oauth-token" {
2896+ t .Fatalf ("apiKey = %q, want oauth-token" , apiKey )
2897+ }
2898+ if baseURL != "http://127.0.0.1:18081" {
2899+ t .Fatalf ("baseURL = %q, want global override" , baseURL )
2900+ }
2901+ }
2902+
2903+ func TestClaudeCredsAuthBaseURLPrecedesGlobalBaseURL (t * testing.T ) {
2904+ _ , baseURL := claudeCredsWithConfig (& config.Config {ClaudeBaseURL : "http://127.0.0.1:18081" }, & cliproxyauth.Auth {
2905+ Attributes : map [string ]string {"base_url" : "http://127.0.0.1:18101" },
2906+ Metadata : map [string ]any {"access_token" : "oauth-token" },
2907+ })
2908+ if baseURL != "http://127.0.0.1:18101" {
2909+ t .Fatalf ("baseURL = %q, want auth override" , baseURL )
2910+ }
2911+ }
2912+
2913+ func TestClaudeCredsMetadataBaseURLPrecedesGlobalBaseURL (t * testing.T ) {
2914+ _ , baseURL := claudeCredsWithConfig (& config.Config {ClaudeBaseURL : "http://127.0.0.1:18081" }, & cliproxyauth.Auth {
2915+ Metadata : map [string ]any {"access_token" : "oauth-token" , "base-url" : "http://127.0.0.1:18103/" },
2916+ })
2917+ if baseURL != "http://127.0.0.1:18103" {
2918+ t .Fatalf ("baseURL = %q, want metadata override" , baseURL )
2919+ }
2920+ }
2921+
2922+ func TestClaudeCredsDoesNotApplyGlobalBaseURLToAPIKeyAuth (t * testing.T ) {
2923+ _ , baseURL := claudeCredsWithConfig (& config.Config {ClaudeBaseURL : "http://127.0.0.1:18081" }, & cliproxyauth.Auth {
2924+ Attributes : map [string ]string {"api_key" : "sk-ant-test" },
2925+ })
2926+ if baseURL != "" {
2927+ t .Fatalf ("baseURL = %q, want empty for API-key auth without per-key base_url" , baseURL )
2928+ }
2929+ }
2930+
2931+ func TestClaudeCredsTrimsTrailingSlashFromBaseURLOverrides (t * testing.T ) {
2932+ _ , authBaseURL := claudeCredsWithConfig (& config.Config {ClaudeBaseURL : "http://127.0.0.1:18081/" }, & cliproxyauth.Auth {
2933+ Attributes : map [string ]string {"base_url" : "http://127.0.0.1:18101/" },
2934+ Metadata : map [string ]any {"access_token" : "oauth-token" },
2935+ })
2936+ if authBaseURL != "http://127.0.0.1:18101" {
2937+ t .Fatalf ("auth baseURL = %q, want trimmed trailing slash" , authBaseURL )
2938+ }
2939+
2940+ _ , globalBaseURL := claudeCredsWithConfig (& config.Config {ClaudeBaseURL : "http://127.0.0.1:18081/" }, & cliproxyauth.Auth {
2941+ Metadata : map [string ]any {"access_token" : "oauth-token" },
2942+ })
2943+ if globalBaseURL != "http://127.0.0.1:18081" {
2944+ t .Fatalf ("global baseURL = %q, want trimmed trailing slash" , globalBaseURL )
2945+ }
2946+ }
2947+
2948+ func TestResolveClaudeKeyConfigNormalizesTrailingSlashForBaseURLMatch (t * testing.T ) {
2949+ cfg := & config.Config {
2950+ ClaudeKey : []config.ClaudeKey {{
2951+ APIKey : "key-123" ,
2952+ BaseURL : "http://127.0.0.1:18101/" ,
2953+ Cloak : & config.CloakConfig {Mode : "always" },
2954+ }},
2955+ }
2956+ auth := & cliproxyauth.Auth {Attributes : map [string ]string {
2957+ "api_key" : "key-123" ,
2958+ "base_url" : "http://127.0.0.1:18101/" ,
2959+ }}
2960+
2961+ cloakCfg := resolveClaudeKeyCloakConfig (cfg , auth )
2962+ if cloakCfg == nil {
2963+ t .Fatal ("expected trailing-slash base URL to match Claude key config" )
2964+ }
2965+ if cloakCfg .Mode != "always" {
2966+ t .Fatalf ("cloak mode = %q, want always" , cloakCfg .Mode )
2967+ }
2968+ }
0 commit comments