diff --git a/plugins/communicators/winrm/helper.rb b/plugins/communicators/winrm/helper.rb index b435a960c..03aff088c 100644 --- a/plugins/communicators/winrm/helper.rb +++ b/plugins/communicators/winrm/helper.rb @@ -33,10 +33,15 @@ module VagrantPlugins return addr if addr ssh_info = machine.ssh_info - raise Errors::WinRMNotReady if !ssh_info || ssh_info[:host].to_s.empty? + raise Errors::WinRMNotReady if winrm_info_invalid?(ssh_info) return ssh_info[:host] end + def self.winrm_info_invalid?(ssh_info) + invalid = (!ssh_info || ssh_info[:host].to_s.empty? || ssh_info[:host].to_s.match(/^169.254/)) + return invalid + end + # Returns the port to access WinRM. # # @param [Vagrant::Machine] machine diff --git a/test/unit/plugins/communicators/winrm/helper_test.rb b/test/unit/plugins/communicators/winrm/helper_test.rb index 80c7f8568..f030f7aa3 100644 --- a/test/unit/plugins/communicators/winrm/helper_test.rb +++ b/test/unit/plugins/communicators/winrm/helper_test.rb @@ -48,6 +48,12 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do expect { subject.winrm_address(machine) }. to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady) end + + it "raise an exception if it detects an APIPA" do + machine.stub(ssh_info: { host: "169.254.123.123" }) + expect { subject.winrm_address(machine) }. + to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady) + end end describe ".winrm_info" do