Skip to content
Open
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
7 changes: 7 additions & 0 deletions lib/synapse_pay_rest/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class HTTPClient
# @return [String] the url which is used to proxy outboard requests
attr_reader :proxy_url

# @!attribute [rw] ssl_cert_store
# @return [OpenSSL::X509::Store] the customized CA cert store

# @param base_url [String] the base url of the API (production or sandbox)
# @param client_id [String]
# @param client_secret [String]
Expand All @@ -22,6 +25,7 @@ class HTTPClient
# @param logging [Boolean] (optional) logs to stdout when true
# @param log_to [String] (optional) file path to log to file (logging must be true)
# @param proxy_url [String] (optional) proxy url which is used to proxy outbound requests
# @param ssl_cert_store [OpenSSL::X509::Store] (optional) a custom store of allowed CA certs
def initialize(base_url:, client_id:, fingerprint:, ip_address:,
client_secret:, **options)
log_to = options[:log_to] || 'stdout'
Expand All @@ -31,6 +35,9 @@ def initialize(base_url:, client_id:, fingerprint:, ip_address:,
RestClient.proxy = options[:proxy_url] if options[:proxy_url]
@proxy_url = options[:proxy_url]

RestClient.ssl_cert_store = options[:ssl_cert_store] if options[:ssl_cert_store]
@ssl_cert_store = options[:ssl_cert_store]

@config = {
client_id: client_id,
client_secret: client_secret,
Expand Down
6 changes: 4 additions & 2 deletions samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ args = {
# (optional) if true logs requests to stdout
logging: true,
# (optional) file path to write logs to
log_to: nil
log_to: nil,
# (optional) URL used to proxy outbound requests
proxy_url: nil
proxy_url: nil,
# (optional) a [OpenSSL::X509::Store](https://ruby-doc.org/stdlib-2.5.0/libdoc/openssl/rdoc/OpenSSL/X509/Store.html) of allowed CA certs
ssl_cert_store: nil,
}

client = SynapsePayRest::Client.new(args)
Expand Down
6 changes: 4 additions & 2 deletions test/factories/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ def test_client(client_id: ENV.fetch('TEST_CLIENT_ID'),
development_mode: true,
logging: false,
log_to: nil,
proxy_url: nil)
proxy_url: nil,
ssl_cert_store: nil)

SynapsePayRest::Client.new(
client_id: client_id,
Expand All @@ -15,7 +16,8 @@ def test_client(client_id: ENV.fetch('TEST_CLIENT_ID'),
ip_address: ip_address,
logging: logging,
log_to: log_to,
proxy_url: proxy_url
proxy_url: proxy_url,
ssl_cert_store: ssl_cert_store
)
end

Expand Down
14 changes: 14 additions & 0 deletions test/synapse_pay_rest/http_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def setup

def teardown
RestClient.proxy = nil
RestClient.ssl_cert_store = nil
end

def test_base_url
Expand Down Expand Up @@ -57,4 +58,17 @@ def test_proxy_url
assert_equal client_with_proxy.http_client.proxy_url, proxy_url
assert_equal RestClient.proxy, proxy_url
end

def test_ssl_cert_store
cert_store = OpenSSL::X509::Store.new
cert_store.set_default_paths

client_without_store = test_client
assert_nil client_without_store.http_client.ssl_cert_store
assert_nil RestClient.ssl_cert_store

client_with_store = test_client(ssl_cert_store: cert_store)
assert_equal client_with_store.http_client.ssl_cert_store, cert_store
assert_equal RestClient.ssl_cert_store, cert_store
end
end