@@ -51,13 +51,13 @@ def test_including_the_env_with_string_keys
51
51
def test_double_quotes_are_escaped_in_env
52
52
SSHKit . config = nil
53
53
c = Command . new ( :rails , 'server' , env : { foo : 'asdf"hjkl' } )
54
- assert_equal %{( export FOO="asdf\\ \ " hjkl" ; /usr/bin/env rails server )} , c . to_command
54
+ assert_equal %{( export FOO="asdf\\ "hjkl" ; /usr/bin/env rails server )} , c . to_command
55
55
end
56
56
57
57
def test_percentage_symbol_handled_in_env
58
58
SSHKit . config = nil
59
59
c = Command . new ( :rails , 'server' , env : { foo : 'asdf%hjkl' } , user : "anotheruser" )
60
- assert_equal %{( export FOO="asdf%hjkl" ; sudo -u anotheruser FOO=\" asdf%hjkl\" -- sh -c ' /usr/bin/env rails server' )} , c . to_command
60
+ assert_equal %{( export FOO="asdf%hjkl" ; sudo -u anotheruser FOO=\" asdf%hjkl\" -- sh -c /usr/bin/env\\ rails\\ server )} , c . to_command
61
61
end
62
62
63
63
def test_including_the_env_doesnt_addressively_escape
@@ -84,6 +84,11 @@ def test_working_in_a_given_directory
84
84
assert_equal "cd /opt/sites && /usr/bin/env ls -l" , c . to_command
85
85
end
86
86
87
+ def test_working_in_a_given_weird_directory
88
+ c = Command . new ( :ls , '-l' , in : "/opt/sites and stuff" )
89
+ assert_equal "cd /opt/sites\\ and\\ stuff && /usr/bin/env ls -l" , c . to_command
90
+ end
91
+
87
92
def test_working_in_a_given_directory_with_env
88
93
c = Command . new ( :ls , '-l' , in : "/opt/sites" , env : { a : :b } )
89
94
assert_equal %{cd /opt/sites && ( export A="b" ; /usr/bin/env ls -l )} , c . to_command
@@ -97,17 +102,27 @@ def test_having_a_host_passed
97
102
98
103
def test_working_as_a_given_user
99
104
c = Command . new ( :whoami , user : :anotheruser )
100
- assert_equal "sudo -u anotheruser -- sh -c '/usr/bin/env whoami'" , c . to_command
105
+ assert_equal "sudo -u anotheruser -- sh -c /usr/bin/env\\ whoami" , c . to_command
106
+ end
107
+
108
+ def test_working_as_a_given_weird_user
109
+ c = Command . new ( :whoami , user : "mr space |" )
110
+ assert_equal "sudo -u mr\\ space\\ \\ | -- sh -c /usr/bin/env\\ whoami" , c . to_command
101
111
end
102
112
103
113
def test_working_as_a_given_group
104
114
c = Command . new ( :whoami , group : :devvers )
105
- assert_equal 'sg devvers -c "/usr/bin/env whoami"' , c . to_command
115
+ assert_equal 'sg devvers -c /usr/bin/env\\ whoami' , c . to_command
116
+ end
117
+
118
+ def test_working_as_a_given_weird_group
119
+ c = Command . new ( :whoami , group : "space | group" )
120
+ assert_equal "sg space\\ \\ |\\ group -c /usr/bin/env\\ whoami" , c . to_command
106
121
end
107
122
108
123
def test_working_as_a_given_user_and_group
109
124
c = Command . new ( :whoami , user : :anotheruser , group : :devvers )
110
- assert_equal %Q(sudo -u anotheruser -- sh -c 'sg devvers -c " /usr/bin/env whoami"' ) , c . to_command
125
+ assert_equal %Q(sudo -u anotheruser -- sh -c sg \\ devvers\\ -c\\ /usr/bin/env\\ \\ \\ whoami) , c . to_command
111
126
end
112
127
113
128
def test_umask
@@ -125,13 +140,13 @@ def test_umask_with_working_directory
125
140
def test_umask_with_working_directory_and_user
126
141
SSHKit . config . umask = '007'
127
142
c = Command . new ( :touch , 'somefile' , in : '/var' , user : 'alice' )
128
- assert_equal "cd /var && umask 007 && sudo -u alice -- sh -c ' /usr/bin/env touch somefile' " , c . to_command
143
+ assert_equal "cd /var && umask 007 && sudo -u alice -- sh -c /usr/bin/env\\ touch\\ somefile" , c . to_command
129
144
end
130
145
131
146
def test_umask_with_env_and_working_directory_and_user
132
147
SSHKit . config . umask = '007'
133
148
c = Command . new ( :touch , 'somefile' , user : 'bob' , env : { a : 'b' } , in : '/var' )
134
- assert_equal %{cd /var && umask 007 && ( export A="b" ; sudo -u bob A="b" -- sh -c ' /usr/bin/env touch somefile' )} , c . to_command
149
+ assert_equal %{cd /var && umask 007 && ( export A="b" ; sudo -u bob A="b" -- sh -c /usr/bin/env\\ touch\\ somefile )} , c . to_command
135
150
end
136
151
137
152
def test_verbosity_defaults_to_logger_info
0 commit comments