diff --git a/spec/services/analytics_spec.rb b/spec/services/analytics_spec.rb index dd9af8ed352..f639cb38480 100644 --- a/spec/services/analytics_spec.rb +++ b/spec/services/analytics_spec.rb @@ -195,5 +195,18 @@ ) end.to_not raise_error end + + it 'does not alert when pii values are inside words' do + expect(ahoy).to receive(:track) + + stub_const('DocAuth::Mock::ResultResponseBuilder::DEFAULT_PII_FROM_DOC', zipcode: '12345') + + expect do + analytics.track_event( + 'Trackable Event', + some_uuid: '12345678-1234-1234-1234-123456789012', + ) + end.to_not raise_error + end end end diff --git a/spec/support/fake_analytics.rb b/spec/support/fake_analytics.rb index 6268cc926d7..7a4a6195afc 100644 --- a/spec/support/fake_analytics.rb +++ b/spec/support/fake_analytics.rb @@ -26,7 +26,7 @@ def track_event(event, original_attributes = {}) :dob, :state_id_number, ).each do |key, default_pii_value| - if string_payload.include?(default_pii_value) + if string_payload.match?(Regexp.new('\b' + Regexp.quote(default_pii_value) + '\b', 'i')) raise PiiDetected, <<~ERROR track_event example PII #{key} (#{default_pii_value}) detected in attributes event: #{event} (#{constant_name})