From 99646735d0ac562c9414901efd50316c4280d022 Mon Sep 17 00:00:00 2001 From: Samer Abukhait Date: Thu, 1 Sep 2011 12:40:09 -0700 Subject: [PATCH] Don't do the port threshold check if running under root --- lib/vagrant/action/vm/forward_ports.rb | 2 +- .../vagrant/action/vm/forward_ports_test.rb | 41 ++++++++++++------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/vagrant/action/vm/forward_ports.rb b/lib/vagrant/action/vm/forward_ports.rb index 136c2ff73..26d0d5c22 100644 --- a/lib/vagrant/action/vm/forward_ports.rb +++ b/lib/vagrant/action/vm/forward_ports.rb @@ -10,7 +10,7 @@ module Vagrant @app = app @env = env - threshold_check + threshold_check unless ENV["USER"] == "root" external_collision_check end diff --git a/test/unit/vagrant/action/vm/forward_ports_test.rb b/test/unit/vagrant/action/vm/forward_ports_test.rb index 401a66b30..4eebb605d 100644 --- a/test/unit/vagrant/action/vm/forward_ports_test.rb +++ b/test/unit/vagrant/action/vm/forward_ports_test.rb @@ -9,6 +9,7 @@ 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 @@ -22,25 +23,37 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase context "checking for threshold" do setup do @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.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.forwarded_ports.clear - @env.env.config.vm.forward_port("foo", 22, 2222) + context "for non-root users" do + + 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 + 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