Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ The default credential routing is defined in `internal/credentials/credentials.j
| `*.anthropic.com` | `x-api-key: <key>` | `ANTHROPIC_API_KEY` |
| `*.openai.com` | `Authorization: Bearer <key>` | `OPENAI_API_KEY` |
| `*.cursor.com`, `*.cursorapi.com` | `Authorization: Bearer <key>` | `CURSOR_API_KEY` |
| `github.com`, `api.github.com` | `Authorization: Bearer <pat>` | `GH_TOKEN` |
| `*.githubusercontent.com` | `Authorization: Bearer <pat>` | `GH_TOKEN` |
| `api.github.com` | `Authorization: Bearer <pat>` | `GH_TOKEN` |
| `*.googleapis.com` | `Authorization: Bearer <token>` | gcloud ADC (auto-refresh) |

## Client Compatibility
Expand Down
25 changes: 15 additions & 10 deletions internal/credentials/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,35 +232,40 @@ func TestBuildFromConfig_GitHubBearer(t *testing.T) {
{
EnvVar: "TEST_GH_TOKEN",
InjectorType: "bearer",
Domains: []string{"github.com", "api.github.com", ".githubusercontent.com"},
Domains: []string{"api.github.com"},
},
},
}

store, _, _ := BuildFromConfig(cfg)

// Test exact domain match
req := &http.Request{
URL: &url.URL{Host: "github.com"},
URL: &url.URL{Host: "api.github.com"},
Header: make(http.Header),
}
if matched, injected := store.InjectCredentials(req); !matched || !injected {
t.Error("should match github.com")
t.Error("should match api.github.com")
}
if got := req.Header.Get("Authorization"); got != "Bearer ghp_test" {
t.Errorf("Authorization = %q, want %q", got, "Bearer ghp_test")
}

// Test suffix domain match
// github.com should NOT match (no PAT for git clone of public repos)
req2 := &http.Request{
URL: &url.URL{Host: "raw.githubusercontent.com"},
URL: &url.URL{Host: "github.com"},
Header: make(http.Header),
}
if matched, injected := store.InjectCredentials(req2); !matched || !injected {
t.Error("should match raw.githubusercontent.com")
if matched, _ := store.InjectCredentials(req2); matched {
t.Error("should not match github.com")
}
if got := req2.Header.Get("Authorization"); got != "Bearer ghp_test" {
t.Errorf("Authorization = %q, want %q", got, "Bearer ghp_test")

// raw.githubusercontent.com should NOT match
req3 := &http.Request{
URL: &url.URL{Host: "raw.githubusercontent.com"},
Header: make(http.Header),
}
if matched, _ := store.InjectCredentials(req3); matched {
t.Error("should not match raw.githubusercontent.com")
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/credentials/credentials.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
"env_var": "GH_TOKEN",
"injector": "bearer",
"domains": ["github.com", "api.github.com", ".githubusercontent.com"]
"domains": ["api.github.com"]
},
{
"env_var": "GOOGLE_APPLICATION_CREDENTIALS",
Expand Down