Skip to content

Commit

Permalink
Allow to configure use_ssl option
Browse files Browse the repository at this point in the history
  • Loading branch information
mantaskujalis committed Jul 17, 2023
1 parent 95f260c commit 25c0b94
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/mangopay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Configuration
:client_id, :client_apiKey,
:temp_dir, :log_file, :http_timeout,
:http_max_retries, :http_open_timeout,
:logger
:logger, :use_ssl

def preproduction
@preproduction || false
Expand All @@ -74,6 +74,13 @@ def http_max_retries
def http_open_timeout
@http_open_timeout || 30
end

def use_ssl
return true unless preproduction == true
return true unless defined?(@use_ssl)

@use_ssl
end
end

class << self
Expand Down Expand Up @@ -150,7 +157,7 @@ def request(method, url, params={}, filters={}, headers_or_idempotency_key = nil
headers['Idempotency-Key'] = headers_or_idempotency_key if headers_or_idempotency_key != nil
end

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, :read_timeout => configuration.http_timeout,
res = Net::HTTP.start(uri.host, uri.port, use_ssl: configuration.use_ssl, :read_timeout => configuration.http_timeout,
:max_retries => configuration.http_max_retries,
:open_timeout => configuration.http_open_timeout, ssl_version: :TLSv1_2) do |http|
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
Expand Down
30 changes: 30 additions & 0 deletions spec/mangopay/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@
expect(users).to be_kind_of(Array)
end

describe 'use_ssl' do
let(:configuration) { MangoPay.configuration }

it 'defaults to true' do
expect(configuration.use_ssl).to eq(true)
end

context 'when assigned to false in production' do
before do
configuration.use_ssl = false
configuration.preproduction = false
end

it 'uses true as value' do
expect(configuration.use_ssl).to eq(true)
end
end

context 'when assigned to false in preproduction' do
before do
configuration.use_ssl = false
configuration.preproduction = true
end

it 'uses assigned as value' do
expect(configuration.use_ssl).to eq(false)
end
end
end

describe 'logger' do
around(:each) do |example|
c = MangoPay.configuration
Expand Down

0 comments on commit 25c0b94

Please sign in to comment.