Sha256: c8a53f763cd6a8d89d2757183daabb04b3871a8f6b5c08fc9fdd48bfe8af4ca1

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true
require 'rspec/webservice_matchers/util'

module RSpec
  module WebserviceMatchers
    module HaveAValidCert
      # Is https is correctly implemented?
      RSpec::Matchers.define :have_a_valid_cert do
        error_message = nil

        match do |domain_name_or_url|
          begin
            Util.try_ssl_connection(domain_name_or_url)
          rescue Exception => e
            error_message = fix_for_excon_bug(e.message)
            false
          end
        end

        failure_message do
          error_message
        end

        # Excon is failing on SSL when a 302 (and possibly others) is received.
        # We should be able to verify the SSL cert even though it's not a
        # 200. HTTPie and Curl are able to.
        # See https://github.com/excon/excon/issues/546
        def fix_for_excon_bug(error_message)
          return error_message unless buggy_message?(error_message)
          'Unable to verify the certificate because a redirect was detected'
        end

        def buggy_message?(text)
          text =~ /Unable to verify|verify failed/
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-webservice_matchers-4.8.1 lib/rspec/webservice_matchers/have_a_valid_cert.rb
rspec-webservice_matchers-4.8.0 lib/rspec/webservice_matchers/have_a_valid_cert.rb
rspec-webservice_matchers-4.7.0 lib/rspec/webservice_matchers/have_a_valid_cert.rb
rspec-webservice_matchers-4.6.0 lib/rspec/webservice_matchers/have_a_valid_cert.rb