mirror of
https://github.com/hashicorp/vagrant.git
synced 2026-05-28 04:36:05 -04:00
Merge pull request #11654 from jbonhag/fix/loopback-forward
Fix #11640: Check port of loopback address
This commit is contained in:
commit
f9f2fc0dd5
2 changed files with 14 additions and 3 deletions
|
|
@ -269,7 +269,8 @@ module Vagrant
|
|||
end
|
||||
else
|
||||
# Do a regular check
|
||||
if test_host_ip == "0.0.0.0" || Vagrant::Util::IPv4Interfaces.ipv4_interfaces.detect { |iface| iface[1] == test_host_ip }
|
||||
if test_host_ip == "0.0.0.0" || Addrinfo.ip(test_host_ip).ipv4_loopback? ||
|
||||
Vagrant::Util::IPv4Interfaces.ipv4_interfaces.detect { |iface| iface[1] == test_host_ip }
|
||||
Vagrant::Util::IsPortOpen.is_port_open?(test_host_ip, host_port)
|
||||
else
|
||||
raise Errors::ForwardPortHostIPNotFound, name: machine.name, host_ip: host_ip
|
||||
|
|
|
|||
|
|
@ -195,12 +195,22 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do
|
|||
end
|
||||
|
||||
context "when host ip does not exist" do
|
||||
let(:host_ip) { "127.0.0.2" }
|
||||
let(:host_ip) { "192.168.99.100" }
|
||||
let(:name) { "default" }
|
||||
|
||||
it "should raise an error including the machine name" do
|
||||
allow(machine).to receive(:name).and_return(name)
|
||||
expect{ instance.send(:port_check, host_ip, host_port) }.to raise_error(Vagrant::Errors::ForwardPortHostIPNotFound, /#{name}/)
|
||||
expect{ instance.send(:port_check, host_ip, host_port) }.
|
||||
to raise_error(Vagrant::Errors::ForwardPortHostIPNotFound, /#{name}/)
|
||||
end
|
||||
end
|
||||
|
||||
context "with loopback address" do
|
||||
let (:host_ip) { "127.1.2.40" }
|
||||
|
||||
it "should check if the port is open" do
|
||||
expect(Vagrant::Util::IsPortOpen).to receive(:is_port_open?).with(host_ip, host_port).and_return(true)
|
||||
instance.send(:port_check, host_ip, host_port)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue