test/unit/vagrant/util/ssh_test.rb in vagrant-unbundled-2.0.1.0 vs test/unit/vagrant/util/ssh_test.rb in vagrant-unbundled-2.0.2.0
- old
+ new
@@ -36,10 +36,25 @@
private_key_path: [temporary_file],
compression: true,
dsa_authentication: true
}}
+ let(:ssh_path) { "/usr/bin/ssh" }
+
+ it "searches original PATH for exectuable" do
+ expect(Vagrant::Util::Which).to receive(:which).with("ssh", original_path: true).and_return("valid-return")
+ allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
+ described_class.exec(ssh_info)
+ end
+
+ it "searches current PATH if original PATH did not result in valid executable" do
+ expect(Vagrant::Util::Which).to receive(:which).with("ssh", original_path: true).and_return(nil)
+ expect(Vagrant::Util::Which).to receive(:which).with("ssh").and_return("valid-return")
+ allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
+ described_class.exec(ssh_info)
+ end
+
it "raises an exception if there is no ssh" do
allow(Vagrant::Util::Which).to receive(:which).and_return(nil)
expect { described_class.exec(ssh_info) }.
to raise_error Vagrant::Errors::SSHUnavailable
@@ -65,11 +80,11 @@
it "invokes SSH with options if subprocess is not allowed" do
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
expect(described_class.exec(ssh_info)).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL","-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"")
+ .with(ssh_path, "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL","-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"")
end
context "when disabling compression or dsa_authentication flags" do
let(:ssh_info) {{
host: "localhost",
@@ -83,29 +98,29 @@
it "does not include compression or dsa_authentication flags if disabled" do
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
expect(described_class.exec(ssh_info)).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"")
+ .with(ssh_path, "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"")
end
end
- context "when paranoid is true" do
+ context "when verify_host_key is true" do
let(:ssh_info) {{
host: "localhost",
port: 2222,
username: "vagrant",
private_key_path: [temporary_file],
- paranoid: true
+ verify_host_key: true
}}
it "does not disable StrictHostKeyChecking or set UserKnownHostsFile" do
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
expect(described_class.exec(ssh_info)).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"")
+ .with(ssh_path, "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"")
end
end
context "when not on solaris not using plain mode or with keys_only enabled" do
let(:ssh_info) {{
@@ -120,11 +135,11 @@
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
allow(Vagrant::Util::Platform).to receive(:solaris?).and_return(false)
expect(described_class.exec(ssh_info, {plain_mode: true})).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null")
+ .with(ssh_path, "localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null")
end
end
context "when forward_x11 is enabled" do
let(:ssh_info) {{
@@ -138,11 +153,11 @@
it "enables ForwardX11 options" do
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
expect(described_class.exec(ssh_info)).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"","-o", "ForwardX11=yes", "-o", "ForwardX11Trusted=yes")
+ .with(ssh_path, "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"","-o", "ForwardX11=yes", "-o", "ForwardX11Trusted=yes")
end
end
context "when forward_agent is enabled" do
let(:ssh_info) {{
@@ -156,11 +171,11 @@
it "enables agent forwarding options" do
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
expect(described_class.exec(ssh_info)).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"","-o", "ForwardAgent=yes")
+ .with(ssh_path, "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"","-o", "ForwardAgent=yes")
end
end
context "when extra_args is provided as an array" do
let(:ssh_info) {{
@@ -174,11 +189,11 @@
it "enables agent forwarding options" do
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
expect(described_class.exec(ssh_info)).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"", "-L", "8008:localhost:80")
+ .with(ssh_path, "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"", "-L", "8008:localhost:80")
end
end
context "when extra_args is provided as a string" do
let(:ssh_info) {{
@@ -192,10 +207,10 @@
it "enables agent forwarding options" do
allow(Vagrant::Util::SafeExec).to receive(:exec).and_return(nil)
expect(described_class.exec(ssh_info)).to eq(nil)
expect(Vagrant::Util::SafeExec).to have_received(:exec)
- .with("ssh", "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"", "-6")
+ .with(ssh_path, "vagrant@localhost", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentityFile=\"#{ssh_info[:private_key_path][0]}\"", "-6")
end
end
context "with subprocess enabled" do
let(:ssh_info) {{