Adding check for APIPA in winrm helper to fix #8996

This commit is contained in:
Bryce Shurts 2017-09-25 16:31:37 -05:00
parent 2355936291
commit 0eaf691ea0
2 changed files with 12 additions and 1 deletions

View File

@ -33,10 +33,15 @@ module VagrantPlugins
return addr if addr return addr if addr
ssh_info = machine.ssh_info 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] return ssh_info[:host]
end 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. # Returns the port to access WinRM.
# #
# @param [Vagrant::Machine] machine # @param [Vagrant::Machine] machine

View File

@ -48,6 +48,12 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
expect { subject.winrm_address(machine) }. expect { subject.winrm_address(machine) }.
to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady) to raise_error(VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady)
end 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 end
describe ".winrm_info" do describe ".winrm_info" do