Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ rvm:
- 2.2
- 2.1
- 2.0
branches:
only:
- master
matrix:
include:
# Run Danger only once, on 2.5
Expand Down
19 changes: 8 additions & 11 deletions test/functional/backends/test_netssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_simple_netssh
"Command: /usr/bin/env ls -l\n",
"Command: if test ! -d /tmp; then echo \"Directory does not exist '/tmp'\" 1>&2; false; fi\n",
"Command: if ! sudo -u root whoami > /dev/null; then echo \"You cannot switch to user 'root' using sudo, please check the sudoers file\" 1>&2; false; fi\n",
"Command: cd /tmp && ( export RAILS_ENV=\"production\" ; sudo -u root RAILS_ENV=\"production\" -- sh -c '/usr/bin/env touch restart.txt' )\n"
"Command: cd /tmp && ( export RAILS_ENV=\"production\" ; sudo -u root RAILS_ENV=\"production\" -- sh -c /usr/bin/env\\ touch\\ restart.txt )\n"
], command_lines
end

Expand Down Expand Up @@ -82,7 +82,7 @@ def test_group_netssh
command_lines = @output.lines.select { |line| line.start_with?('Command:') }
assert_equal [
"Command: if ! sudo -u root whoami > /dev/null; then echo \"You cannot switch to user 'root' using sudo, please check the sudoers file\" 1>&2; false; fi\n",
"Command: sudo -u root -- sh -c 'sg admin -c \"/usr/bin/env touch restart.txt\"'\n"
"Command: sudo -u root -- sh -c sg\\ admin\\ -c\\ /usr/bin/env\\\\\\ touch\\\\\\ restart.txt\n"
], command_lines
end

Expand All @@ -96,21 +96,18 @@ def test_capture
end

def test_ssh_option_merge
verify_host_opt = if Net::SSH::Version::MAJOR >= 5
{ verify_host_key: :always }
else
{ paranoid: true }
end
a_host.ssh_options = verify_host_opt
keepalive_opt = { keepalive: true }
test_host = a_host.dup
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added .dup here because the modifications to a_host were polluting other tests.

test_host.ssh_options = keepalive_opt
host_ssh_options = {}
SSHKit::Backend::Netssh.config.ssh_options = { forward_agent: false }
Netssh.new(a_host) do |host|
Netssh.new(test_host) do |host|
capture(:uname)
host_ssh_options = host.ssh_options
end.run
assert_equal [:forward_agent, *verify_host_opt.keys, :known_hosts, :logger, :password_prompt].sort, host_ssh_options.keys.sort
assert_equal [:forward_agent, *keepalive_opt.keys, :known_hosts, :logger, :password_prompt].sort, host_ssh_options.keys.sort
assert_equal false, host_ssh_options[:forward_agent]
assert_equal verify_host_opt.values.first, host_ssh_options[verify_host_opt.keys.first]
assert_equal keepalive_opt.values.first, host_ssh_options[keepalive_opt.keys.first]
assert_instance_of SSHKit::Backend::Netssh::KnownHosts, host_ssh_options[:known_hosts]
end

Expand Down
11 changes: 10 additions & 1 deletion test/support/vagrant_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ def vm_host(vm)
user: vm['user'] || 'vagrant',
hostname: vm['hostname'] || 'localhost',
port: vm['port'] || '22',
password: vm['password'] || 'vagrant'
password: vm['password'] || 'vagrant',
ssh_options: host_verify_options
}

SSHKit::Host.new(host_options)
end

def host_verify_options
if Net::SSH::Version::MAJOR >= 5
{ verify_host_key: :never }
else
{ paranoid: false }
end
end
end
end