Remove fallback to hostip.info
authorTom Hughes <tom@compton.nu>
Mon, 6 Jan 2020 19:14:12 +0000 (19:14 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 6 Jan 2020 19:14:12 +0000 (19:14 +0000)
We haven't used hostip.info in production for years, except
for when we did so by accident, leading to a two hour partial
outage when it went down.

lib/osm.rb
test/application_system_test_case.rb
test/controllers/api/users_controller_test.rb
test/controllers/site_controller_test.rb
test/controllers/users_controller_test.rb
test/integration/oauth_test.rb
test/integration/page_locale_test.rb
test/integration/user_creation_test.rb
test/integration/user_terms_seen_test.rb
test/test_helper.rb

index 26ebca09f9a7a235a820b533be5c8742b6d89e09..3e4b5dcee4b005d8b4db2bc2b7e81bf8bf9eeedc 100644 (file)
@@ -513,15 +513,8 @@ module OSM
   def self.ip_to_country(ip_address)
     ipinfo = maxmind_database.lookup(ip_address) if Settings.key?(:maxmind_database)
 
-    if ipinfo&.found?
-      country = ipinfo.country.iso_code
-    else
-      country = http_client.get("https://api.hostip.info/country.php?ip=#{ip_address}").body
-      country = "GB" if country == "UK"
-    end
+    return ipinfo.country.iso_code if ipinfo&.found?
 
-    country
-  rescue StandardError
     nil
   end
 
index 96406b5a3c5fc58000e326ba0b16cdca17a09ecc..581297313a0dcc7f23e1c1db7403595e80378785 100644 (file)
@@ -13,12 +13,6 @@ end
 class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
   driven_by :poltergeist, :screen_size => [1400, 1400], :options => { :timeout => 120 }
 
-  def initialize(*args)
-    stub_request(:get, "https://api.hostip.info/country.php?ip=127.0.0.1")
-      .to_return(:status => 404)
-    super(*args)
-  end
-
   # Phantomjs can pick up browser Accept-Language preferences from your desktop environment.
   # We don't want this to happen during the tests!
   setup do
index cc9d932bcb3e705b726a19e1a5a276bd572cdf1e..437020c5f3a4705ff7f442e8546465b45128bfea 100644 (file)
@@ -2,12 +2,6 @@ require "test_helper"
 
 module Api
   class UsersControllerTest < ActionController::TestCase
-    def setup
-      super
-
-      stub_hostip_requests
-    end
-
     ##
     # test all routes which lead to this controller
     def test_routes
index ed20f4d90575ec66fb30027eba46426272c39507..4dc07f9960a8613b43248d16d541ec28ac4f7aa0 100644 (file)
@@ -8,8 +8,6 @@ class SiteControllerTest < ActionController::TestCase
 
     Settings.id_key = create(:client_application).key
     Settings.potlatch2_key = create(:client_application).key
-
-    stub_hostip_requests
   end
 
   ##
index feca92df56dbcbe594bdbc2b756b2df737d3c398..5097c42fb515ce64e1626cf57eb1e058f03da185 100644 (file)
@@ -1,12 +1,6 @@
 require "test_helper"
 
 class UsersControllerTest < ActionController::TestCase
-  def setup
-    super
-
-    stub_hostip_requests
-  end
-
   ##
   # test all routes which lead to this controller
   def test_routes
index 60e1db24d8e63b62b860bed413490c8a54eb8965..618ced0e6304625f4a22d16e6dc24693facab5b9 100644 (file)
@@ -3,10 +3,6 @@ require "test_helper"
 class OAuthTest < ActionDispatch::IntegrationTest
   include OAuth::Helper
 
-  def setup
-    stub_hostip_requests
-  end
-
   def test_oauth10_web_app
     client = create(:client_application, :callback_url => "http://some.web.app.example.org/callback", :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true)
 
index 9c42d9be760b993f420d2de5fa7493a8563e067a..2c4939b054fddf456565505dbd48802e4215c4f1 100644 (file)
@@ -3,7 +3,6 @@ require "test_helper"
 class PageLocaleTest < ActionDispatch::IntegrationTest
   def setup
     I18n.locale = "en"
-    stub_hostip_requests
   end
 
   def teardown
index 4d9bca7bfa2efbbedd2a8d2be7a682e92376f83a..a353245161013b4dc83ad067c74a23e49d700247 100644 (file)
@@ -7,7 +7,6 @@ class UserCreationTest < ActionDispatch::IntegrationTest
     OmniAuth.config.test_mode = true
 
     stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
-    stub_hostip_requests
   end
 
   def teardown
index 32fdba0b2c09516f26209de4400863213ef344b4..51eab5b18947ca0d0d53c635a8aa9a305b17d228 100644 (file)
@@ -1,10 +1,6 @@
 require "test_helper"
 
 class UserTermsSeenTest < ActionDispatch::IntegrationTest
-  def setup
-    stub_hostip_requests
-  end
-
   def test_api_blocked
     user = create(:user, :terms_seen => false, :terms_agreed => nil)
 
index 4d9372148f270cd447df619f1c438f2f4335b238..378d49bb9a02f43097cfe13c9b73c32c702e1aac 100644 (file)
@@ -159,12 +159,6 @@ module ActiveSupport
       stub_request(:get, url).and_return(:status => status, :body => body)
     end
 
-    def stub_hostip_requests
-      # Controller tests and integration tests use different IPs
-      stub_request(:get, "https://api.hostip.info/country.php?ip=0.0.0.0")
-      stub_request(:get, "https://api.hostip.info/country.php?ip=127.0.0.1")
-    end
-
     def email_text_parts(message)
       message.parts.each_with_object([]) do |part, text_parts|
         if part.content_type.start_with?("text/")
@@ -176,7 +170,6 @@ module ActiveSupport
     end
 
     def sign_in_as(user)
-      stub_hostip_requests
       visit login_path
       fill_in "username", :with => user.email
       fill_in "password", :with => "test"