@@ -33,60 +33,65 @@ def test_leading_and_trailing_space_is_stripped
33
33
def test_including_the_env
34
34
SSHKit . config = nil
35
35
c = Command . new ( :rails , 'server' , env : { rails_env : :production } )
36
- assert_equal %{( export RAILS_ENV="production" ; /usr/bin/env rails server )} , c . to_command
36
+ assert_equal %{( export RAILS_ENV=\ " production\ " ; /usr/bin/env rails server )} , c . to_command
37
37
end
38
38
39
39
def test_including_the_env_with_multiple_keys
40
40
SSHKit . config = nil
41
41
c = Command . new ( :rails , 'server' , env : { rails_env : :production , foo : 'bar' } )
42
- assert_equal %{( export RAILS_ENV="production" FOO="bar" ; /usr/bin/env rails server )} , c . to_command
42
+ assert_equal %{( export RAILS_ENV=\ " production\ " FOO=\ " bar\ " ; /usr/bin/env rails server )} , c . to_command
43
43
end
44
44
45
45
def test_including_the_env_with_string_keys
46
46
SSHKit . config = nil
47
47
c = Command . new ( :rails , 'server' , env : { 'FACTER_env' => :production , foo : 'bar' } )
48
- assert_equal %{( export FACTER_env="production" FOO="bar" ; /usr/bin/env rails server )} , c . to_command
48
+ assert_equal %{( export FACTER_env=\ " production\ " FOO=\ " bar\ " ; /usr/bin/env rails server )} , c . to_command
49
49
end
50
50
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
64
64
SSHKit . config = nil
65
65
c = Command . new ( :rails , 'server' , env : { path : '/example:$PATH' } )
66
- assert_equal %{( export PATH="/example:$PATH" ; /usr/bin/env rails server )} , c . to_command
66
+ assert_equal %{( export PATH=\ " /example:$PATH\ " ; /usr/bin/env rails server )} , c . to_command
67
67
end
68
68
69
69
def test_global_env
70
70
SSHKit . config = nil
71
71
SSHKit . config . default_env = { default : 'env' }
72
72
c = Command . new ( :rails , 'server' , env : { } )
73
- assert_equal %{( export DEFAULT="env" ; /usr/bin/env rails server )} , c . to_command
73
+ assert_equal %{( export DEFAULT=\ " env\ " ; /usr/bin/env rails server )} , c . to_command
74
74
end
75
75
76
76
def test_default_env_is_overwritten_with_locally_defined
77
77
SSHKit . config . default_env = { foo : 'bar' , over : 'under' }
78
78
c = Command . new ( :rails , 'server' , env : { over : 'write' } )
79
- assert_equal %{( export FOO="bar" OVER="write" ; /usr/bin/env rails server )} , c . to_command
79
+ assert_equal %{( export FOO=\ " bar\ " OVER=\ " write\ " ; /usr/bin/env rails server )} , c . to_command
80
80
end
81
81
82
82
def test_working_in_a_given_directory
83
83
c = Command . new ( :ls , '-l' , in : "/opt/sites" )
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
- assert_equal %{cd /opt/sites && ( export A="b " ; /usr/bin/env ls -l )} , c . to_command
94
+ assert_equal %{cd /opt/sites && ( export A=\" b \ " ; /usr/bin/env ls -l )} , c . to_command
90
95
end
91
96
92
97
def test_having_a_host_passed
@@ -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