Error if a forwarded port is below 1024 [closes GH-97]
This commit is contained in:
parent
7de7982214
commit
a5643d3239
|
@ -10,7 +10,8 @@ module Vagrant
|
||||||
@app = app
|
@app = app
|
||||||
@env = env
|
@env = env
|
||||||
|
|
||||||
external_collision_check
|
threshold_check
|
||||||
|
external_collision_check if !env.error?
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
|
@ -18,6 +19,14 @@ module Vagrant
|
||||||
# executing the action
|
# executing the action
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
|
|
||||||
|
# This method checks for any forwarded ports on the host below
|
||||||
|
# 1024, which causes the forwarded ports to fail.
|
||||||
|
def threshold_check
|
||||||
|
@env.env.config.vm.forwarded_ports.each do |name, options|
|
||||||
|
return @env.error!(:vm_port_below_threshold) if options[:hostport] <= 1024
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This method checks for any port collisions with any VMs
|
# This method checks for any port collisions with any VMs
|
||||||
# which are already created (by Vagrant or otherwise).
|
# which are already created (by Vagrant or otherwise).
|
||||||
# report the collisions detected or will attempt to fix them
|
# report the collisions detected or will attempt to fix them
|
||||||
|
|
|
@ -272,6 +272,11 @@
|
||||||
|
|
||||||
VM: <%= vm_name %>
|
VM: <%= vm_name %>
|
||||||
Forwarded port: <%= name %> (<%= options[:guestport] %> => <%= options[:hostport] %>)
|
Forwarded port: <%= name %> (<%= options[:guestport] %> => <%= options[:hostport] %>)
|
||||||
|
:vm_port_below_threshold: |-
|
||||||
|
The host port of all forwarded ports must be above 1024. VirtualBox
|
||||||
|
does not allow host ports to be below 1024. (Guest ports below 1024
|
||||||
|
are fine. For example: SSH on port 22 on the guest can be forwarded
|
||||||
|
to port 2222, but not 222).
|
||||||
:vm_port_collision: |-
|
:vm_port_collision: |-
|
||||||
Vagrant cannot forward the specified ports on this VM, since they
|
Vagrant cannot forward the specified ports on this VM, since they
|
||||||
would collide with another VirtualBox virtual machine's forwarded
|
would collide with another VirtualBox virtual machine's forwarded
|
||||||
|
|
|
@ -12,11 +12,29 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "initializing" do
|
context "initializing" do
|
||||||
should "call proper methods" do
|
should "call proper methods" do
|
||||||
|
@klass.any_instance.expects(:threshold_check)
|
||||||
@klass.any_instance.expects(:external_collision_check)
|
@klass.any_instance.expects(:external_collision_check)
|
||||||
@klass.new(@app, @env)
|
@klass.new(@app, @env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "checking for threshold" do
|
||||||
|
should "error if has a port below threshold" do
|
||||||
|
@env.env.config.vm.forwarded_ports.clear
|
||||||
|
@env.env.config.vm.forward_port("foo", 22, 222)
|
||||||
|
@klass.new(@app, @env)
|
||||||
|
assert @env.error?
|
||||||
|
assert_equal :vm_port_below_threshold, @env.error.first
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not error if ports are fine" do
|
||||||
|
@env.env.config.vm.forwarded_ports.clear
|
||||||
|
@env.env.config.vm.forward_port("foo", 22, 2222)
|
||||||
|
@klass.new(@app, @env)
|
||||||
|
assert !@env.error?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "checking for colliding external ports" do
|
context "checking for colliding external ports" do
|
||||||
setup do
|
setup do
|
||||||
@env.env.config.vm.forwarded_ports.clear
|
@env.env.config.vm.forwarded_ports.clear
|
||||||
|
@ -43,6 +61,7 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "with instance" do
|
context "with instance" do
|
||||||
setup do
|
setup do
|
||||||
|
@klass.any_instance.stubs(:threshold_check)
|
||||||
@klass.any_instance.stubs(:external_collision_check)
|
@klass.any_instance.stubs(:external_collision_check)
|
||||||
@instance = @klass.new(@app, @env)
|
@instance = @klass.new(@app, @env)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue