diff --git a/Gemfile.lock b/Gemfile.lock index a1f63dd3..1b594926 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,66 +10,65 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (7.2.2) - actionpack (= 7.2.2) - activesupport (= 7.2.2) + actioncable (8.0.0) + actionpack (= 8.0.0) + activesupport (= 8.0.0) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.2.2) - actionpack (= 7.2.2) - activejob (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + actionmailbox (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) mail (>= 2.8.0) - actionmailer (7.2.2) - actionpack (= 7.2.2) - actionview (= 7.2.2) - activejob (= 7.2.2) - activesupport (= 7.2.2) + actionmailer (8.0.0) + actionpack (= 8.0.0) + actionview (= 8.0.0) + activejob (= 8.0.0) + activesupport (= 8.0.0) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.2.2) - actionview (= 7.2.2) - activesupport (= 7.2.2) + actionpack (8.0.0) + actionview (= 8.0.0) + activesupport (= 8.0.0) nokogiri (>= 1.8.5) - racc - rack (>= 2.2.4, < 3.2) + rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (7.2.2) - actionpack (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) + actiontext (8.0.0) + actionpack (= 8.0.0) + activerecord (= 8.0.0) + activestorage (= 8.0.0) + activesupport (= 8.0.0) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.2.2) - activesupport (= 7.2.2) + actionview (8.0.0) + activesupport (= 8.0.0) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.2.2) - activesupport (= 7.2.2) + activejob (8.0.0) + activesupport (= 8.0.0) globalid (>= 0.3.6) - activemodel (7.2.2) - activesupport (= 7.2.2) - activerecord (7.2.2) - activemodel (= 7.2.2) - activesupport (= 7.2.2) + activemodel (8.0.0) + activesupport (= 8.0.0) + activerecord (8.0.0) + activemodel (= 8.0.0) + activesupport (= 8.0.0) timeout (>= 0.4.0) - activestorage (7.2.2) - actionpack (= 7.2.2) - activejob (= 7.2.2) - activerecord (= 7.2.2) - activesupport (= 7.2.2) + activestorage (8.0.0) + actionpack (= 8.0.0) + activejob (= 8.0.0) + activerecord (= 8.0.0) + activesupport (= 8.0.0) marcel (~> 1.0) - activesupport (7.2.2) + activesupport (8.0.0) base64 benchmark (>= 0.3) bigdecimal @@ -81,6 +80,7 @@ GEM minitest (>= 5.1) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) appraisal (2.5.0) @@ -88,24 +88,24 @@ GEM rake thor (>= 0.14.0) ast (2.4.2) - async (2.19.0) + async (2.21.0) console (~> 1.29) fiber-annotation io-event (~> 1.6, >= 1.6.5) - async-http (0.82.3) + async-http (0.84.0) async (>= 2.10.2) async-pool (~> 0.9) io-endpoint (~> 0.14) io-stream (~> 0.6) metrics (~> 0.12) - protocol-http (~> 0.37) + protocol-http (~> 0.43) protocol-http1 (>= 0.28.1) protocol-http2 (~> 0.19) traces (~> 0.10) async-http-faraday (0.19.0) async-http (~> 0.42) faraday - async-pool (0.10.1) + async-pool (0.10.2) async (>= 1.25) traces backport (1.2.0) @@ -134,14 +134,14 @@ GEM drb (2.2.1) e2mmap (0.1.0) erubi (1.13.0) - faraday (2.12.0) - faraday-net_http (>= 2.0, < 3.4) + faraday (2.12.1) + faraday-net_http (>= 2.0, < 3.5) json logger faraday-http-cache (2.5.1) faraday (>= 0.8) - faraday-net_http (3.3.0) - net-http + faraday-net_http (3.4.0) + net-http (>= 0.5.0) fiber-annotation (0.2.0) fiber-local (1.1.0) fiber-storage @@ -189,7 +189,7 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) - hashdiff (1.1.1) + hashdiff (1.1.2) httparty (0.22.0) csv mini_mime (>= 1.0.0) @@ -199,19 +199,19 @@ GEM concurrent-ruby (~> 1.0) io-console (0.7.2) io-endpoint (0.14.0) - io-event (1.7.3) + io-event (1.7.4) io-stream (0.6.1) irb (1.14.1) rdoc (>= 4.0.0) reline (>= 0.4.2) jaro_winkler (1.6.0) - json (2.8.1) + json (2.8.2) json-schema (2.8.1) addressable (>= 2.4) jwt (2.9.3) base64 - kramdown (2.4.0) - rexml + kramdown (2.5.1) + rexml (>= 3.3.9) kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) language_server-protocol (3.17.0.3) @@ -228,13 +228,13 @@ GEM method_source (1.1.0) metrics (0.12.1) mini_mime (1.1.5) - minitest (5.25.1) + minitest (5.25.2) multi_json (1.15.0) multi_xml (0.6.0) - mutex_m (0.2.0) + mutex_m (0.3.0) net-http (0.5.0) uri - net-imap (0.5.0) + net-imap (0.5.1) date net-protocol net-pop (0.1.2) @@ -265,14 +265,13 @@ GEM ast (~> 2.4.1) racc protocol-hpack (1.5.1) - protocol-http (0.42.0) + protocol-http (0.45.0) protocol-http1 (0.28.1) protocol-http (~> 0.22) - protocol-http2 (0.19.4) + protocol-http2 (0.20.0) protocol-hpack (~> 1.4) protocol-http (~> 0.18) - traces - pry (0.14.2) + pry (0.15.0) coderay (~> 1.1) method_source (~> 1.0) psych (5.2.0) @@ -284,9 +283,8 @@ GEM rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (2.2.0) + rackup (2.2.1) rack (>= 3) -<<<<<<< HEAD rails (8.0.0) actioncable (= 8.0.0) actionmailbox (= 8.0.0) @@ -301,22 +299,6 @@ GEM activesupport (= 8.0.0) bundler (>= 1.15.0) railties (= 8.0.0) -======= - rails (7.2.2) - actioncable (= 7.2.2) - actionmailbox (= 7.2.2) - actionmailer (= 7.2.2) - actionpack (= 7.2.2) - actiontext (= 7.2.2) - actionview (= 7.2.2) - activejob (= 7.2.2) - activemodel (= 7.2.2) - activerecord (= 7.2.2) - activestorage (= 7.2.2) - activesupport (= 7.2.2) - bundler (>= 1.15.0) - railties (= 7.2.2) ->>>>>>> 7618b23697e91ab1ababee5234faaa260f6c873e rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -324,15 +306,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) -<<<<<<< HEAD railties (8.0.0) actionpack (= 8.0.0) activesupport (= 8.0.0) -======= - railties (7.2.2) - actionpack (= 7.2.2) - activesupport (= 7.2.2) ->>>>>>> 7618b23697e91ab1ababee5234faaa260f6c873e irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) @@ -341,7 +317,7 @@ GEM rainbow (3.1.1) rake (13.2.1) rbs (2.8.4) - rdoc (6.7.0) + rdoc (6.8.1) psych (>= 4.0.0) regexp_parser (2.9.2) reline (0.5.11) @@ -364,11 +340,7 @@ GEM rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) -<<<<<<< HEAD - rspec-rails (7.0.1) -======= rspec-rails (7.1.0) ->>>>>>> 7618b23697e91ab1ababee5234faaa260f6c873e actionpack (>= 7.0) activesupport (>= 7.0) railties (>= 7.0) @@ -377,17 +349,17 @@ GEM rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.1) - rubocop (1.68.0) + rubocop (1.69.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 2.4, < 3.0) - rubocop-ast (>= 1.32.2, < 2.0) + rubocop-ast (>= 1.36.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.34.1) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.36.1) parser (>= 3.3.1.0) rubocop-capybara (2.21.0) rubocop (~> 1.41) @@ -404,7 +376,7 @@ GEM sawyer (0.9.2) addressable (>= 2.3.5) faraday (>= 0.17.3, < 3) - securerandom (0.3.1) + securerandom (0.3.2) signet (0.19.0) addressable (~> 2.8) faraday (>= 0.17.5, < 3.a) @@ -426,16 +398,16 @@ GEM thor (~> 1.0) tilt (~> 2.0) yard (~> 0.9, >= 0.9.24) - sqlite3 (2.2.0-aarch64-linux-gnu) - sqlite3 (2.2.0-aarch64-linux-musl) - sqlite3 (2.2.0-arm-linux-gnu) - sqlite3 (2.2.0-arm-linux-musl) - sqlite3 (2.2.0-arm64-darwin) - sqlite3 (2.2.0-x86-linux-gnu) - sqlite3 (2.2.0-x86-linux-musl) - sqlite3 (2.2.0-x86_64-darwin) - sqlite3 (2.2.0-x86_64-linux-gnu) - sqlite3 (2.2.0-x86_64-linux-musl) + sqlite3 (2.3.1-aarch64-linux-gnu) + sqlite3 (2.3.1-aarch64-linux-musl) + sqlite3 (2.3.1-arm-linux-gnu) + sqlite3 (2.3.1-arm-linux-musl) + sqlite3 (2.3.1-arm64-darwin) + sqlite3 (2.3.1-x86-linux-gnu) + sqlite3 (2.3.1-x86-linux-musl) + sqlite3 (2.3.1-x86_64-darwin) + sqlite3 (2.3.1-x86_64-linux-gnu) + sqlite3 (2.3.1-x86_64-linux-musl) stringio (3.1.2) thor (1.3.2) tilt (2.4.0) @@ -446,8 +418,10 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unicode-display_width (2.6.0) - uri (1.0.1) + unicode-display_width (3.1.2) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + uri (1.0.2) useragent (0.16.10) webmock (3.24.0) addressable (>= 2.8.0) @@ -459,11 +433,7 @@ GEM with_model (2.1.7) activerecord (>= 6.0) yard (0.9.37) -<<<<<<< HEAD zeitwerk (2.7.1) -======= - zeitwerk (2.6.18) ->>>>>>> 7618b23697e91ab1ababee5234faaa260f6c873e PLATFORMS aarch64-linux diff --git a/lib/dfe/analytics/event.rb b/lib/dfe/analytics/event.rb index 036d0332..eaab9d84 100644 --- a/lib/dfe/analytics/event.rb +++ b/lib/dfe/analytics/event.rb @@ -61,7 +61,7 @@ def with_user(user) end def with_namespace(namespace) - @event_hash.merge!(namespace: namespace) + @event_hash.merge!(namespace:) self end @@ -126,7 +126,8 @@ def hash_to_kv_pairs(hash) end def anonymised_user_agent_and_ip(rack_request) - DfE::Analytics.anonymise(rack_request.user_agent.to_s + rack_request.remote_ip.to_s) if rack_request.remote_ip.present? + Rails.logger.info("X-REAL-IP: #{rack_request.headers['X-REAL-IP']}") + DfE::Analytics.anonymise(rack_request.user_agent.to_s + rack_request.headers['X-REAL-IP'].to_s) if rack_request.headers['X-REAL-IP'].present? end def user_identifier(user) diff --git a/spec/dfe/analytics/event_spec.rb b/spec/dfe/analytics/event_spec.rb index 37d8dd97..54c35739 100644 --- a/spec/dfe/analytics/event_spec.rb +++ b/spec/dfe/analytics/event_spec.rb @@ -23,7 +23,7 @@ describe 'anonymised_user_agent_and_ip' do subject do request = fake_request( - remote_ip: remote_ip, + headers: headers, user_agent: user_agent ) @@ -33,28 +33,28 @@ context 'user agent and IP are both present' do let(:user_agent) { 'SomeClient' } - let(:remote_ip) { '1.2.3.4' } + let(:headers) { { 'X-REAL-IP' => '1.2.3.4' } } it { is_expected.to eq '90d5c396fe8da875d25688dfec3f2881c52e81507614ba1958262c8443db29c5' } end context 'user agent is present but IP is not' do let(:user_agent) { 'SomeClient' } - let(:remote_ip) { nil } + let(:headers) { { 'X-REAL-IP' => nil } } it { is_expected.to be_nil } end context 'IP is present but user agent is not' do let(:user_agent) { nil } - let(:remote_ip) { '1.2.3.4' } + let(:headers) { { 'X-REAL-IP' => '1.2.3.4' } } it { is_expected.to eq '6694f83c9f476da31f5df6bcc520034e7e57d421d247b9d34f49edbfc84a764c' } end context 'neither IP not user agent is present' do let(:user_agent) { nil } - let(:remote_ip) { nil } + let(:headers) { { 'X-REAL-IP' => nil } } it { is_expected.to be_nil } end @@ -238,9 +238,9 @@ def fake_request(overrides = {}) query_string: 'a=b', referer: nil, user_agent: 'SomeClient', - remote_ip: '1.2.3.4' + headers: { 'X-REAL-IP' => '1.2.3.4' } }.merge(overrides) instance_double(ActionDispatch::Request, attrs) end -end +end \ No newline at end of file diff --git a/spec/dfe/analytics/requests_spec.rb b/spec/dfe/analytics/requests_spec.rb index c08fdb8a..b7b4655f 100644 --- a/spec/dfe/analytics/requests_spec.rb +++ b/spec/dfe/analytics/requests_spec.rb @@ -61,7 +61,7 @@ def index { key: 'array_param[]', value: %w[1 2] }], request_referer: nil, - anonymised_user_agent_and_ip: '16859db7ca4ec906925a0a2cb227bf307740a0c919ab9e2f7efeadf37779e770', + anonymised_user_agent_and_ip: '6b3f52c670279e133a78a03e34eea436c65395417ec264eb9f8c1e6da4f5ed56', response_content_type: 'text/plain; charset=utf-8', response_status: 200, namespace: 'example_namespace', @@ -80,7 +80,7 @@ def index perform_enqueued_jobs do get('/example/path', params: { page: '1', per_page: '25', array_param: %w[1 2] }, - headers: { 'HTTP_USER_AGENT' => 'Test agent' }) + headers: { 'HTTP_USER_AGENT' => 'Test agent', 'X-REAL-IP' => '1.2.3.4' }) end end @@ -100,7 +100,7 @@ def index request_path: '/unauthenticated_example', request_query: [], request_referer: nil, - anonymised_user_agent_and_ip: '12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0', + anonymised_user_agent_and_ip: '6694f83c9f476da31f5df6bcc520034e7e57d421d247b9d34f49edbfc84a764c', response_content_type: 'text/plain; charset=utf-8', response_status: 200 } end @@ -110,7 +110,8 @@ def index DfE::Analytics::Testing.webmock! do perform_enqueued_jobs do - get('/unauthenticated_example') + get('/unauthenticated_example', + headers: { 'X-REAL-IP' => '1.2.3.4' }) end end @@ -131,7 +132,7 @@ def index request_path: '/unauthenticated_example', request_query: [], request_referer: nil, - anonymised_user_agent_and_ip: '12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0', + anonymised_user_agent_and_ip: '6694f83c9f476da31f5df6bcc520034e7e57d421d247b9d34f49edbfc84a764c', response_content_type: 'text/html; charset=utf-8', response_status: 304 } end @@ -156,7 +157,8 @@ def index DfE::Analytics::Testing.webmock! do perform_enqueued_jobs do - get('/unauthenticated_example') + get('/unauthenticated_example', + headers: { 'X-REAL-IP' => '1.2.3.4' }) end end @@ -217,4 +219,4 @@ def index expect(request).not_to have_been_made end end -end +end \ No newline at end of file