From e115322e78d3da464657b8cdb69ed691245581ae Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Jan 2014 09:48:35 -0800 Subject: [PATCH] core: accept passwords in ssh_info --- lib/vagrant/machine.rb | 4 +++- plugins/kernel_v2/config/ssh_connect.rb | 3 +++ test/unit/vagrant/machine_test.rb | 11 ++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 14c700197..3d46edde9 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -280,6 +280,7 @@ module Vagrant info[:host] = @config.ssh.host if @config.ssh.host info[:port] = @config.ssh.port if @config.ssh.port info[:username] = @config.ssh.username if @config.ssh.username + info[:password] = @config.ssh.password if @config.ssh.password # We also set some fields that are purely controlled by Varant info[:forward_agent] = @config.ssh.forward_agent @@ -291,7 +292,7 @@ module Vagrant # Set the private key path. If a specific private key is given in # the Vagrantfile we set that. Otherwise, we use the default (insecure) # private key, but only if the provider didn't give us one. - if !info[:private_key_path] + if !info[:private_key_path] && !info[:password] if @config.ssh.private_key_path info[:private_key_path] = @config.ssh.private_key_path else @@ -300,6 +301,7 @@ module Vagrant end # Setup the keys + info[:private_key_path] ||= [] if !info[:private_key_path].is_a?(Array) info[:private_key_path] = [info[:private_key_path]] end diff --git a/plugins/kernel_v2/config/ssh_connect.rb b/plugins/kernel_v2/config/ssh_connect.rb index 06d9de10e..f3925f09c 100644 --- a/plugins/kernel_v2/config/ssh_connect.rb +++ b/plugins/kernel_v2/config/ssh_connect.rb @@ -5,12 +5,14 @@ module VagrantPlugins attr_accessor :port attr_accessor :private_key_path attr_accessor :username + attr_accessor :password def initialize @host = UNSET_VALUE @port = UNSET_VALUE @private_key_path = UNSET_VALUE @username = UNSET_VALUE + @password = UNSET_VALUE end def finalize! @@ -18,6 +20,7 @@ module VagrantPlugins @port = nil if @port == UNSET_VALUE @private_key_path = nil if @private_key_path == UNSET_VALUE @username = nil if @username == UNSET_VALUE + @password = nil if @password == UNSET_VALUE if @private_key_path && !@private_key_path.is_a?(Array) @private_key_path = [@private_key_path] diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 8eaa30810..29758246f 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -279,7 +279,7 @@ describe Vagrant::Machine do let(:provider_ssh_info) { {} } before(:each) do - provider.should_receive(:ssh_info).and_return(provider_ssh_info) + provider.stub(:ssh_info).and_return(provider_ssh_info) end [:host, :port, :username].each do |type| @@ -373,6 +373,15 @@ describe Vagrant::Machine do instance.ssh_info[:private_key_path].should == [instance.env.default_private_key_path.to_s] end + + it "should not set any default private keys if a password is specified" do + provider_ssh_info[:private_key_path] = nil + instance.config.ssh.private_key_path = nil + instance.config.ssh.password = "" + + expect(instance.ssh_info[:private_key_path]).to be_empty + expect(instance.ssh_info[:password]).to eql("") + end end end