-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ssh: implement Git SSH variant selection
We'd implemented Git's autodetection of SSH variants in the past, but we hadn't implemented the newer explicit SSH selection. Since we're about to pass some additional options to our ssh binaries, let's implement the proper variant using GIT_SSH_VARIANT and ssh.variant. Roughly, the algorithm is this: GIT_SSH_VARIANT overrides ssh.variant, and if neither is set, autodetection occurs. A user can specify either "ssh" (OpenSSH), "putty" (or its synonym "plink"), "tortoiseplink", or "simple", or, if they'd like the autodetection behavior, "auto". If the value is not any of these, then it is interpreted as "ssh".
- Loading branch information
Showing
2 changed files
with
158 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,44 @@ func TestSSHGetExeAndArgsPlinkCustomPort(t *testing.T) { | |
assert.Equal(t, []string{"-P", "8888", "[email protected]"}, args) | ||
} | ||
|
||
func TestSSHGetExeAndArgsPlinkCustomPortExplicitEnvironment(t *testing.T) { | ||
plink := filepath.Join("Users", "joebloggs", "bin", "ssh") | ||
|
||
cli, err := lfshttp.NewClient(lfshttp.NewContext(nil, map[string]string{ | ||
"GIT_SSH_COMMAND": "", | ||
"GIT_SSH": plink, | ||
"GIT_SSH_VARIANT": "plink", | ||
}, nil)) | ||
require.Nil(t, err) | ||
|
||
meta := SSHMetadata{} | ||
meta.UserAndHost = "[email protected]" | ||
meta.Port = "8888" | ||
|
||
exe, args := formatArgs(getExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta)) | ||
assert.Equal(t, plink, exe) | ||
assert.Equal(t, []string{"-P", "8888", "[email protected]"}, args) | ||
} | ||
|
||
func TestSSHGetExeAndArgsPlinkCustomPortExplicitEnvironmentPutty(t *testing.T) { | ||
plink := filepath.Join("Users", "joebloggs", "bin", "ssh") | ||
|
||
cli, err := lfshttp.NewClient(lfshttp.NewContext(nil, map[string]string{ | ||
"GIT_SSH_COMMAND": "", | ||
"GIT_SSH": plink, | ||
"GIT_SSH_VARIANT": "putty", | ||
}, nil)) | ||
require.Nil(t, err) | ||
|
||
meta := SSHMetadata{} | ||
meta.UserAndHost = "[email protected]" | ||
meta.Port = "8888" | ||
|
||
exe, args := formatArgs(getExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta)) | ||
assert.Equal(t, plink, exe) | ||
assert.Equal(t, []string{"-P", "8888", "[email protected]"}, args) | ||
} | ||
|
||
func TestSSHGetExeAndArgsTortoisePlink(t *testing.T) { | ||
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink.exe") | ||
|
||
|
@@ -152,6 +190,66 @@ func TestSSHGetExeAndArgsTortoisePlinkCustomPort(t *testing.T) { | |
assert.Equal(t, []string{"-batch", "-P", "8888", "[email protected]"}, args) | ||
} | ||
|
||
func TestSSHGetExeAndArgsTortoisePlinkCustomPortExplicitEnvironment(t *testing.T) { | ||
plink := filepath.Join("Users", "joebloggs", "bin", "ssh") | ||
|
||
cli, err := lfshttp.NewClient(lfshttp.NewContext(nil, map[string]string{ | ||
"GIT_SSH_COMMAND": "", | ||
"GIT_SSH": plink, | ||
"GIT_SSH_VARIANT": "tortoiseplink", | ||
}, nil)) | ||
require.Nil(t, err) | ||
|
||
meta := SSHMetadata{} | ||
meta.UserAndHost = "[email protected]" | ||
meta.Port = "8888" | ||
|
||
exe, args := formatArgs(getExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta)) | ||
assert.Equal(t, plink, exe) | ||
assert.Equal(t, []string{"-batch", "-P", "8888", "[email protected]"}, args) | ||
} | ||
|
||
func TestSSHGetExeAndArgsTortoisePlinkCustomPortExplicitConfig(t *testing.T) { | ||
plink := filepath.Join("Users", "joebloggs", "bin", "ssh") | ||
|
||
cli, err := lfshttp.NewClient(lfshttp.NewContext(nil, map[string]string{ | ||
"GIT_SSH_COMMAND": "", | ||
"GIT_SSH": plink, | ||
"GIT_SSH_VARIANT": "tortoiseplink", | ||
}, map[string]string{ | ||
"ssh.variant": "tortoiseplink", | ||
})) | ||
require.Nil(t, err) | ||
|
||
meta := SSHMetadata{} | ||
meta.UserAndHost = "[email protected]" | ||
meta.Port = "8888" | ||
|
||
exe, args := formatArgs(getExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta)) | ||
assert.Equal(t, plink, exe) | ||
assert.Equal(t, []string{"-batch", "-P", "8888", "[email protected]"}, args) | ||
} | ||
|
||
func TestSSHGetExeAndArgsTortoisePlinkCustomPortExplicitConfigOverride(t *testing.T) { | ||
plink := filepath.Join("Users", "joebloggs", "bin", "ssh") | ||
|
||
cli, err := lfshttp.NewClient(lfshttp.NewContext(nil, map[string]string{ | ||
"GIT_SSH_COMMAND": "", | ||
"GIT_SSH": plink, | ||
}, map[string]string{ | ||
"ssh.variant": "putty", | ||
})) | ||
require.Nil(t, err) | ||
|
||
meta := SSHMetadata{} | ||
meta.UserAndHost = "[email protected]" | ||
meta.Port = "8888" | ||
|
||
exe, args := formatArgs(getExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta)) | ||
assert.Equal(t, plink, exe) | ||
assert.Equal(t, []string{"-batch", "-P", "8888", "[email protected]"}, args) | ||
} | ||
|
||
func TestSSHGetExeAndArgsSshCommandPrecedence(t *testing.T) { | ||
cli, err := lfshttp.NewClient(lfshttp.NewContext(nil, map[string]string{ | ||
"GIT_SSH_COMMAND": "sshcmd", | ||
|