package forge import ( "context" "encoding/base64" "os" "path/filepath" "strings" "testing" "amadan.net/oficina/equipo/internal/runner/workspace" ) func TestBranchGitUsesRemoteUsername(t *testing.T) { dir := t.TempDir() script := filepath.Join(dir, "git") if err := os.WriteFile(script, []byte("#!/bin/sh\nprintf '%s' \"$GIT_CONFIG_VALUE_9\"\n"), 0700); err != nil { t.Fatal(err) } b := BranchPush{Git: script, GitDir: dir} for _, user := range []string{"", "x-access-token"} { remote := workspace.Remote{URL: "https://amadan.net/o/r", GitPassword: "fixture-password", GitUsername: user} got, err := b.git(context.Background(), dir, &remote, "push") wantUser := user if wantUser == "" { wantUser = "x" } want := "Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte(wantUser+":fixture-password")) if err != nil || got != want { t.Fatalf("git authentication user %q: %q %v", user, got, err) } } } func TestPushDetailScrubsRemoteUsername(t *testing.T) { remote := workspace.Remote{URL: "https://github.com/o/r", GitPassword: "abc12345", GitUsername: "x-access-token"} encoded := base64.StdEncoding.EncodeToString([]byte(remote.Username() + ":" + remote.GitPassword)) answer := pushAnswer("! rejected", "remote: diagnostic "+encoded+" "+remote.GitPassword, &remote) tail := PushDetail(&PushError{Op: "push", Answer: answer, Err: ErrPushUncertain}) if strings.Contains(tail, encoded) || strings.Contains(tail, remote.GitPassword) || !strings.Contains(tail, "diagnostic") { t.Fatalf("credentials leaked or detail lost: %q", tail) } }