feat: publish verifiable proxyctl v1
This commit is contained in:
@@ -116,39 +116,75 @@ func TestDoctorStoragePermissionCheckIsReadOnly(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaintenanceCommandsRunThroughBuiltBinaryWithIsolatedXDG(t *testing.T) {
|
||||
func TestCommandsRunAsRealProcessesInsideIsolatedUserState(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
binary := filepath.Join(root, "proxyctl")
|
||||
build := exec.Command("go", "build", "-o", binary, ".")
|
||||
binary := filepath.Join(root, "bin", "proxyctl")
|
||||
if err := os.MkdirAll(filepath.Dir(binary), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(root, "home"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
build := exec.Command("go", "build", "-tags", "proxyctl_process_test", "-o", binary, ".")
|
||||
if output, err := build.CombinedOutput(); err != nil {
|
||||
t.Fatalf("build proxyctl: %v\n%s", err, output)
|
||||
}
|
||||
environment := isolatedProcessEnvironment(root)
|
||||
|
||||
doctor := exec.Command(binary, "doctor")
|
||||
doctor.Env = environment
|
||||
doctorOutput, doctorErr := doctor.CombinedOutput()
|
||||
if doctorErr == nil || !strings.Contains(string(doctorOutput), "[FAIL]") || !strings.Contains(string(doctorOutput), "Target availability") {
|
||||
invoke := func(input string, args ...string) ([]byte, error) {
|
||||
t.Helper()
|
||||
command := exec.Command(binary, args...)
|
||||
command.Env = environment
|
||||
command.Stdin = strings.NewReader(input)
|
||||
return command.CombinedOutput()
|
||||
}
|
||||
|
||||
defaultOutput, err := invoke("q")
|
||||
if err != nil || !strings.Contains(string(defaultOutput), "proxyctl — Target panel") {
|
||||
t.Fatalf("default process err=%v output=%q", err, defaultOutput)
|
||||
}
|
||||
versionOutput, err := invoke("", "version", "--short")
|
||||
if err != nil || strings.TrimSpace(string(versionOutput)) == "" || strings.Contains(string(versionOutput), " ") {
|
||||
t.Fatalf("version process err=%v output=%q", err, versionOutput)
|
||||
}
|
||||
doctorOutput, doctorErr := invoke("", "doctor")
|
||||
if !strings.Contains(string(doctorOutput), "Profile validity") || (doctorErr != nil && !strings.Contains(string(doctorOutput), "[FAIL]")) {
|
||||
t.Fatalf("doctor process err=%v output=%q", doctorErr, doctorOutput)
|
||||
}
|
||||
|
||||
cancel := exec.Command(binary, "reset")
|
||||
cancel.Env = environment
|
||||
cancel.Stdin = strings.NewReader("no\n")
|
||||
cancelOutput, err := cancel.CombinedOutput()
|
||||
if err != nil || !strings.Contains(string(cancelOutput), "Reset cancelled") {
|
||||
t.Fatalf("cancel process err=%v output=%q", err, cancelOutput)
|
||||
resetOutput, err := invoke("no\n", "reset")
|
||||
if err != nil || !strings.Contains(string(resetOutput), "Reset cancelled") {
|
||||
t.Fatalf("reset cancellation process err=%v output=%q", err, resetOutput)
|
||||
}
|
||||
resetOutput, err = invoke("yes\n", "reset")
|
||||
if err != nil || !strings.Contains(string(resetOutput), "shell: skipped (Disabled)") {
|
||||
t.Fatalf("confirmed reset process err=%v output=%q", err, resetOutput)
|
||||
}
|
||||
installOutput, err := invoke("", "shell", "install")
|
||||
if err != nil || !strings.Contains(string(installOutput), "installed") {
|
||||
t.Fatalf("shell install process err=%v output=%q", err, installOutput)
|
||||
}
|
||||
startup := filepath.Join(root, "home", ".bashrc")
|
||||
startupData, err := os.ReadFile(startup)
|
||||
if err != nil || !strings.Contains(string(startupData), "proxyctl shell integration") {
|
||||
t.Fatalf("isolated startup after install err=%v data=%q", err, startupData)
|
||||
}
|
||||
uninstallOutput, err := invoke("", "shell", "uninstall")
|
||||
if err != nil || !strings.Contains(string(uninstallOutput), "uninstalled") {
|
||||
t.Fatalf("shell uninstall process err=%v output=%q", err, uninstallOutput)
|
||||
}
|
||||
startupData, err = os.ReadFile(startup)
|
||||
if err != nil || strings.Contains(string(startupData), "proxyctl shell integration") {
|
||||
t.Fatalf("isolated startup after uninstall err=%v data=%q", err, startupData)
|
||||
}
|
||||
|
||||
confirmed := exec.Command(binary, "reset")
|
||||
confirmed.Env = environment
|
||||
confirmed.Stdin = strings.NewReader("yes\n")
|
||||
confirmedOutput, err := confirmed.CombinedOutput()
|
||||
if err != nil || !strings.Contains(string(confirmedOutput), "shell: skipped (Disabled)") {
|
||||
t.Fatalf("confirmed process err=%v output=%q", err, confirmedOutput)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "home", ".bashrc")); !os.IsNotExist(err) {
|
||||
t.Fatalf("process smoke test touched a Shell startup file: %v", err)
|
||||
for _, path := range []string{
|
||||
filepath.Join(root, "etc"),
|
||||
filepath.Join(root, "var"),
|
||||
filepath.Join(root, "home", ".docker"),
|
||||
} {
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
t.Fatalf("process smoke created prohibited system/Docker fixture %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +201,8 @@ func isolatedProcessEnvironment(root string) []string {
|
||||
"HOME="+filepath.Join(root, "home"),
|
||||
"XDG_CONFIG_HOME="+filepath.Join(root, "config"),
|
||||
"XDG_STATE_HOME="+filepath.Join(root, "state"),
|
||||
"SHELL=/bin/fish",
|
||||
"SHELL=/bin/bash",
|
||||
"PROXYCTL_PROCESS_TEST_HOME="+filepath.Join(root, "home"),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user