Skip to content
Snippets Groups Projects
Commit ee5ee852 authored by Alex Reisner's avatar Alex Reisner
Browse files

Force :google to use HTTPS if API key set.

parent 70e21e0d
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,15 @@ module Geocoder::Lookup ...@@ -12,6 +12,15 @@ module Geocoder::Lookup
"http://maps.google.com/maps?q=#{coordinates.join(',')}" "http://maps.google.com/maps?q=#{coordinates.join(',')}"
end end
def supported_protocols
# Google requires HTTPS if an API key is used.
if configuration.api_key
[:https]
else
[:http, :https]
end
end
def query_url(query) def query_url(query)
"#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query) "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query)
end end
......
...@@ -10,7 +10,7 @@ class HttpsTest < GeocoderTestCase ...@@ -10,7 +10,7 @@ class HttpsTest < GeocoderTestCase
end end
def test_uses_http_by_default def test_uses_http_by_default
g = Geocoder::Lookup::Google.new g = Geocoder::Lookup::Esri.new
assert_match(/^http:/, g.query_url(Geocoder::Query.new("test"))) assert_match(/^http:/, g.query_url(Geocoder::Query.new("test")))
end end
end end
...@@ -16,6 +16,6 @@ class GooglePremierTest < GeocoderTestCase ...@@ -16,6 +16,6 @@ class GooglePremierTest < GeocoderTestCase
def test_query_url def test_query_url
Geocoder.configure(google_premier: {api_key: ["deadbeef", "gme-test", "test-dev"]}) Geocoder.configure(google_premier: {api_key: ["deadbeef", "gme-test", "test-dev"]})
query = Geocoder::Query.new("Madison Square Garden, New York, NY") query = Geocoder::Query.new("Madison Square Garden, New York, NY")
assert_equal "http://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&channel=test-dev&client=gme-test&language=en&sensor=false&signature=doJvJqX7YJzgV9rJ0DnVkTGZqTg=", query.url assert_equal "https://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&channel=test-dev&client=gme-test&language=en&sensor=false&signature=doJvJqX7YJzgV9rJ0DnVkTGZqTg=", query.url
end end
end end
...@@ -80,4 +80,9 @@ class GoogleTest < GeocoderTestCase ...@@ -80,4 +80,9 @@ class GoogleTest < GeocoderTestCase
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}" assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
end end
def test_google_uses_https_when_api_key_is_set
Geocoder.configure(api_key: "deadbeef")
query = Geocoder::Query.new("Madison Square Garden, New York, NY")
assert_match /^https:/, query.url
end
end end
...@@ -5,25 +5,25 @@ class ProxyTest < GeocoderTestCase ...@@ -5,25 +5,25 @@ class ProxyTest < GeocoderTestCase
def test_uses_proxy_when_specified def test_uses_proxy_when_specified
Geocoder.configure(:http_proxy => 'localhost') Geocoder.configure(:http_proxy => 'localhost')
lookup = Geocoder::Lookup::Google.new lookup = Geocoder::Lookup::Esri.new
assert lookup.send(:http_client).proxy_class? assert lookup.send(:http_client).proxy_class?
end end
def test_doesnt_use_proxy_when_not_specified def test_doesnt_use_proxy_when_not_specified
lookup = Geocoder::Lookup::Google.new lookup = Geocoder::Lookup::Esri.new
assert !lookup.send(:http_client).proxy_class? assert !lookup.send(:http_client).proxy_class?
end end
def test_exception_raised_on_bad_proxy_url def test_exception_raised_on_bad_proxy_url
Geocoder.configure(:http_proxy => ' \\_O< Quack Quack') Geocoder.configure(:http_proxy => ' \\_O< Quack Quack')
assert_raise Geocoder::ConfigurationError do assert_raise Geocoder::ConfigurationError do
Geocoder::Lookup::Google.new.send(:http_client) Geocoder::Lookup::Esri.new.send(:http_client)
end end
end end
def test_accepts_proxy_with_http_protocol def test_accepts_proxy_with_http_protocol
Geocoder.configure(:http_proxy => 'http://localhost') Geocoder.configure(:http_proxy => 'http://localhost')
lookup = Geocoder::Lookup::Google.new lookup = Geocoder::Lookup::Esri.new
assert lookup.send(:http_client).proxy_class? assert lookup.send(:http_client).proxy_class?
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