Sha256: c517776618da1abaec56602544781fe109601c59422fd6636e4f467159811361

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'rspec/webservice_matchers/version'
require 'curb'

module RSpec
  module WebserviceMatchers

    def self.has_valid_ssl_cert?(domain_name)
      begin
        Curl.get "https://#{domain_name}"  # Faster than Curl.head; not sure why.
        return true
      rescue Curl::Err::ConnectionFailedError, Curl::Err::SSLCACertificateError, Curl::Err::SSLPeerCertificateError
        # Not serving SSL, expired, or incorrect domain name
        return false
      end
    end

    #
    # Custom RSpec matcher: have_a_valid_cert
    #
    RSpec::Matchers.define :have_a_valid_cert do
      match do |domain_name|
        RSpec::WebserviceMatchers.has_valid_ssl_cert?(domain_name)
      end
    end


    # Would this matcher be helpful?

    #
    # Return true if the domain serves content via SSL
    # without checking certificate validity.
    #
    # def self.supports_ssl?(domain_name)
    #   begin
    #     has_valid_ssl_cert?(domain_name)
    #     # Cert may not be valid, but content IS
    #     # being served via https.
    #     return true
    #   rescue Curl::Err::ConnectionFailedError
    #     return false
    #   end
    # end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-webservice_matchers-0.0.2 lib/rspec/webservice_matchers.rb
rspec-webservice_matchers-0.0.1 lib/rspec/webservice_matchers.rb