Skip to content
Snippets Groups Projects
Commit 6c5769cf authored by jlhonora's avatar jlhonora
Browse files

Disable SSL v2 and v3 if ssl enabled

parent df0aaa6c
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ end
group :test do
gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
gem 'webmock'
platforms :ruby do
gem 'pg'
......
......@@ -274,6 +274,7 @@ module Geocoder
uri = URI.parse(query_url(query))
Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
http_client.start(uri.host, uri.port, use_ssl: use_ssl?, open_timeout: configuration.timeout, read_timeout: configuration.timeout) do |client|
configure_ssl!(client) if use_ssl?
req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
if configuration.basic_auth[:user] and configuration.basic_auth[:password]
req.basic_auth(
......@@ -297,6 +298,8 @@ module Geocoder
end
end
def configure_ssl!(client); end
def check_api_key_configuration!(query)
key_parts = query.lookup.required_api_key_parts
if key_parts.size > Array(configuration.api_key).size
......
......@@ -27,6 +27,13 @@ module Geocoder::Lookup
private # ---------------------------------------------------------------
def configure_ssl!(client)
client.instance_eval {
@ssl_context = OpenSSL::SSL::SSLContext.new
@ssl_context.set_params({:options=> OpenSSL::SSL::OP_NO_SSLv2 | OpenSSL::SSL::OP_NO_SSLv3 | OpenSSL::SSL::OP_NO_COMPRESSION})
}
end
def valid_response?(response)
json = parse_json(response.body)
status = json["status"] if json
......
......@@ -120,6 +120,7 @@ module Geocoder
fixture_exists?(filename) ? filename : default_fixture_filename
end
alias_method :make_api_http_request, :make_api_request
remove_method(:make_api_request)
def make_api_request(query)
......
......@@ -160,4 +160,19 @@ class LookupTest < GeocoderTestCase
assert_equal :google, Geocoder::Lookup::Google.new.handle
assert_equal :geocoder_ca, Geocoder::Lookup::GeocoderCa.new.handle
end
def test_http_request
Geocoder.configure(use_https: true)
require 'webmock/test_unit'
WebMock.enable!
stub_all = WebMock.stub_request(:any, /.*/).to_return(status: 200)
g = Geocoder::Lookup::Google.new
g.send(:make_api_http_request, Geocoder::Query.new('test location'))
assert_requested(stub_all)
WebMock.reset!
WebMock.disable!
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment