feat: Set SSH env vars: SSH_CLIENT, SSH_CONNECTION and SSH_TTY (#3622)

Fixes #2339
This commit is contained in:
Mathias Fredriksson
2022-08-23 21:19:57 +03:00
committed by GitHub
parent 9c0cd5287c
commit e44f7adb7e
4 changed files with 45 additions and 1 deletions

View File

@ -252,6 +252,29 @@ func TestAgent(t *testing.T) {
}
})
t.Run("SSH connection env vars", func(t *testing.T) {
t.Parallel()
// Note: the SSH_TTY environment variable should only be set for TTYs.
// For some reason this test produces a TTY locally and a non-TTY in CI
// so we don't test for the absence of SSH_TTY.
for _, key := range []string{"SSH_CONNECTION", "SSH_CLIENT"} {
key := key
t.Run(key, func(t *testing.T) {
t.Parallel()
session := setupSSHSession(t, agent.Metadata{})
command := "sh -c 'echo $" + key + "'"
if runtime.GOOS == "windows" {
command = "cmd.exe /c echo %" + key + "%"
}
output, err := session.Output(command)
require.NoError(t, err)
require.NotEmpty(t, strings.TrimSpace(string(output)))
})
}
})
t.Run("StartupScript", func(t *testing.T) {
t.Parallel()
tempPath := filepath.Join(t.TempDir(), "content.txt")