1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Revert "make sudo helper play nicely with complex commands"

This reverts commit f9d2af0b24. It was a nice idea, but it wrought havoc on those people who were using sudo correctly and only granting access to certain commands.
This commit is contained in:
Jamis Buck 2008-05-24 20:53:18 -06:00
parent 32d0b9a7df
commit 461ca9611e
4 changed files with 10 additions and 8 deletions

View file

@ -1,5 +1,7 @@
*unreleased*
* Revert "make sudo helper play nicely with complex command chains", since it broke stuff [Jamis Buck]
* Make set(:default_shell, false) work for not using a shell on a per-command basis [Ryan McGeary]
* Improved test coverage [Ryan McGeary]

View file

@ -82,12 +82,12 @@ module Capistrano
if options[:shell] == false
shell = nil
else
shell = [options.fetch(:shell, "sh"), "-c"].join(" ")
shell = "#{options[:shell] || "sh"} -c"
cmd = cmd.gsub(/[$\\`"]/) { |m| "\\#{m}" }
cmd = "\"#{cmd}\""
end
command_line = [environment, options[:command_prefix], shell, cmd].compact.join(" ")
command_line = [environment, shell, cmd].compact.join(" ")
ch.exec(command_line)
ch.send_data(options[:data]) if options[:data]

View file

@ -72,7 +72,7 @@ module Capistrano
as = options.delete(:as)
user = as && "-u #{as}"
options[:command_prefix] = [fetch(:sudo, "sudo"), "-p '#{sudo_prompt}'", user].compact.join(" ")
command = [fetch(:sudo, "sudo"), "-p '#{sudo_prompt}'", user, command].compact.join(" ")
run(command, options, &sudo_behavior_callback(block))
end

View file

@ -103,29 +103,29 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
end
def test_sudo_should_default_to_sudo
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: '")
@config.expects(:run).with("sudo -p 'sudo password: ' ls", {})
@config.sudo "ls"
end
def test_sudo_should_use_sudo_variable_definition
@config.expects(:run).with("ls", :command_prefix => "/opt/local/bin/sudo -p 'sudo password: '")
@config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: ' ls", {})
@config.options[:sudo] = "/opt/local/bin/sudo"
@config.sudo "ls"
end
def test_sudo_should_interpret_as_option_as_user
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: ' -u app")
@config.expects(:run).with("sudo -p 'sudo password: ' -u app ls", {})
@config.sudo "ls", :as => "app"
end
def test_sudo_should_pass_options_through_to_run
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'sudo password: '", :foo => "bar")
@config.expects(:run).with("sudo -p 'sudo password: ' ls", :foo => "bar")
@config.sudo "ls", :foo => "bar"
end
def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt
@config.set :sudo_prompt, "give it to me: "
@config.expects(:run).with("ls", :command_prefix => "sudo -p 'give it to me: '")
@config.expects(:run).with("sudo -p 'give it to me: ' ls", {})
@config.sudo "ls"
end