summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-11-20 18:50:57 +0000
committerGitHub <noreply@github.com>2017-11-20 18:50:57 +0000
commitd91594fb85c67dd18430a14368872a8efe000a86 (patch)
treec053cc8be6b5055dd2ddc9e87bfbb1b6823554a2
parent25d1ec70d26e999a9998e6b8df6078f0df01aa5a (diff)
parentab2aad50f613eb9b2f59da2c1452b27fd3f2f589 (diff)
downloadchef-d91594fb85c67dd18430a14368872a8efe000a86.tar.gz
Merge pull request #6593 from afn/master
Filter out periods from tmux session name
-rw-r--r--lib/chef/knife/ssh.rb2
-rw-r--r--spec/unit/knife/ssh_spec.rb17
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