Changeset 7390
- Timestamp:
- 09/01/07 14:56:00 (11 months ago)
- Files:
-
- tools/capistrano/CHANGELOG (modified) (2 diffs)
- tools/capistrano/lib/capistrano/configuration/actions/invocation.rb (modified) (3 diffs)
- tools/capistrano/test/configuration/actions/invocation_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/capistrano/CHANGELOG
r7389 r7390 1 1 *SVN* 2 2 3 * Use sudo -p switch to set sudo password prompt to something predictable [Mike Bailey] 4 3 5 * Allow independent configurations to require the same recipe file [Jamis Buck] 4 6 … … 17 19 * Add version_dir, current_dir, and shared_dir variables for naming the directories used in deployment [drinkingbird] 18 20 19 * Use Windows-safe binary reads for reading file contents [ fukas78]21 * Use Windows-safe binary reads for reading file contents [Ladislav Martincik] 20 22 21 23 * Add Accurev SCM support [Doug Barth] tools/capistrano/lib/capistrano/configuration/actions/invocation.rb
r7387 r7390 69 69 options = options.dup 70 70 as = options.delete(:as) 71 71 72 72 user = as && "-u #{as}" 73 command = [fetch(:sudo, "sudo"), user, command].compact.join(" ")73 command = [fetch(:sudo, "sudo"), "-p '#{sudo_prompt}'", user, command].compact.join(" ") 74 74 75 75 run(command, options, &sudo_behavior_callback(block)) … … 85 85 # subsequent prompts from that host. 86 86 prompt_host = nil 87 87 88 88 Proc.new do |ch, stream, out| 89 if out =~ / password:/i89 if out =~ /^#{Regexp.escape(sudo_prompt)}/ 90 90 ch.send_data "#{self[:password]}\n" 91 91 elsif out =~ /try again/ … … 124 124 options 125 125 end 126 127 private 128 129 # Returns the prompt text to use with sudo 130 def sudo_prompt 131 fetch(:sudo_prompt, "sudo password: ") 132 end 126 133 end 127 134 end tools/capistrano/test/configuration/actions/invocation_test.rb
r6947 r7390 98 98 99 99 def test_sudo_should_default_to_sudo 100 @config.expects(:run).with("sudo ls", {})100 @config.expects(:run).with("sudo -p 'sudo password: ' ls", {}) 101 101 @config.sudo "ls" 102 102 end 103 103 104 104 def test_sudo_should_use_sudo_variable_definition 105 @config.expects(:run).with("/opt/local/bin/sudo ls", {})105 @config.expects(:run).with("/opt/local/bin/sudo -p 'sudo password: ' ls", {}) 106 106 @config.options[:sudo] = "/opt/local/bin/sudo" 107 107 @config.sudo "ls" … … 109 109 110 110 def test_sudo_should_interpret_as_option_as_user 111 @config.expects(:run).with("sudo - u app ls", {})111 @config.expects(:run).with("sudo -p 'sudo password: ' -u app ls", {}) 112 112 @config.sudo "ls", :as => "app" 113 113 end 114 114 115 115 def test_sudo_should_pass_options_through_to_run 116 @config.expects(:run).with("sudo ls", :foo => "bar")116 @config.expects(:run).with("sudo -p 'sudo password: ' ls", :foo => "bar") 117 117 @config.sudo "ls", :foo => "bar" 118 118 end 119 119 120 def test_sudo_behavior_callback_should_send_password_when_prompted 120 def test_sudo_should_interpret_sudo_prompt_variable_as_custom_prompt 121 @config.set :sudo_prompt, "give it to me: " 122 @config.expects(:run).with("sudo -p 'give it to me: ' ls", {}) 123 @config.sudo "ls" 124 end 125 126 def test_sudo_behavior_callback_should_send_password_when_prompted_with_default_sudo_prompt 121 127 ch = mock("channel") 122 128 ch.expects(:send_data).with("g00b3r\n") 123 129 @config.options[:password] = "g00b3r" 124 @config.sudo_behavior_callback(nil)[ch, nil, " Password: "]125 end 126 127 def test_sudo_behavior_callback_should_send_password_when_prompted_with_ SuSE_dialect130 @config.sudo_behavior_callback(nil)[ch, nil, "sudo password: "] 131 end 132 133 def test_sudo_behavior_callback_should_send_password_when_prompted_with_custom_sudo_prompt 128 134 ch = mock("channel") 129 135 ch.expects(:send_data).with("g00b3r\n") 136 @config.set :sudo_prompt, "give it to me: " 130 137 @config.options[:password] = "g00b3r" 131 @config.sudo_behavior_callback(nil)[ch, nil, " user's password: "]138 @config.sudo_behavior_callback(nil)[ch, nil, "give it to me: "] 132 139 end 133 140