Skip to content
Browse files

Make sure sudo prompts are retried correctly even if "try again" and …

…the prompt appear in the same text chunk from the server
  • Loading branch information...
1 parent 0b7c577 commit 9ba526dcb02dbeb2db72fd61861824498cd31b2d @jamis jamis committed Jan 29, 2009
View
7 CHANGELOG.rdoc
@@ -1,3 +1,10 @@
+== (unreleased)
+
+* Make sure sudo prompts are retried correctly even if "try again" and the prompt appear in the same text chunk from the server [Jamis Buck]
+
+* Add supported environment variables to -H output [François Beausoleil]
+
+
== 2.5.3 / December 6, 2008
* Make previous_release return nil if there is no previous release [Mathias Meyer]
View
8 lib/capistrano/configuration/actions/invocation.rb
@@ -223,14 +223,16 @@ def sudo_behavior_callback(fallback) #:nodoc:
prompt_host = nil
Proc.new do |ch, stream, out|
- if out =~ /^#{Regexp.escape(sudo_prompt)}/
- ch.send_data "#{self[:password]}\n"
- elsif out =~ /^Sorry, try again/
+ if out =~ /^Sorry, try again/
if prompt_host.nil? || prompt_host == ch[:server]
prompt_host = ch[:server]
logger.important out, "#{stream} :: #{ch[:server]}"
reset! :password
end
+ end
+
+ if out =~ /^#{Regexp.escape(sudo_prompt)}/
+ ch.send_data "#{self[:password]}\n"
elsif fallback
fallback.call(ch, stream, out)
end
View
14 test/configuration/actions/invocation_test.rb
@@ -166,6 +166,20 @@ def test_sudo_behavior_callback_with_incorrect_password_on_subsequent_prompts
callback[ch, nil, "Sorry, try again."]
end
+ def test_sudo_behavior_callback_should_reset_password_and_prompt_again_if_output_includes_both_cues
+ ch = mock("channel")
+ ch.stubs(:[]).with(:host).returns("capistrano")
+ ch.stubs(:[]).with(:server).returns(server("capistrano"))
+ ch.expects(:send_data, "password!\n").times(2)
+
+ @config.set(:password, "password!")
+ @config.expects(:reset!).with(:password)
+
+ callback = @config.sudo_behavior_callback(nil)
+ callback[ch, :out, "sudo password: "]
+ callback[ch, :out, "Sorry, try again.\nsudo password: "]
+ end
+
def test_sudo_behavior_callback_should_defer_to_fallback_for_other_output
callback = @config.sudo_behavior_callback(inspectable_proc)

0 comments on commit 9ba526d

Please sign in to comment.
Something went wrong with that request. Please try again.