From e1b6d887a38984b08b7e17457bafeb771eb269ef Mon Sep 17 00:00:00 2001 From: Rob Di Marco <rob.dimarco@416software.com> Date: Thu, 3 Jan 2013 14:48:09 -0500 Subject: [PATCH] Added a unit test to illustrate bug when HTTP_X_FORWARDED_FOR header is comma delimited --- test/request_test.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/request_test.rb diff --git a/test/request_test.rb b/test/request_test.rb new file mode 100644 index 00000000..3acbe284 --- /dev/null +++ b/test/request_test.rb @@ -0,0 +1,29 @@ +# encoding: utf-8 +require 'test_helper' + +class RequestTest < Test::Unit::TestCase + class MockRequest + include Geocoder::Request + attr_accessor :env, :ip + def initialize(env={}, ip="") + @env = env + @ip = ip + end + end + def test_http_x_real_ip + req = MockRequest.new({"HTTP_X_REAL_IP" => "74.200.247.59"}) + assert req.location.is_a?(Geocoder::Result::Freegeoip) + end + def test_http_x_forwarded_for_without_proxy + req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "74.200.247.59"}) + assert req.location.is_a?(Geocoder::Result::Freegeoip) + end + def test_http_x_forwarded_for_with_proxy + req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "74.200.247.59, 74.200.247.59"}) + assert req.location.is_a?(Geocoder::Result::Freegeoip) + end + def test_with_request_ip + req = MockRequest.new({}, "74.200.247.59") + assert req.location.is_a?(Geocoder::Result::Freegeoip) + end +end \ No newline at end of file -- GitLab