aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-05-19 18:24:52 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-05-19 18:24:52 +0000
commitdd8c92ea5be3faa9436363d8a37d5debec2027c4 (patch)
treed1e465b53afe7da9de4f34cb24125a8df8925bfc /actionpack
parent473e5bde747d227d47d00e9b5f52b668b29f53df (diff)
downloadrails-dd8c92ea5be3faa9436363d8a37d5debec2027c4.tar.gz
rails-dd8c92ea5be3faa9436363d8a37d5debec2027c4.tar.bz2
rails-dd8c92ea5be3faa9436363d8a37d5debec2027c4.zip
Fixed Request#remote_ip in testing #1251 [bitsweat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1322 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/test_process.rb8
-rw-r--r--actionpack/test/controller/request_test.rb33
3 files changed, 41 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index cd7d8591fc..51306db495 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed Request#remote_ip in testing #1251 [bitsweat]
+
* Fixed that compute_public_path should recognize external URLs, so image_tag("http://www.example.com/images/icon.gif") is not prefixed with the relative url path #1254 [victor-ronr-trac@carotena.net]
* Added support for descending year values in DateHelper#select_year, like select_year(Date.today, :start_year => 2005, :end_year => 1900), which would count down from 2005 to 1900 instead of the other way #1274 [nwoods@mail.com]
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index 3fd86477db..25ad540468 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -32,7 +32,7 @@ module ActionController #:nodoc:
class TestRequest < AbstractRequest #:nodoc:
attr_accessor :cookies
attr_accessor :query_parameters, :request_parameters, :path, :session, :env
- attr_accessor :host, :remote_addr
+ attr_accessor :host
def initialize(query_parameters = nil, request_parameters = nil, session = nil)
@query_parameters = query_parameters || {}
@@ -71,6 +71,10 @@ module ActionController #:nodoc:
@path = uri.split("?").first
end
+ def remote_addr=(addr)
+ @env['REMOTE_ADDR'] = addr
+ end
+
def request_uri
@request_uri || super()
end
@@ -88,7 +92,7 @@ module ActionController #:nodoc:
def initialize_default_values
@host = "test.host"
@request_uri = "/"
- @remote_addr, @remote_ip = "127.0.0.1"
+ self.remote_addr = "127.0.0.1"
@env["SERVER_PORT"] = 80
end
end
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index 372d5929fa..76082c2dbd 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -5,6 +5,39 @@ class RequestTest < Test::Unit::TestCase
@request = ActionController::TestRequest.new
end
+ def test_remote_ip
+ assert_equal '127.0.0.1', @request.remote_ip
+
+ @request.remote_addr = '1.2.3.4'
+ assert_equal '1.2.3.4', @request.remote_ip
+
+ @request.env['HTTP_CLIENT_IP'] = '2.3.4.5'
+ assert_equal '2.3.4.5', @request.remote_ip
+ @request.env.delete 'HTTP_CLIENT_IP'
+
+ @request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
+ assert_equal '3.4.5.6', @request.remote_ip
+
+ @request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,3.4.5.6'
+ assert_equal '3.4.5.6', @request.remote_ip
+
+ @request.env['HTTP_X_FORWARDED_FOR'] = '172.16.0.1,3.4.5.6'
+ assert_equal '3.4.5.6', @request.remote_ip
+
+ @request.env['HTTP_X_FORWARDED_FOR'] = '192.168.0.1,3.4.5.6'
+ assert_equal '3.4.5.6', @request.remote_ip
+
+ @request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1,3.4.5.6'
+ assert_equal '3.4.5.6', @request.remote_ip
+
+ @request.env['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,3.4.5.6'
+ assert_equal '127.0.0.1', @request.remote_ip
+
+ @request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,192.168.0.1'
+ assert_equal '1.2.3.4', @request.remote_ip
+ @request.env.delete 'HTTP_X_FORWARDED_FOR'
+ end
+
def test_domains
@request.host = "www.rubyonrails.org"
assert_equal "rubyonrails.org", @request.domain