diff options
Diffstat (limited to 'spec/functional')
-rw-r--r-- | spec/functional/knife/ssh_spec.rb | 58 | ||||
-rw-r--r-- | spec/functional/resource/template_spec.rb | 17 |
2 files changed, 74 insertions, 1 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 diff --git a/spec/functional/resource/template_spec.rb b/spec/functional/resource/template_spec.rb index 87a8a3db66..0987aabf05 100644 --- a/spec/functional/resource/template_spec.rb +++ b/spec/functional/resource/template_spec.rb @@ -49,7 +49,22 @@ describe Chef::Resource::Template do create_resource end - let(:default_mode) { "600" } + let(:default_mode) do + # TODO: Lots of ugly here :( + # RemoteFile uses FileUtils.cp. FileUtils does a copy by opening the + # destination file and writing to it. Before 1.9.3, it does not preserve + # the mode of the copied file. In 1.9.3 and after, it does. So we have to + # figure out what the default mode ought to be via heuristic. + + t = Tempfile.new("get-the-mode") + path = t.path + path_2 = t.path + "fileutils-mode-test" + FileUtils.cp(path, path_2) + t.close + m = File.stat(path_2).mode + (07777 & m).to_s(8) + end + it_behaves_like "a file resource" |