|
6 | 6 | "testing" |
7 | 7 |
|
8 | 8 | "github.com/router-for-me/CLIProxyAPI/v6/internal/thinking" |
| 9 | + cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth" |
9 | 10 | "github.com/tidwall/gjson" |
10 | 11 | ) |
11 | 12 |
|
@@ -176,3 +177,35 @@ func TestWrapQwenError_Maps403QuotaTo429WithoutRetryAfter(t *testing.T) { |
176 | 177 | t.Fatalf("wrapQwenError retryAfter = %v, want nil", *retryAfter) |
177 | 178 | } |
178 | 179 | } |
| 180 | + |
| 181 | +func TestQwenCreds_NormalizesResourceURL(t *testing.T) { |
| 182 | + tests := []struct { |
| 183 | + name string |
| 184 | + resourceURL string |
| 185 | + wantBaseURL string |
| 186 | + }{ |
| 187 | + {"host only", "portal.qwen.ai", "https://portal.qwen.ai/v1"}, |
| 188 | + {"scheme no v1", "https://portal.qwen.ai", "https://portal.qwen.ai/v1"}, |
| 189 | + {"scheme with v1", "https://portal.qwen.ai/v1", "https://portal.qwen.ai/v1"}, |
| 190 | + {"scheme with v1 slash", "https://portal.qwen.ai/v1/", "https://portal.qwen.ai/v1"}, |
| 191 | + } |
| 192 | + |
| 193 | + for _, tt := range tests { |
| 194 | + t.Run(tt.name, func(t *testing.T) { |
| 195 | + auth := &cliproxyauth.Auth{ |
| 196 | + Metadata: map[string]any{ |
| 197 | + "access_token": "test-token", |
| 198 | + "resource_url": tt.resourceURL, |
| 199 | + }, |
| 200 | + } |
| 201 | + |
| 202 | + token, baseURL := qwenCreds(auth) |
| 203 | + if token != "test-token" { |
| 204 | + t.Fatalf("qwenCreds token = %q, want %q", token, "test-token") |
| 205 | + } |
| 206 | + if baseURL != tt.wantBaseURL { |
| 207 | + t.Fatalf("qwenCreds baseURL = %q, want %q", baseURL, tt.wantBaseURL) |
| 208 | + } |
| 209 | + }) |
| 210 | + } |
| 211 | +} |
0 commit comments