From 846f942ff0ad0c913ceedc4ec410669f827e2173 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 14 Mar 2014 14:04:00 -0700 Subject: [PATCH] core: check for data_dir [GH-3208] --- lib/vagrant/machine.rb | 8 +++++--- test/unit/vagrant/machine_test.rb | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index ec4d11d91..360d9c4aa 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -311,9 +311,11 @@ module Vagrant end # If we have a private key in our data dir, then use that - data_private_key = @data_dir.join("private_key") - if data_private_key.file? - info[:private_key_path] = [data_private_key.to_s] + if @data_dir + data_private_key = @data_dir.join("private_key") + if data_private_key.file? + info[:private_key_path] = [data_private_key.to_s] + end end # Setup the keys diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 08efef37e..5518e05e9 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -20,6 +20,7 @@ describe Vagrant::Machine do let(:provider_config) { Object.new } let(:provider_name) { :test } let(:provider_options) { {} } + let(:base) { false } let(:box) { Object.new } let(:config) { env.vagrantfile.config } let(:data_dir) { Pathname.new(Dir.mktmpdir("vagrant")) } @@ -42,7 +43,7 @@ describe Vagrant::Machine do def new_instance described_class.new(name, provider_name, provider_cls, provider_config, provider_options, config, data_dir, box, - env, env.vagrantfile) + env, env.vagrantfile, base) end describe "initialization" do @@ -459,6 +460,20 @@ describe Vagrant::Machine do [instance.data_dir.join("private_key").to_s]) expect(instance.ssh_info[:password]).to eql("") end + + context "with no data dir" do + let(:base) { true } + let(:data_dir) { nil } + + it "returns nil as the private key path" 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 end