mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* test(update): cover batch fetch failure warning A batch update that cannot fetch a repo counts its skills as skipped and prints nothing about it. Remove the remote after installing two grouped skills and check that update --all names the repo in a warning. * fix(update): warn when a repo fetch fails When a clone failed during update --all, the summary counted its skills as skipped and printed nothing. That hid a repo that timed out on every run. Print the repo and the error. * fix(update): redact credentials in fetch warning The fetch warning printed the stored repo URL as is. An HTTPS URL can carry a token as userinfo, and git error text can echo that URL, so the token reached stdout and CI logs. Name the repo with DisplayURL, which already strips userinfo for submodule URLs, and redact the userinfo from the error text. * fix(update): redact query tokens in fetch warning The fetch warning redacted only the userinfo of the repo URL. A token in the query survived in the error text, since git echoes the full URL. And DisplayURL treats the last "@" anywhere as the end of userinfo, so an "@" in the path named a different repo. Parse http(s) repo URLs the way git does: userinfo ends at the last "@" before the first "/", and the query and fragment go too. Remove the same parts from the error text. Other URLs print unchanged. DisplayURL goes back to being private to submodule.go. --------- Co-authored-by: Willie <egg358358@gmail.com>
109 lines
3.4 KiB
Go
109 lines
3.4 KiB
Go
//go:build !online
|
|
|
|
package integration
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/testutil"
|
|
)
|
|
|
|
// In a batch update, a repo that could not be fetched used to count its
|
|
// skills as skipped without any message. (A single target already reports
|
|
// the error through the verbose path.)
|
|
func TestUpdateAll_WarnsWhenRepoFetchFails(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
setupGlobalConfig(sb)
|
|
|
|
remote := filepath.Join(sb.Root, "unreachable.git")
|
|
work := filepath.Join(sb.Root, "unreachable-work")
|
|
gitInit(t, remote, true)
|
|
gitClone(t, remote, work)
|
|
for _, name := range []string{"alpha", "beta"} {
|
|
dir := filepath.Join(work, "skills", name)
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := "---\nname: " + name + "\n---\n# " + name + "\n"
|
|
if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte(body), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
gitAddCommit(t, work, "add skills")
|
|
gitPush(t, work)
|
|
for _, name := range []string{"alpha", "beta"} {
|
|
sb.RunCLI("install", "file://"+remote+"//skills/"+name, "--skip-audit").AssertSuccess(t)
|
|
}
|
|
|
|
if err := os.RemoveAll(remote); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
result := sb.RunCLI("update", "--all", "--skip-audit")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Could not fetch")
|
|
result.AssertAnyOutputContains(t, "unreachable.git")
|
|
result.AssertAnyOutputContains(t, "2 skipped")
|
|
}
|
|
|
|
// The stored repo URL can carry a token as userinfo or in its query. The
|
|
// warning must name the repo without it, must not echo it through git's error
|
|
// text, and must keep an "@" that is part of the path.
|
|
func TestUpdateAll_FetchWarningRedactsURLCredentials(t *testing.T) {
|
|
// Nothing listens on port 1, so every clone fails right away.
|
|
tests := []struct {
|
|
name, repoURL, want string
|
|
leaks []string
|
|
}{
|
|
{"userinfo", "https://someone:s3cret-token@127.0.0.1:1/owner/skills.git", "https://127.0.0.1:1/owner/skills.git", []string{"s3cret-token", "someone:"}},
|
|
{"query token", "https://127.0.0.1:1/owner/skills.git?token=s3cret-token", "https://127.0.0.1:1/owner/skills.git", []string{"s3cret-token"}},
|
|
{"at sign in path", "https://127.0.0.1:1/team@archive/skills.git", "https://127.0.0.1:1/team@archive/skills.git", nil},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
setupGlobalConfig(sb)
|
|
|
|
store, err := install.LoadMetadata(sb.SourcePath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, name := range []string{"alpha", "beta"} {
|
|
dir := filepath.Join(sb.SourcePath, name)
|
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := "---\nname: " + name + "\n---\n# " + name + "\n"
|
|
if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte(body), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
store.Set(name, &install.MetadataEntry{
|
|
Source: tt.repoURL + "//skills/" + name,
|
|
Type: "git",
|
|
RepoURL: tt.repoURL,
|
|
Subdir: "skills/" + name,
|
|
})
|
|
}
|
|
if err := store.Save(sb.SourcePath); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
result := sb.RunCLI("update", "--all", "--skip-audit")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Could not fetch "+tt.want+":")
|
|
out := result.Stdout + result.Stderr
|
|
for _, leak := range tt.leaks {
|
|
if strings.Contains(out, leak) {
|
|
t.Fatalf("fetch warning leaked %q:\n%s", leak, out)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|