diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index a221b5361..1d7e394bf 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -122,8 +122,11 @@ module Vagrant return pnum if pnum # Check if we have an SSH forwarded port - pnum = env.config.vm.forwarded_ports[env.config.ssh.forwarded_port_key] - return pnum[:hostport] if pnum + pnum = env.vm.vm.forwarded_ports.detect do |fp| + fp.name == env.config.ssh.forwarded_port_key + end + + return pnum.hostport if pnum # Fall back to the default return env.config.ssh.port diff --git a/test/test_helper.rb b/test/test_helper.rb index 18ee012d6..da09636b3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -29,6 +29,7 @@ class Test::Unit::TestCase config.ssh.username = "foo" config.ssh.password = "bar" config.ssh.host = "baz" + config.ssh.port = 22 config.ssh.forwarded_port_key = "ssh" config.ssh.max_tries = 10 config.ssh.timeout = 10 diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index 8b76d0555..0b3b77cf8 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -6,6 +6,13 @@ class SshTest < Test::Unit::TestCase yield config if block_given? end + @forwarded_ports = [] + @vm = mock("vm") + @vm.stubs(:forwarded_ports).returns(@forwarded_ports) + + @env.stubs(:vm).returns(mock_vm(@env)) + @env.vm.stubs(:vm).returns(@vm) + @ssh = Vagrant::SSH.new(@env) end @@ -181,10 +188,17 @@ class SshTest < Test::Unit::TestCase context "getting the ssh port" do setup do mock_ssh + end should "return the configured port by default" do - assert_equal @env.config.vm.forwarded_ports[@env.config.ssh.forwarded_port_key][:hostport], @ssh.port + port = 2222 + fp = mock("fp") + fp.stubs(:name).returns(@env.config.ssh.forwarded_port_key) + fp.stubs(:hostport).returns(port) + @forwarded_ports << fp + + assert_equal port, @ssh.port end should "return the port given in options if it exists" do diff --git a/vagrant.gemspec b/vagrant.gemspec index 057256235..94971275c 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.authors = ["Mitchell Hashimoto", "John Bender"] - s.date = %q{2010-05-26} + s.date = %q{2010-05-27} s.default_executable = %q{vagrant} s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]