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
9 changes: 8 additions & 1 deletion lib/ews/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Connection
# seconds
# @option opts [Fixnum] :connect_timeout override the default connect timeout
# seconds
# @option opts [OpenSSL::X509::Store] :cert_store a custom cert store
# @option opts [Array] :trust_ca an array of hashed dir paths or a file
# @option opts [String] :user_agent the http user agent to use in all requests
def initialize(endpoint, opts = {})
Expand All @@ -44,7 +45,13 @@ def initialize(endpoint, opts = {})
httpclient_opts = opts.slice(*SUPPORTED_HTTPCLIENT_OPTS)
@httpcli = HTTPClient.new(**httpclient_opts)

if opts[:trust_ca]
if opts[:cert_store].is_a?(OpenSSL::X509::Store)
@log.debug 'Applying custom cert_store provided via opts[:cert_store]'
# Assign the provided store directly
@httpcli.ssl_config.cert_store = opts[:cert_store]

@log.debug 'Skipping original :trust_ca handling due to provided :cert_store.'
elsif opts[:trust_ca]
@httpcli.ssl_config.clear_cert_store
opts[:trust_ca].each do |ca|
@httpcli.ssl_config.add_trust_ca ca
Expand Down
31 changes: 31 additions & 0 deletions spec/ews/connection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'spec_helper'

describe Viewpoint::EWS::Connection do
let(:endpoint) { 'https://example.com/ews/Exchange.asmx' }

def ssl_config_for(opts)
described_class.new(endpoint, opts).instance_variable_get(:@httpcli).ssl_config
end

describe ':cert_store option' do
it 'assigns a custom OpenSSL::X509::Store to the http client' do
store = OpenSSL::X509::Store.new
store.set_default_paths
expect(ssl_config_for(cert_store: store).cert_store).to be(store)
end

it 'skips :trust_ca handling when a custom store is given' do
store = OpenSSL::X509::Store.new
# A bogus :trust_ca path would raise if it were processed.
config = ssl_config_for(cert_store: store, trust_ca: ['/definitely/not/a/ca/path'])
expect(config.cert_store).to be(store)
end

it 'ignores a :cert_store value that is not an OpenSSL::X509::Store' do
config = ssl_config_for(cert_store: 'not-a-store')
expect(config.cert_store).not_to be('not-a-store')
end
end
end