mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(server): use token auth when checking default-branch skill remotes
The dashboard check fetched the remote HEAD without credentials when a skill had no pinned branch. Private repos therefore reported an error in the dashboard while the CLI check, which uses GetRemoteHeadHashWithAuth, succeeded. The pinned-branch path already used auth, and the default-branch path now matches it.
This commit is contained in:
@@ -184,5 +184,5 @@ func (g urlBranchGroup) remoteHash() (string, error) {
|
||||
if g.branch != "" {
|
||||
return git.GetRemoteRefHashWithAuth(g.url, g.branch)
|
||||
}
|
||||
return git.GetRemoteHeadHash(g.url)
|
||||
return git.GetRemoteHeadHashWithAuth(g.url)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -71,3 +72,29 @@ func TestHandleCheck_DirtyCheckErrorReported(t *testing.T) {
|
||||
t.Fatalf("expected one repo with status error, got %+v", resp.TrackedRepos)
|
||||
}
|
||||
}
|
||||
|
||||
// TestURLBranchGroupRemoteHash_DefaultBranchUsesAuth verifies that a skill
|
||||
// without a pinned branch still probes the remote HEAD with token auth, as the
|
||||
// CLI check does. The fake git answers ls-remote only when the auth env
|
||||
// carries the token.
|
||||
func TestURLBranchGroupRemoteHash_DefaultBranchUsesAuth(t *testing.T) {
|
||||
const token = "ghp_check_default_branch_token"
|
||||
fakeBin := t.TempDir()
|
||||
script := "#!/bin/sh\n" +
|
||||
"case \"$GIT_CONFIG_KEY_0\" in *" + token + "*) ;; *) echo 'fatal: Authentication failed' >&2; exit 128;; esac\n" +
|
||||
"printf '0123456789abcdef0123456789abcdef01234567\\tHEAD\\n'\n"
|
||||
if err := os.WriteFile(filepath.Join(fakeBin, "git"), []byte(script), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", fakeBin+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
t.Setenv("GIT_CONFIG_COUNT", "")
|
||||
t.Setenv("GITHUB_TOKEN", token)
|
||||
|
||||
hash, err := urlBranchGroup{url: "https://github.com/org/private-skills.git"}.remoteHash()
|
||||
if err != nil {
|
||||
t.Fatalf("remoteHash without branch failed: %v", err)
|
||||
}
|
||||
if !strings.HasPrefix("0123456789abcdef0123456789abcdef01234567", hash) || hash == "" {
|
||||
t.Fatalf("unexpected hash %q", hash)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user