Show warning if forwarding port less than 1024 [closes GH-487]

This commit is contained in:
Mitchell Hashimoto 2011-09-11 23:56:02 -07:00
parent 99646735d0
commit 7219f3d05b
5 changed files with 23 additions and 38 deletions

View File

@ -2,6 +2,8 @@
- Fix regression with remote paths from chef-solo. [GH-431]
- Fix issue where Vagrant crashes if `.vagrant` file becomes invalid. [GH-496]
- Issue a warning instead of an error for attempting to forward a port
<= 1024. [GH-487]
## 0.8.6 (August 28, 2011)

View File

@ -10,7 +10,7 @@ module Vagrant
@app = app
@env = env
threshold_check unless ENV["USER"] == "root"
threshold_check
external_collision_check
end
@ -23,7 +23,10 @@ module Vagrant
# 1024, which causes the forwarded ports to fail.
def threshold_check
@env.env.config.vm.forwarded_ports.each do |name, options|
raise Errors::ForwardPortBelowThreshold if options[:hostport] <= 1024
if options[:hostport] <= 1024
@env.ui.warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports")
return
end
end
end

View File

@ -168,11 +168,6 @@ module Vagrant
error_key(:auto_empty, "vagrant.actions.vm.forward_ports")
end
class ForwardPortBelowThreshold < VagrantError
status_code(25)
error_key(:below_threshold_error, "vagrant.actions.vm.forward_ports")
end
class ForwardPortCollision < VagrantError
status_code(26)
error_key(:collision_error, "vagrant.actions.vm.forward_ports")

View File

@ -314,11 +314,6 @@ en:
VM: %{vm_name}
Forwarded port: %{name} (%{guest_port} => %{host_port})
below_threshold_error: |-
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).
collision_error: |-
Vagrant cannot forward the specified ports on this VM, since they
would collide with another VirtualBox virtual machine's forwarded
@ -336,6 +331,12 @@ en:
non_nat: |-
VirtualBox adapter #%{adapter} not configured as "NAT"
Skipping port forwarding '%{name}'.
privileged_ports: |-
You are trying to forward to privileged ports (ports <= 1024). Most
operating systems restrict this to only privileged process (typically
processes running as an administrative user). This is a warning in case
the port forwarding doesn't work. If any problems occur, please try a
port higher than 1024.
halt:
force: Forcing shutdown of VM...
host_name:

View File

@ -9,7 +9,6 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
@vm.stubs(:name).returns("foo")
@env["vm"] = @vm
@env["vm.modify"] = mock("proc")
ENV["USER"] = "not-root"
end
context "initializing" do
@ -26,34 +25,19 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
@env.env.config.vm.forwarded_ports.clear
end
context "for non-root users" do
should "error if has a port below threshold" do
should "issue a warning for ports less than 1024" do
@env.env.config.vm.forward_port("foo", 22, 222)
assert_raises(Vagrant::Errors::ForwardPortBelowThreshold) { @klass.new(@app, @env) }
@env.ui.expects(:warn).once
@klass.new(@app, @env)
end
should "not error if ports are fine" do
should "not issue a warning for ports greater than 1024" do
@env.env.config.vm.forward_port("foo", 22, 2222)
assert_nothing_raised { @klass.new(@app, @env) }
end
@env.ui.expects(:warn).never
@klass.new(@app, @env)
end
context "for a root user" do
setup do
ENV["USER"] = "root"
end
should "not error for any port" do
@env.env.config.vm.forward_port("foo", 22, 222)
assert_nothing_raised { @klass.new(@app, @env) }
@env.env.config.vm.forward_port("foo", 22, 2222)
assert_nothing_raised { @klass.new(@app, @env) }
end
end
end
context "checking for colliding external ports" do