Skip to content

Commit 24f8e6a

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

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
@@ -232,6 +232,30 @@ func TestAgent(t *testing.T) {
232232
require.Equal(t, expect, strings.TrimSpace(string(output)))
233233
})
234234

235+
t.Run("SSH connection env vars", func(t *testing.T) {
236+
t.Parallel()
237+
238+
// Note: the SSH_TTY environment variable should only be set for TTYs.
239+
for _, key := range []string{"SSH_CONNECTION", "SSH_CLIENT", "SSH_TTY"} {
240+
key := key
241+
t.Run(key, func(t *testing.T) {
242+
t.Parallel()
243+
244+
command := "sh -c 'echo $" + key + "'"
245+
if runtime.GOOS == "windows" {
246+
if key == "SSH_TTY" {
247+
t.Skip("The SSH_PTY environment variable is not set on Windows")
248+
}
249+
command = "cmd.exe /c echo %" + key + "%"
250+
}
251+
session := setupSSHSession(t, agent.Metadata{})
252+
output, err := session.Output(command)
253+
require.NoError(t, err)
254+
require.NotEmpty(t, strings.TrimSpace(string(output)))
255+
})
256+
}
257+
})
258+
235259
t.Run("StartupScript", func(t *testing.T) {
236260
t.Parallel()
237261
tempPath := filepath.Join(t.TempDir(), "content.txt")

0 commit comments

Comments
 (0)