Skip to content

Commit 5500d8d

Browse files
committed
Update spec_acceptance_helper for net-ssh 5 support
1 parent ecf145f commit 5500d8d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

spec/spec_helper_acceptance.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
require 'serverspec'
44
require 'puppet_litmus'
5-
include PuppetLitmus
65
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
6+
include PuppetLitmus
77

88
if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
99
puts 'Running tests against this machine !'
@@ -28,14 +28,38 @@
2828
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
2929
options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil?
3030
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
31-
options[:verify_host_key] = Net::SSH::Verifiers::Null.new unless node_config.dig('ssh', 'host-key-check').nil?
31+
# Support both net-ssh 4 and 5.
32+
# rubocop:disable Metrics/BlockNesting
33+
options[:verify_host_key] = if node_config.dig('ssh', 'host-key-check').nil?
34+
# Fall back to SSH behavior. This variable will only be set in net-ssh 5.3+.
35+
if @strict_host_key_checking.nil? || @strict_host_key_checking
36+
Net::SSH::Verifiers::Always.new
37+
else
38+
# SSH's behavior with StrictHostKeyChecking=no: adds new keys to known_hosts.
39+
# If known_hosts points to /dev/null, then equivalent to :never where it
40+
# accepts any key beacuse they're all new.
41+
Net::SSH::Verifiers::AcceptNewOrLocalTunnel.new
42+
end
43+
elsif node_config.dig('ssh', 'host-key-check')
44+
if defined?(Net::SSH::Verifiers::Always)
45+
Net::SSH::Verifiers::Always.new
46+
else
47+
Net::SSH::Verifiers::Secure.new
48+
end
49+
elsif defined?(Net::SSH::Verifiers::Never)
50+
Net::SSH::Verifiers::Never.new
51+
else
52+
Net::SSH::Verifiers::Null.new
53+
end
54+
# rubocop:enable Metrics/BlockNesting
3255
host = if ENV['TARGET_HOST'].include?(':')
3356
ENV['TARGET_HOST'].split(':').first
3457
else
3558
ENV['TARGET_HOST']
3659
end
3760
set :host, options[:host_name] || host
3861
set :ssh_options, options
62+
set :request_pty, true
3963
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
4064
require 'winrm'
4165

0 commit comments

Comments
 (0)