From 4f8c1d86b1ba699e7a66cd649947ed270a74e0bb Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 19 Nov 2019 16:07:44 -0500 Subject: [PATCH] ssh/agent: clear the environment when starting ssh-agent in client_test Certain environment variables can influence the behavior of ssh-agent, causing the test to fail. Avoid that influence by using a consistent environment. This fixes a locally-observed test failure for me. Change-Id: I0f5e8d643199519f88e80825335ee8e6eb08e3af Reviewed-on: https://go-review.googlesource.com/c/crypto/+/207901 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Han-Wen Nienhuys --- ssh/agent/client_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ssh/agent/client_test.go b/ssh/agent/client_test.go index c31853a..71e9db1 100644 --- a/ssh/agent/client_test.go +++ b/ssh/agent/client_test.go @@ -14,6 +14,7 @@ import ( "os/exec" "path/filepath" "strconv" + "strings" "sync" "testing" "time" @@ -35,17 +36,19 @@ func startOpenSSHAgent(t *testing.T) (client ExtendedAgent, socket string, clean } cmd := exec.Command(bin, "-s") + cmd.Env = []string{} // Do not let the user's environment influence ssh-agent behavior. + cmd.Stderr = new(bytes.Buffer) out, err := cmd.Output() if err != nil { - t.Fatalf("cmd.Output: %v", err) + t.Fatalf("%s failed: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr) } - /* Output looks like: + // Output looks like: + // + // SSH_AUTH_SOCK=/tmp/ssh-P65gpcqArqvH/agent.15541; export SSH_AUTH_SOCK; + // SSH_AGENT_PID=15542; export SSH_AGENT_PID; + // echo Agent pid 15542; - SSH_AUTH_SOCK=/tmp/ssh-P65gpcqArqvH/agent.15541; export SSH_AUTH_SOCK; - SSH_AGENT_PID=15542; export SSH_AGENT_PID; - echo Agent pid 15542; - */ fields := bytes.Split(out, []byte(";")) line := bytes.SplitN(fields[0], []byte("="), 2) line[0] = bytes.TrimLeft(line[0], "\n")