From 160fa252ef5e795dc32597c7a7e201f37be292c5 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 27 Sep 2023 12:43:15 +0100 Subject: [PATCH 1/4] fix: avoid logging env in unit tests --- cli/root.go | 1 - cli/ssh_test.go | 2 +- pty/start_other_test.go | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cli/root.go b/cli/root.go index c8103540df31c..1530318e13144 100644 --- a/cli/root.go +++ b/cli/root.go @@ -161,7 +161,6 @@ func (r *RootCmd) Command(subcommands []*clibase.Cmd) (*clibase.Cmd, error) { }, ), Handler: func(i *clibase.Invocation) error { - // fmt.Fprintf(i.Stderr, "env debug: %+v", i.Environ) // The GIT_ASKPASS environment variable must point at // a binary with no arguments. To prevent writing // cross-platform scripts to invoke the Coder binary diff --git a/cli/ssh_test.go b/cli/ssh_test.go index 2a371d5d0544f..698a54e9dbd2c 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -368,7 +368,7 @@ func TestSSH(t *testing.T) { // Ensure that SSH_AUTH_SOCK is set. // Linux: /tmp/auth-agent3167016167/listener.sock // macOS: /var/folders/ng/m1q0wft14hj0t3rtjxrdnzsr0000gn/T/auth-agent3245553419/listener.sock - pty.WriteLine("env") + pty.WriteLine(`grep --perl-regexp --binary-files=text 'SSH_AUTH_SOCK=[^\x00]+' /proc/self/environ`) pty.ExpectMatch("SSH_AUTH_SOCK=") // Ensure that ssh-add lists our key. pty.WriteLine("ssh-add -L") diff --git a/pty/start_other_test.go b/pty/start_other_test.go index 57fc9e4847832..dd26b59bf4c72 100644 --- a/pty/start_other_test.go +++ b/pty/start_other_test.go @@ -54,7 +54,7 @@ func TestStart(t *testing.T) { Height: 24, }, })) - pty, ps := ptytest.Start(t, pty.Command("env"), opts) + pty, ps := ptytest.Start(t, pty.Command("grep", "--binary-files=text", `SSH_TTY=/dev/`, "/proc/self/environ"), opts) pty.ExpectMatch("SSH_TTY=/dev/") err := ps.Wait() require.NoError(t, err) From 849d2bc4f3095d4b40f499c86f919344ee1ff2d1 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 27 Sep 2023 13:21:26 +0100 Subject: [PATCH 2/4] be more cross-platform --- cli/ssh_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index 698a54e9dbd2c..4752b21e65a49 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -368,7 +368,7 @@ func TestSSH(t *testing.T) { // Ensure that SSH_AUTH_SOCK is set. // Linux: /tmp/auth-agent3167016167/listener.sock // macOS: /var/folders/ng/m1q0wft14hj0t3rtjxrdnzsr0000gn/T/auth-agent3245553419/listener.sock - pty.WriteLine(`grep --perl-regexp --binary-files=text 'SSH_AUTH_SOCK=[^\x00]+' /proc/self/environ`) + pty.WriteLine(`echo -n SSH_AUTH_SOCK=${SSH_AUTH_SOCK}`) pty.ExpectMatch("SSH_AUTH_SOCK=") // Ensure that ssh-add lists our key. pty.WriteLine("ssh-add -L") From 00ab29efdfdfd3877472d4de119dd6536f2114b9 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 27 Sep 2023 13:23:32 +0100 Subject: [PATCH 3/4] fixup! be more cross-platform --- pty/start_other_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pty/start_other_test.go b/pty/start_other_test.go index dd26b59bf4c72..63b6a36e8cea7 100644 --- a/pty/start_other_test.go +++ b/pty/start_other_test.go @@ -54,7 +54,7 @@ func TestStart(t *testing.T) { Height: 24, }, })) - pty, ps := ptytest.Start(t, pty.Command("grep", "--binary-files=text", `SSH_TTY=/dev/`, "/proc/self/environ"), opts) + pty, ps := ptytest.Start(t, pty.Command(`/bin/sh`, `-c`, `env | grep SSH_TTY`), opts) pty.ExpectMatch("SSH_TTY=/dev/") err := ps.Wait() require.NoError(t, err) From cede0b18e6b98245d7c6af7fc292f2db9b840386 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Wed, 27 Sep 2023 13:25:54 +0100 Subject: [PATCH 4/4] converge on env grep thing --- cli/ssh_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index 4752b21e65a49..90b34ca9f4b70 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -368,7 +368,7 @@ func TestSSH(t *testing.T) { // Ensure that SSH_AUTH_SOCK is set. // Linux: /tmp/auth-agent3167016167/listener.sock // macOS: /var/folders/ng/m1q0wft14hj0t3rtjxrdnzsr0000gn/T/auth-agent3245553419/listener.sock - pty.WriteLine(`echo -n SSH_AUTH_SOCK=${SSH_AUTH_SOCK}`) + pty.WriteLine(`env | grep SSH_AUTH_SOCK=`) pty.ExpectMatch("SSH_AUTH_SOCK=") // Ensure that ssh-add lists our key. pty.WriteLine("ssh-add -L")