Browse Source

refactor client_ip to use RemoteIp middleware

pull/1/head
Nicolae Claudius 11 years ago
parent
commit
02fe04be7f
  1. 2
      app/controllers/application_controller.rb
  2. 3
      config/settings.sample.yml
  3. 4
      spec/controllers/users/records_controller_spec.rb

2
app/controllers/application_controller.rb

@ -32,7 +32,7 @@ class ApplicationController < ActionController::Base
end
def client_remote_ip
@client_remote_ip ||= request.env["HTTP_X_FORWARDED_FOR"]
@client_remote_ip ||= Settings.uses_proxy ? request.remote_ip : request.ip
end
def check_honeypot

3
config/settings.sample.yml

@ -1,6 +1,9 @@
# framework
secret_key_base: 0ce1f02a4b3fc4d1a1c8d22973b21e8589e9314dc338294953f0b985e3f44f12c8af74f2d9ba6f7c7bdb736c4efc5ea3f8135e23b1a036d033cd23331383ac75
# deployment
uses_proxy: true
# application
default_ttl: 3600
min_ttl: 60

4
spec/controllers/users/records_controller_spec.rb

@ -21,7 +21,7 @@ describe Users::RecordsController do
it "modifies @record with remote IP" do
ip = '127.0.0.3'
request.env["HTTP_X_FORWARDED_FOR"] = ip
@request.env['REMOTE_ADDR'] = ip
get :modify, :authentication_token => a_record.authentication_token
response.should be_success
response.body.should == Users::RecordsController::MODIFY_OK
@ -31,7 +31,7 @@ describe Users::RecordsController do
it "errors when not A type @record with" do
ip = '127.0.0.3'
request.env["HTTP_X_FORWARDED_FOR"] = ip
@request.env['REMOTE_ADDR'] = ip
get :modify, :authentication_token => soa_record.authentication_token
response.should be_success
response.body.should == Users::RecordsController::MODIFY_ERROR

Loading…
Cancel
Save