Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7390

Show
Ignore:
Timestamp:
09/01/07 14:56:00 (11 months ago)
Author:
minam
Message:

Use sudo -p switch to set sudo password prompt to something predictable

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/capistrano/CHANGELOG

    r7389 r7390  
    11*SVN* 
    22 
     3* Use sudo -p switch to set sudo password prompt to something predictable [Mike Bailey] 
     4 
    35* Allow independent configurations to require the same recipe file [Jamis Buck] 
    46 
     
    1719* Add version_dir, current_dir, and shared_dir variables for naming the directories used in deployment [drinkingbird] 
    1820 
    19 * Use Windows-safe binary reads for reading file contents [fukas78
     21* Use Windows-safe binary reads for reading file contents [Ladislav Martincik
    2022 
    2123* Add Accurev SCM support [Doug Barth] 
  • tools/capistrano/lib/capistrano/configuration/actions/invocation.rb

    r7387 r7390  
    6969          options = options.dup 
    7070          as = options.delete(:as) 
    71  
     71           
    7272          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(" ") 
    7474 
    7575          run(command, options, &sudo_behavior_callback(block)) 
     
    8585          # subsequent prompts from that host. 
    8686          prompt_host = nil 
    87            
     87 
    8888          Proc.new do |ch, stream, out| 
    89             if out =~ /password:/i 
     89            if out =~ /^#{Regexp.escape(sudo_prompt)}/ 
    9090              ch.send_data "#{self[:password]}\n" 
    9191            elsif out =~ /try again/ 
     
    124124          options 
    125125        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 
    126133      end 
    127134    end 
  • tools/capistrano/test/configuration/actions/invocation_test.rb

    r6947 r7390  
    9898 
    9999  def test_sudo_should_default_to_sudo 
    100     @config.expects(:run).with("sudo ls", {}) 
     100    @config.expects(:run).with("sudo -p 'sudo password: ' ls", {}) 
    101101    @config.sudo "ls" 
    102102  end 
    103103 
    104104  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", {}) 
    106106    @config.options[:sudo] = "/opt/local/bin/sudo" 
    107107    @config.sudo "ls" 
     
    109109 
    110110  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", {}) 
    112112    @config.sudo "ls", :as => "app" 
    113113  end 
    114114 
    115115  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") 
    117117    @config.sudo "ls", :foo => "bar" 
    118118  end 
    119119 
    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 
    121127    ch = mock("channel") 
    122128    ch.expects(:send_data).with("g00b3r\n") 
    123129    @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_dialec
     130    @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_promp
    128134    ch = mock("channel") 
    129135    ch.expects(:send_data).with("g00b3r\n") 
     136    @config.set :sudo_prompt, "give it to me: " 
    130137    @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: "] 
    132139  end 
    133140