@@ -232,35 +232,40 @@ func TestBuildFromConfig_GitHubBearer(t *testing.T) {
232232 {
233233 EnvVar : "TEST_GH_TOKEN" ,
234234 InjectorType : "bearer" ,
235- Domains : []string {"github.com" , " api.github.com" , ".githubusercontent .com" },
235+ Domains : []string {"api.github.com" },
236236 },
237237 },
238238 }
239239
240240 store , _ , _ := BuildFromConfig (cfg )
241241
242- // Test exact domain match
243242 req := & http.Request {
244- URL : & url.URL {Host : "github.com" },
243+ URL : & url.URL {Host : "api. github.com" },
245244 Header : make (http.Header ),
246245 }
247246 if matched , injected := store .InjectCredentials (req ); ! matched || ! injected {
248- t .Error ("should match github.com" )
247+ t .Error ("should match api. github.com" )
249248 }
250249 if got := req .Header .Get ("Authorization" ); got != "Bearer ghp_test" {
251250 t .Errorf ("Authorization = %q, want %q" , got , "Bearer ghp_test" )
252251 }
253252
254- // Test suffix domain match
253+ // github.com should NOT match (no PAT for git clone of public repos)
255254 req2 := & http.Request {
256- URL : & url.URL {Host : "raw.githubusercontent .com" },
255+ URL : & url.URL {Host : "github .com" },
257256 Header : make (http.Header ),
258257 }
259- if matched , injected := store .InjectCredentials (req2 ); ! matched || ! injected {
260- t .Error ("should match raw.githubusercontent .com" )
258+ if matched , _ := store .InjectCredentials (req2 ); matched {
259+ t .Error ("should not match github .com" )
261260 }
262- if got := req2 .Header .Get ("Authorization" ); got != "Bearer ghp_test" {
263- t .Errorf ("Authorization = %q, want %q" , got , "Bearer ghp_test" )
261+
262+ // raw.githubusercontent.com should NOT match
263+ req3 := & http.Request {
264+ URL : & url.URL {Host : "raw.githubusercontent.com" },
265+ Header : make (http.Header ),
266+ }
267+ if matched , _ := store .InjectCredentials (req3 ); matched {
268+ t .Error ("should not match raw.githubusercontent.com" )
264269 }
265270}
266271
0 commit comments