@@ -51,13 +51,13 @@ def test_including_the_env_with_string_keys
5151 def test_double_quotes_are_escaped_in_env
5252 SSHKit . config = nil
5353 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
5555 end
5656
5757 def test_percentage_symbol_handled_in_env
5858 SSHKit . config = nil
5959 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
6161 end
6262
6363 def test_including_the_env_doesnt_addressively_escape
@@ -84,6 +84,11 @@ def test_working_in_a_given_directory
8484 assert_equal "cd /opt/sites && /usr/bin/env ls -l" , c . to_command
8585 end
8686
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+
8792 def test_working_in_a_given_directory_with_env
8893 c = Command . new ( :ls , '-l' , in : "/opt/sites" , env : { a : :b } )
8994 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
97102
98103 def test_working_as_a_given_user
99104 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
101111 end
102112
103113 def test_working_as_a_given_group
104114 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
106121 end
107122
108123 def test_working_as_a_given_user_and_group
109124 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
111126 end
112127
113128 def test_umask
@@ -125,13 +140,13 @@ def test_umask_with_working_directory
125140 def test_umask_with_working_directory_and_user
126141 SSHKit . config . umask = '007'
127142 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
129144 end
130145
131146 def test_umask_with_env_and_working_directory_and_user
132147 SSHKit . config . umask = '007'
133148 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
135150 end
136151
137152 def test_verbosity_defaults_to_logger_info
0 commit comments