Skip to content

Commit 1f5afe3

Browse files
committed
Add test for SSH env vars
1 parent 7a015af commit 1f5afe3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

agent/agent_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,30 @@ func TestAgent(t *testing.T) {
210210
require.Equal(t, value, strings.TrimSpace(string(output)))
211211
})
212212

213+
t.Run("SSH connection env vars", func(t *testing.T) {
214+
t.Parallel()
215+
216+
// Note: the SSH_TTY environment variable should only be set for TTYs.
217+
for _, key := range []string{"SSH_CONNECTION", "SSH_CLIENT", "SSH_TTY"} {
218+
key := key
219+
t.Run(key, func(t *testing.T) {
220+
t.Parallel()
221+
222+
command := "sh -c 'echo $" + key + "'"
223+
if runtime.GOOS == "windows" {
224+
if key == "SSH_TTY" {
225+
t.Skip("The SSH_PTY environment variable is not set on Windows")
226+
}
227+
command = "cmd.exe /c echo %" + key + "%"
228+
}
229+
session := setupSSHSession(t, agent.Metadata{})
230+
output, err := session.Output(command)
231+
require.NoError(t, err)
232+
require.NotEmpty(t, strings.TrimSpace(string(output)))
233+
})
234+
}
235+
})
236+
213237
t.Run("EnvironmentVariableExpansion", func(t *testing.T) {
214238
t.Parallel()
215239
key := "EXAMPLE"

0 commit comments

Comments
 (0)