diff options
author | Tim Smith <tsmith@chef.io> | 2019-10-08 09:13:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-08 09:13:08 -0700 |
commit | bed47ece7b8b13e69c7464104f6a22a6f60932f4 (patch) | |
tree | cc910b7dc43195927c3933e120d55f243b855015 /spec | |
parent | 7f059a779913440c5458df6341e76f16b1b93c4e (diff) | |
parent | d58a7eb7965a1c5102b3ee7216dd465064c89524 (diff) | |
download | chef-bed47ece7b8b13e69c7464104f6a22a6f60932f4.tar.gz |
Merge pull request #8856 from MsysTechnologiesllc/bootstrap_password_prompt
Fix Bootstrap password prompt
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 752fcff1e3..46415085bc 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -1839,6 +1839,20 @@ describe Chef::Knife::Bootstrap do e end + let(:expected_error_password_prompt) do + e = Train::ClientError.new + reason = :no_ssh_password_or_key_available + allow(e).to receive(:reason).and_return(reason) + e + end + + let(:expected_error_password_prompt_winrm) do + e = RuntimeError.new + message = "password is a required option" + allow(e).to receive(:message).and_return(message) + e + end + context "and password auth was used" do before do allow(connection).to receive(:password_auth?).and_return true @@ -1854,19 +1868,41 @@ describe Chef::Knife::Bootstrap do before do allow(connection).to receive(:password_auth?).and_return false allow(connection).to receive(:user).and_return "testuser" + allow(knife).to receive(:connection_protocol).and_return connection_protocol end - it "warns, prompts for password, then reconnects with a password-enabled configuration using the new password" do - question_mock = double("question") - expect(knife).to receive(:do_connect).and_raise(expected_error) - expect(knife.ui).to receive(:warn).with(/Failed to auth.*/) - expect(knife.ui).to receive(:ask).and_yield(question_mock).and_return("newpassword") - # Ensure that we set echo off to prevent showing password on the screen - expect(question_mock).to receive(:echo=).with false - expect(knife).to receive(:do_connect) do |opts| - expect(opts[:password]).to eq "newpassword" + context "when using ssh" do + let(:connection_protocol) { "ssh" } + + it "warns, prompts for password, then reconnects with a password-enabled configuration using the new password" do + question_mock = double("question") + expect(knife).to receive(:do_connect).and_raise(expected_error_password_prompt) + expect(knife.ui).to receive(:warn).with(/Failed to auth.*/) + expect(knife.ui).to receive(:ask).and_yield(question_mock).and_return("newpassword") + # Ensure that we set echo off to prevent showing password on the screen + expect(question_mock).to receive(:echo=).with false + expect(knife).to receive(:do_connect) do |opts| + expect(opts[:password]).to eq "newpassword" + end + knife.connect! + end + end + + context "when using winrm" do + let(:connection_protocol) { "winrm" } + + it "warns, prompts for password, then reconnects with a password-enabled configuration using the new password for" do + question_mock = double("question") + expect(knife).to receive(:do_connect).and_raise(expected_error_password_prompt_winrm) + expect(knife.ui).to receive(:warn).with(/Failed to auth.*/) + expect(knife.ui).to receive(:ask).and_yield(question_mock).and_return("newpassword") + # Ensure that we set echo off to prevent showing password on the screen + expect(question_mock).to receive(:echo=).with false + expect(knife).to receive(:do_connect) do |opts| + expect(opts[:password]).to eq "newpassword" + end + knife.connect! end - knife.connect! end end end |