Properly expand config.ssh.private_key_path
This commit is contained in:
parent
202cfebc24
commit
434cc79a83
|
@ -274,8 +274,16 @@ 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.
|
||||
info[:private_key_path] = @config.ssh.private_key_path if @config.ssh.private_key_path
|
||||
info[:private_key_path] = @env.default_private_key_path if !info[:private_key_path]
|
||||
if @config.ssh.private_key_path
|
||||
info[:private_key_path] = @config.ssh.private_key_path
|
||||
end
|
||||
|
||||
if !info[:private_key_path]
|
||||
info[:private_key_path] = @env.default_private_key_path
|
||||
end
|
||||
|
||||
# Expand the private key path relative to the root path
|
||||
info[:private_key_path] = File.expand_path(info[:private_key_path], @env.root_path)
|
||||
|
||||
# Return the final compiled SSH info data
|
||||
info
|
||||
|
|
|
@ -363,23 +363,40 @@ describe Vagrant::Machine do
|
|||
end
|
||||
|
||||
it "should return the provider private key if given" do
|
||||
provider_ssh_info[:private_key_path] = "foo"
|
||||
provider_ssh_info[:private_key_path] = "/foo"
|
||||
|
||||
instance.ssh_info[:private_key_path].should == "foo"
|
||||
instance.ssh_info[:private_key_path].should == "/foo"
|
||||
end
|
||||
|
||||
it "should return the configured SSH key path if set" do
|
||||
provider_ssh_info[:private_key_path] = "foo"
|
||||
instance.config.ssh.private_key_path = "bar"
|
||||
provider_ssh_info[:private_key_path] = "/foo"
|
||||
instance.config.ssh.private_key_path = "/bar"
|
||||
|
||||
instance.ssh_info[:private_key_path].should == "bar"
|
||||
instance.ssh_info[:private_key_path].should == "/bar"
|
||||
end
|
||||
|
||||
context "expanding path relative to the root path" do
|
||||
it "should with the provider key path" do
|
||||
provider_ssh_info[:private_key_path] = "~/foo"
|
||||
|
||||
instance.ssh_info[:private_key_path].should ==
|
||||
File.expand_path("~/foo", env.root_path)
|
||||
end
|
||||
|
||||
it "should with the config private key path" do
|
||||
provider_ssh_info[:private_key_path] = "~/foo"
|
||||
instance.config.ssh.private_key_path = "~/bar"
|
||||
|
||||
instance.ssh_info[:private_key_path].should ==
|
||||
File.expand_path("~/bar", env.root_path)
|
||||
end
|
||||
end
|
||||
|
||||
it "should return the default private key path if provider and config doesn't have one" do
|
||||
provider_ssh_info[:private_key_path] = nil
|
||||
instance.config.ssh.private_key_path = nil
|
||||
|
||||
instance.ssh_info[:private_key_path].should == instance.env.default_private_key_path
|
||||
instance.ssh_info[:private_key_path].should == instance.env.default_private_key_path.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue