plugin: Bun's release check asks GitHub's API with the GitHub token from Settings too (#1942, bingqilinweimaotai)
What changed: an audit of every request magpie makes to GitHub's API after the git-plugin fix. The library's skill checks, private-repo probes and RTK's release check already carried the token; the Plugins page's git-plugin check and topic search got it in the previous commit. The one left was Bun's newest-release check (bunLatest), asked of api.github.com/repos/oven-sh/bun/releases/latest anonymously through getURL. getURLFrom now has a request to GitHub's API's host carry the token (ghtoken.Authorize), and bunLatest asks githubAPI so tests can move it. Bun's zips (github.com, npmmirror) are other hosts and never get it. With a token set, that one request isn't sent to the MAGPIE_MIRRORS fallback (source.Do sends nothing with Authorization to a mirror), the same as the library's API requests. Left as they are: Copilot's api.github.com requests carry the user's Copilot sign-in, not this token; raw.githubusercontent.com and codeload aren't the rate-limited REST API; site/worker.js is the website's. What was run: - TestBunReleaseCheckCarriesGitHubToken (new): bunLatest is asked with "Bearer github-env", a download from another host with none. With the Authorize call removed it fails: "Bun's release was asked of GitHub's API with Authorization """. - go test -tags nogui -run 'Bun' ./internal/plugin: ok. - gofmt -l clean; go vet -tags nogui darwin, GOOS=linux, GOOS=windows on internal/plugin: clean.
This commit is contained in:
@@ -169,3 +169,39 @@ func TestGitPluginCheckCarriesGitHubToken(t *testing.T) {
|
||||
t.Errorf("a host other than GitHub's API was sent Authorization %q", rawAuth)
|
||||
}
|
||||
}
|
||||
|
||||
// Bun's newest release, asked of GitHub's API, carries the token too; a
|
||||
// Bun download from another host never does (#1942).
|
||||
func TestBunReleaseCheckCarriesGitHubToken(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("HOME", dir)
|
||||
t.Setenv("USERPROFILE", dir)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "config"))
|
||||
t.Setenv("GITHUB_TOKEN", "github-env")
|
||||
var apiAuth, dlAuth string
|
||||
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
apiAuth = r.Header.Get("Authorization")
|
||||
fmt.Fprint(w, `{"tag_name":"bun-v1.4.2","published_at":"2026-10-01T00:00:00Z"}`)
|
||||
}))
|
||||
t.Cleanup(api.Close)
|
||||
dl := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
dlAuth = r.Header.Get("Authorization")
|
||||
fmt.Fprint(w, "zip")
|
||||
}))
|
||||
t.Cleanup(dl.Close)
|
||||
was := githubAPI
|
||||
githubAPI = api.URL
|
||||
t.Cleanup(func() { githubAPI = was })
|
||||
if v, _, err := bunLatest(context.Background()); err != nil || v != "1.4.2" {
|
||||
t.Fatalf("bunLatest = %q, %v", v, err)
|
||||
}
|
||||
if apiAuth != "Bearer github-env" {
|
||||
t.Errorf("Bun's release was asked of GitHub's API with Authorization %q", apiAuth)
|
||||
}
|
||||
if _, err := getURL(context.Background(), dl.URL+"/bun-darwin-aarch64.zip", 1<<10); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if dlAuth != "" {
|
||||
t.Errorf("a download from another host was sent Authorization %q", dlAuth)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user