diff --git a/inspec.gemspec b/inspec.gemspec index e1527333d..af888a823 100644 --- a/inspec.gemspec +++ b/inspec.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_dependency 'train', '>=0.19.0', '<1.0' + spec.add_dependency 'train', '>=0.19.1', '<1.0' spec.add_dependency 'thor', '~> 0.19' spec.add_dependency 'json', '>= 1.8', '< 3.0' spec.add_dependency 'rainbow', '~> 2' diff --git a/lib/resources/ssl.rb b/lib/resources/ssl.rb index aa1db5077..26722c74b 100644 --- a/lib/resources/ssl.rb +++ b/lib/resources/ssl.rb @@ -44,18 +44,16 @@ class SSL < Inspec.resource(1) attr_reader :host, :port def initialize(opts = {}) - @host = opts[:host] || - inspec.backend.instance_variable_get(:@hostname) - # FIXME: This can be removed when/if @hostname is available as a property for 'Train::Transports::WinRM::Connection' - # Train enhancement request for this here: https://github.com/chef/train/issues/128 - if @host.nil? && inspec.backend.class.to_s == 'Train::Transports::WinRM::Connection' - @host = URI.parse(inspec.backend.instance_variable_get(:@options)[:endpoint]).hostname - end - if @host.nil? && inspec.backend.class.to_s == 'Train::Transports::Local::Connection' - @host = 'localhost' - end + @host = opts[:host] if @host.nil? - fail 'Cannot determine host for SSL test. Please specify it or use a different target.' + # Transports like SSH and WinRM will provide a hostname + if inspec.backend.respond_to?('hostname') + @host = inspec.backend.hostname + elsif inspec.backend.class.to_s == 'Train::Transports::Local::Connection' + @host = 'localhost' + else + fail 'Cannot determine host for SSL test. Please specify it or use a different target.' + end end @port = opts[:port] || 443 @timeout = opts[:timeout]