Merge pull request #8997 from bshurts/fix/winrm-apipa

Adding check for APIPA in winrm helper to fix #8996
This commit is contained in:
Chris Roberts 2017-10-23 16:47:32 -07:00 committed by GitHub
commit eaa518159c
2 changed files with 39 additions and 1 deletions

View File

@ -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].start_with?("169.254"))
return invalid
end
# Returns the port to access WinRM.
#
# @param [Vagrant::Machine] machine

View File

@ -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
@ -142,4 +148,31 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
expect(subject.winrm_port(machine)).to eq(2456)
end
end
describe ".winrm_info_invalid?" do
it "returns true if it can't detect a host" do
allow(machine).to receive(:ssh_info).and_return(nil)
expect(subject).to be_winrm_info_invalid(machine.ssh_info)
end
it "returns true if it detects an empty host ip" do
allow(machine).to receive(:ssh_info).and_return({ host: "" })
expect(subject).to be_winrm_info_invalid(machine.ssh_info)
end
it "returns true if it detects an unset host ip" do
allow(machine).to receive(:ssh_info).and_return({ host: nil })
expect(subject).to be_winrm_info_invalid(machine.ssh_info)
end
it "returns true if it detects an APIPA" do
machine.stub(ssh_info: { host: "169.254.123.123" })
expect(subject).to be_winrm_info_invalid(machine.ssh_info)
end
it "returns false if the IP is valid" do
machine.stub(ssh_info: { host: "192.168.123.123" })
expect(subject).not_to be_winrm_info_invalid(machine.ssh_info)
end
end
end