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 <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Han-Wen Nienhuys <hanwen@google.com>
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 @@
"os/exec"
"path/filepath"
"strconv"
+ "strings"
"sync"
"testing"
"time"
@@ -35,17 +36,19 @@
}
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")