Skip to content

Commit

Permalink
transforms ips to hashes (#6)
Browse files Browse the repository at this point in the history
* transforms ips to hashes

* updates version

* transforms forwarded_ip to hash only if it is present

* changes from SHA1 to SHA256

* don't set forwarded_ip anymore
  • Loading branch information
chrisokamoto authored and gewo committed May 31, 2018
1 parent dad3ffa commit a27fb52
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ gemspec
gem "jquery-rails"

gem "responders"

gem 'test-unit', '~> 3.0'
3 changes: 2 additions & 1 deletion gemfiles/rails_3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ source "https://rubygems.org/"

gem "jquery-rails"
gem "responders"
gem "test-unit", "~> 3.0"
gem "rails", "~> 3.2.21"
gem "mongoid", "~> 3.1.6"

gemspec :path => "../"
gemspec path: "../"
3 changes: 2 additions & 1 deletion gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ source "https://rubygems.org/"

gem "jquery-rails"
gem "responders"
gem "test-unit", "~> 3.0"
gem "rails", "~> 4.0"
gem "mongoid", "~> 4"

gemspec :path => "../"
gemspec path: "../"
9 changes: 7 additions & 2 deletions lib/re_track/session_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ def first_visited_at
end

def ip
@request.remote_ip
Digest::SHA256.hexdigest(@request.remote_ip + ip_secret)
end

def accept_language
@request.env['HTTP_ACCEPT_LANGUAGE']
end

def forwarded_ip
@request.env['HTTP_X_FORWARDED_FOR'] || @request.env['HTTP_CLIENT_IP']
# we don't need this information anymore
nil
end

def ip_secret
ENV['ENCRYPT_IP_SECRET'] || ''
end

extend self
Expand Down
2 changes: 1 addition & 1 deletion lib/re_track/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ReTrack
VERSION = '0.6.0'
VERSION = '0.7.4'
end
5 changes: 3 additions & 2 deletions spec/controllers/referer_tracking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@
end

it 'saves the ip in RefererTracking' do
@rt.ip.should == @ip
encrypted_ip = Digest::SHA256.hexdigest(@ip)
@rt.ip.should == encrypted_ip
end

it 'saves the accept_language in RefererTracking' do
expect(@rt.accept_language).to eq @accept_language
end

it 'saves forwarded_ip in RefererTracking' do
expect(@rt.forwarded_ip).to eq @forwarded_ip
expect(@rt.forwarded_ip).to eq nil
end
end

Expand Down

0 comments on commit a27fb52

Please sign in to comment.