Skip to content

Commit

Permalink
Chef version test + whitespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
btm committed May 27, 2015
1 parent 995a1bd commit 89a26b9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
3 changes: 0 additions & 3 deletions lib/chef/knife/bootstrap_windows_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions lib/chef/knife/bootstrap_windows_winrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 ]
Expand Down
8 changes: 2 additions & 6 deletions spec/functional/bootstrap_download_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
run_download_scenario
end
end

end

def download_succeeded?
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

28 changes: 14 additions & 14 deletions spec/unit/knife/bootstrap_windows_winrm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
end

0 comments on commit 89a26b9

Please sign in to comment.