summaryrefslogtreecommitdiff
path: root/spec/functional/knife/ssh_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/functional/knife/ssh_spec.rb')
-rw-r--r--spec/functional/knife/ssh_spec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/functional/knife/ssh_spec.rb b/spec/functional/knife/ssh_spec.rb
index 53012ce56d..a853e8de19 100644
--- a/spec/functional/knife/ssh_spec.rb
+++ b/spec/functional/knife/ssh_spec.rb
@@ -23,6 +23,7 @@ describe Chef::Knife::Ssh do
before(:all) do
@original_config = Chef::Config.hash_dup
+ @original_knife_config = Chef::Config[:knife].dup
Chef::Knife::Ssh.load_deps
@server = TinyServer::Manager.new
@server.start
@@ -30,6 +31,7 @@ describe Chef::Knife::Ssh do
after(:all) do
Chef::Config.configuration = @original_config
+ Chef::Config[:knife] = @original_knife_config
@server.stop
end
@@ -89,6 +91,19 @@ describe Chef::Knife::Ssh do
end
end
+ describe "port" do
+ context "when -p 31337 is provided" do
+ before do
+ setup_knife(['-p 31337', '*:*', 'uptime'])
+ end
+
+ it "uses the ssh_port" do
+ @knife.run
+ @knife.config[:ssh_port].should == "31337"
+ end
+ end
+ end
+
describe "user" do
context "when knife[:ssh_user] is set" do
before do
@@ -192,6 +207,49 @@ describe Chef::Knife::Ssh do
end
end
+ describe "gateway" do
+ context "when knife[:ssh_gateway] is set" do
+ before do
+ setup_knife(['*:*', 'uptime'])
+ Chef::Config[:knife][:ssh_gateway] = "user@ec2.public_hostname"
+ end
+
+ it "uses the ssh_gateway" do
+ @knife.session.should_receive(:via).with("ec2.public_hostname", "user", {})
+ @knife.run
+ @knife.config[:ssh_gateway].should == "user@ec2.public_hostname"
+ end
+ end
+
+ context "when -G user@ec2.public_hostname is provided" do
+ before do
+ setup_knife(['-G user@ec2.public_hostname', '*:*', 'uptime'])
+ Chef::Config[:knife][:ssh_gateway] = nil
+ end
+
+ it "uses the ssh_gateway" do
+ @knife.session.should_receive(:via).with("ec2.public_hostname", "user", {})
+ @knife.run
+ @knife.config[:ssh_gateway].should == "user@ec2.public_hostname"
+ end
+ end
+
+ context "when the gateway requires a password" do
+ before do
+ setup_knife(['-G user@ec2.public_hostname', '*:*', 'uptime'])
+ Chef::Config[:knife][:ssh_gateway] = nil
+ @knife.session.stub(:via) do |host, user, options|
+ raise Net::SSH::AuthenticationFailed unless options[:password]
+ end
+ end
+
+ it "should prompt the user for a password" do
+ @knife.ui.should_receive(:ask).with("Enter the password for user@ec2.public_hostname: ").and_return("password")
+ @knife.run
+ end
+ end
+ end
+
def setup_knife(params=[])
@knife = Chef::Knife::Ssh.new(params)
# We explicitly avoid running #configure_chef, which would read a knife.rb