@@ -4,12 +4,15 @@ import (
4
4
"os"
5
5
"os/exec"
6
6
"path/filepath"
7
+ "runtime"
7
8
"strings"
8
9
"testing"
9
10
10
11
"github.com/stretchr/testify/require"
11
12
)
12
13
14
+ // This test tries to mimic the behavior of OpenSSH
15
+ // when executing e.g. a ProxyCommand.
13
16
func Test_sshConfigExecEscape (t * testing.T ) {
14
17
t .Parallel ()
15
18
@@ -34,7 +37,11 @@ func Test_sshConfigExecEscape(t *testing.T) {
34
37
err := os .MkdirAll (dir ,0o755 )
35
38
require .NoError (t ,err )
36
39
bin := filepath .Join (dir ,"coder" )
37
- err = os .WriteFile (bin , []byte ("#!/bin/sh\n echo yay\n " ),0o755 )//nolint:gosec
40
+ contents := []byte ("#!/bin/sh\n echo yay\n " )
41
+ if runtime .GOOS == "windows" {
42
+ contents = []byte ("cls\r \n @echo off\r \n echo\" yay\" \r \n " )
43
+ }
44
+ err = os .WriteFile (bin ,contents ,0o755 )//nolint:gosec
38
45
require .NoError (t ,err )
39
46
40
47
escaped ,err := sshConfigExecEscape (bin )
@@ -44,7 +51,11 @@ func Test_sshConfigExecEscape(t *testing.T) {
44
51
}
45
52
require .NoError (t ,err )
46
53
47
- b ,err := exec .Command ("/bin/sh" ,"-c" ,escaped ).Output ()
54
+ args := []string {"/bin/sh" ,"-c" ,escaped }
55
+ if runtime .GOOS == "windows" {
56
+ args = []string {"cmd.exe" ,"/c" ,escaped }
57
+ }
58
+ b ,err := exec .Command (args [0 ],args [1 :]... ).Output ()
48
59
require .NoError (t ,err )
49
60
got := strings .TrimSpace (string (b ))
50
61
require .Equal (t ,"yay" ,got )