Don't do the port threshold check if running under root

This commit is contained in:
Samer Abukhait 2011-09-01 12:40:09 -07:00 committed by Mitchell Hashimoto
parent 1cfef2734a
commit 99646735d0
2 changed files with 28 additions and 15 deletions

View File

@ -10,7 +10,7 @@ module Vagrant
@app = app @app = app
@env = env @env = env
threshold_check threshold_check unless ENV["USER"] == "root"
external_collision_check external_collision_check
end end

View File

@ -9,6 +9,7 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
@vm.stubs(:name).returns("foo") @vm.stubs(:name).returns("foo")
@env["vm"] = @vm @env["vm"] = @vm
@env["vm.modify"] = mock("proc") @env["vm.modify"] = mock("proc")
ENV["USER"] = "not-root"
end end
context "initializing" do context "initializing" do
@ -22,25 +23,37 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
context "checking for threshold" do context "checking for threshold" do
setup do setup do
@klass.any_instance.stubs(:external_collision_check) @klass.any_instance.stubs(:external_collision_check)
end
should "error if has a port below threshold" do
@env.env.config.vm.forwarded_ports.clear @env.env.config.vm.forwarded_ports.clear
@env.env.config.vm.forward_port("foo", 22, 222)
assert_raises(Vagrant::Errors::ForwardPortBelowThreshold) {
@klass.new(@app, @env)
}
end end
should "not error if ports are fine" do context "for non-root users" do
@env.env.config.vm.forwarded_ports.clear
@env.env.config.vm.forward_port("foo", 22, 2222) should "error if has a port below threshold" do
@env.env.config.vm.forward_port("foo", 22, 222)
assert_raises(Vagrant::Errors::ForwardPortBelowThreshold) { @klass.new(@app, @env) }
end
should "not error if ports are fine" do
@env.env.config.vm.forward_port("foo", 22, 2222)
assert_nothing_raised { @klass.new(@app, @env) }
end
assert_nothing_raised {
@klass.new(@app, @env)
}
end 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 end
context "checking for colliding external ports" do context "checking for colliding external ports" do