diff --git a/lib/chef/knife/bootstrap_windows_base.rb b/lib/chef/knife/bootstrap_windows_base.rb index c793f335..215f20b8 100644 --- a/lib/chef/knife/bootstrap_windows_base.rb +++ b/lib/chef/knife/bootstrap_windows_base.rb @@ -217,9 +217,6 @@ def bootstrap(proto=nil) STDOUT.sync = STDERR.sync = true if (Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key]))) - # require 'pry' - # binding.pry - if Chef::VERSION.split('.').first.to_i == 11 ui.error("Unable to find validation key. Please verify your configuration file for validation_key config value.") exit 1 diff --git a/lib/chef/knife/bootstrap_windows_winrm.rb b/lib/chef/knife/bootstrap_windows_winrm.rb index 44418178..3227cb38 100644 --- a/lib/chef/knife/bootstrap_windows_winrm.rb +++ b/lib/chef/knife/bootstrap_windows_winrm.rb @@ -30,7 +30,6 @@ class BootstrapWindowsWinrm < Bootstrap include Chef::Knife::WinrmBase include Chef::Knife::WinrmCommandSharedFunctions - deps do require 'chef/knife/core/windows_bootstrap_context' require 'chef/json_compat' @@ -42,20 +41,14 @@ class BootstrapWindowsWinrm < Bootstrap def run if (Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key]))) - if !negotiate_auth? && !(locate_config_value(:winrm_transport) == 'ssl') - ui.error("Validatorless bootstrap only supported with negotiate authentication protocol and ssl/plaintext transport") - exit 1 - elsif !(Chef::Platform.windows?) && negotiate_auth? - ui.error("Negotiate protocol with plaintext transport is only supported when this tool is invoked from windows based system") + ui.error("Validatorless bootstrap over unsecure winrm channels could expose your key to network sniffing") exit 1 end - end bootstrap end - def run_command(command = '') winrm = Chef::Knife::Winrm.new winrm.name_args = [ server_name, command ] diff --git a/spec/functional/bootstrap_download_spec.rb b/spec/functional/bootstrap_download_spec.rb index 3cade82e..e56c9094 100644 --- a/spec/functional/bootstrap_download_spec.rb +++ b/spec/functional/bootstrap_download_spec.rb @@ -100,7 +100,6 @@ run_download_scenario end end - end def download_succeeded? @@ -118,13 +117,10 @@ def run_download_scenario clean_test_case winrm_bootstrapper = Chef::Knife::BootstrapWindowsWinrm.new([ "127.0.0.1" ]) + if chef_12? winrm_bootstrapper.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil) - allow(winrm_bootstrapper.client_builder).to receive(:run) - allow(winrm_bootstrapper.client_builder).to receive(:client_path) - end - - if chef_11? + elsif chef_11? allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(true) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 773b4234..0230ba3d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -65,5 +65,7 @@ def chef_12? RSpec.configure do |config| config.filter_run_excluding :windows_only => true unless windows? config.filter_run_excluding :windows_2012_only => true unless windows2012? + config.filter_run_excluding :chef_11_only unless chef_11? + config.filter_run_excluding :chef_12_only unless chef_12? end diff --git a/spec/unit/knife/bootstrap_windows_winrm_spec.rb b/spec/unit/knife/bootstrap_windows_winrm_spec.rb index 73c9c777..3e42470e 100644 --- a/spec/unit/knife/bootstrap_windows_winrm_spec.rb +++ b/spec/unit/knife/bootstrap_windows_winrm_spec.rb @@ -41,7 +41,7 @@ let(:initial_fail_count) { 4 } - it 'should retry if a 401 is received from WinRM' do + it 'should retry if a 401 is received from WinRM' do call_result_sequence = Array.new(initial_fail_count) {lambda {raise WinRM::WinRMHTTPTransportError.new('', '401')}} call_result_sequence.push(0) allow(bootstrap).to receive(:run_command).and_return(*call_result_sequence) @@ -114,7 +114,18 @@ end context "when validation_key is not present" do - if chef_12? + context "using chef 11", :chef_11_only do + before do + allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(false) + end + + it 'raises an exception if validation_key is not present in chef 11' do + expect(bootstrap.ui).to receive(:error) + expect { bootstrap.bootstrap }.to raise_error(SystemExit) + end + end + + context "using chef 12", :chef_12_only do before do allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(false) bootstrap.client_builder = instance_double("Chef::Knife::Bootstrap::ClientBuilder", :run => nil, :client_path => nil) @@ -135,16 +146,5 @@ expect { bootstrap.bootstrap }.to raise_error(SystemExit) end end - - if chef_11? - before do - allow(File).to receive(:exist?).with(File.expand_path(Chef::Config[:validation_key])).and_return(false) - end - - it 'raises an exception if validation_key is not present in chef 11' do - expect(bootstrap.ui).to receive(:error) - expect { bootstrap.bootstrap }.to raise_error(SystemExit) - end - end end -end \ No newline at end of file +end