- Notifications
You must be signed in to change notification settings - Fork928
fix: Use smarter quoting for ProxyCommand in config-ssh#3755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
b5868f6
fix: Use smarter quoting for ProxyCommand in config-ssh
mafredri218d38f
fix: Ensure `~/.ssh` directory exists
mafredri6f07ec2
fix: Add nolint
mafredridb5438a
Add tests for sshConfigExecEscape
mafredri73e6a84
Attempt windows test compat
mafredri57e9b7d
Add links to PowerShell version of OpenSSH
mafredrif65ee2b
Use combined output
mafredrif1dcdc9
Windows fs names are much more limited
mafredri14eacf9
Drop Windows tests due to different mechanism
mafredriFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
78 changes: 72 additions & 6 deletionscli/configssh.go
This file contains hidden or 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
62 changes: 62 additions & 0 deletionscli/configssh_internal_test.go
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cli | ||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
"github.com/stretchr/testify/require" | ||
) | ||
// This test tries to mimic the behavior of OpenSSH | ||
// when executing e.g. a ProxyCommand. | ||
func Test_sshConfigExecEscape(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
path string | ||
wantErr bool | ||
windows bool | ||
}{ | ||
{"no spaces", "simple", false, true}, | ||
{"spaces", "path with spaces", false, true}, | ||
{"quotes", "path with \"quotes\"", false, false}, | ||
{"backslashes", "path with \\backslashes", false, false}, | ||
{"tabs", "path with \ttabs", false, false}, | ||
{"newline fails", "path with \nnewline", true, false}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
if runtime.GOOS == "windows" { | ||
t.Skip("Windows doesn't typically execute via /bin/sh or cmd.exe, so this test is not applicable.") | ||
} | ||
dir := filepath.Join(t.TempDir(), tt.path) | ||
err := os.MkdirAll(dir, 0o755) | ||
require.NoError(t, err) | ||
bin := filepath.Join(dir, "coder") | ||
contents := []byte("#!/bin/sh\necho yay\n") | ||
err = os.WriteFile(bin, contents, 0o755) //nolint:gosec | ||
require.NoError(t, err) | ||
escaped, err := sshConfigExecEscape(bin) | ||
if tt.wantErr { | ||
require.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
b, err := exec.Command("/bin/sh", "-c", escaped).CombinedOutput() //nolint:gosec | ||
require.NoError(t, err) | ||
got := strings.TrimSpace(string(b)) | ||
require.Equal(t, "yay", got) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.