Skip to content

Commit

Permalink
Merge pull request heartcombo#1398 from salidux/master
Browse files Browse the repository at this point in the history
Trackable don't work properly behind a proxy
  • Loading branch information
josevalim committed Oct 22, 2011
2 parents 6079a02 + d114026 commit d525636
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/devise/models/trackable.rb
Expand Up @@ -16,7 +16,7 @@ def update_tracked_fields!(request)
self.last_sign_in_at = old_current || new_current
self.current_sign_in_at = new_current

old_current, new_current = self.current_sign_in_ip, request.remote_ip
old_current, new_current = self.current_sign_in_ip, request.ip
self.last_sign_in_ip = old_current || new_current
self.current_sign_in_ip = new_current

Expand Down
11 changes: 11 additions & 0 deletions test/integration/trackable_test.rb
Expand Up @@ -36,6 +36,17 @@ class TrackableHooksTest < ActionController::IntegrationTest
assert_equal "127.0.0.1", user.current_sign_in_ip
assert_equal "127.0.0.1", user.last_sign_in_ip
end

test "current remote ip returns original ip behind a non transparent proxy" do
user = create_user

arbitrary_ip = '192.168.1.69'
sign_in_as_user do
header 'HTTP_X_FORWARDED_FOR', arbitrary_ip
end
user.reload
assert_equal arbitrary_ip, user.current_sign_in_ip
end

test "increase sign in count" do
user = create_user
Expand Down

0 comments on commit d525636

Please sign in to comment.