Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure use_ssl option #225

Merged
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
12 changes: 10 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,14 @@ 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)
return false if @use_ssl == false

true
end
end

class << self
Expand Down Expand Up @@ -150,7 +158,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.new }

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