Skip to content

Commit

Permalink
ssh/agent: clear the environment when starting ssh-agent in client_test
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bryan C. Mills authored and hanwen committed Nov 19, 2019
1 parent 497ca9f commit 4f8c1d8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ssh/agent/client_test.go
Expand Up @@ -14,6 +14,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
"testing"
"time"
Expand All @@ -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")
Expand Down

0 comments on commit 4f8c1d8

Please sign in to comment.