diff options
author | Thom May <thom@may.lt> | 2017-11-20 18:50:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-20 18:50:57 +0000 |
commit | d91594fb85c67dd18430a14368872a8efe000a86 (patch) | |
tree | c053cc8be6b5055dd2ddc9e87bfbb1b6823554a2 | |
parent | 25d1ec70d26e999a9998e6b8df6078f0df01aa5a (diff) | |
parent | ab2aad50f613eb9b2f59da2c1452b27fd3f2f589 (diff) | |
download | chef-d91594fb85c67dd18430a14368872a8efe000a86.tar.gz |
Merge pull request #6593 from afn/master
Filter out periods from tmux session name
-rw-r--r-- | lib/chef/knife/ssh.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/ssh_spec.rb | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index ae14ce9954..f4a025dba3 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -461,7 +461,7 @@ class Chef end.join(" \\; ") end - tmux_name = "'knife ssh #{@name_args[0].tr(':', '=')}'" + tmux_name = "'knife ssh #{@name_args[0].tr(':.', '=-')}'" begin server = session.servers_for.first cmd = ["tmux new-session -d -s #{tmux_name}", diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index e15ca8a7f0..815995b687 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -295,6 +295,23 @@ describe Chef::Knife::Ssh do end end + describe "#tmux" do + before do + ssh_config = { :timeout => 50, :user => "locutus", :port => 23, :keepalive => true, :keepalive_interval => 60 } + allow(Net::SSH).to receive(:configuration_for).with("foo.example.org", true).and_return(ssh_config) + @query = Chef::Search::Query.new + expect(@query).to receive(:search).and_yield(@node_foo) + allow(Chef::Search::Query).to receive(:new).and_return(@query) + allow(@knife).to receive(:exec).and_return(0) + end + + it "filters out invalid characters from tmux session name" do + @knife.name_args = ["name:foo.example.org", "tmux"] + expect(@knife).to receive(:shell_out!).with("tmux new-session -d -s 'knife ssh name=foo-example-org' -n 'foo.example.org' 'ssh locutus@foo.example.org' ") + @knife.run + end + end + describe "#run" do before do @query = Chef::Search::Query.new |