From 39bb2b8ed19c4931dfe2c899ae22e2de2b3a2f5b Mon Sep 17 00:00:00 2001 From: Borna Kapusta Date: Mon, 30 Sep 2024 18:33:32 +0200 Subject: [PATCH] Mask sanitized value length (#7) --- lib/treblle/utils/hash_sanitizer.rb | 2 +- spec/lib/utils/hash_sanitizer_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/treblle/utils/hash_sanitizer.rb b/lib/treblle/utils/hash_sanitizer.rb index 93c5f35..49a7206 100644 --- a/lib/treblle/utils/hash_sanitizer.rb +++ b/lib/treblle/utils/hash_sanitizer.rb @@ -32,7 +32,7 @@ def sanitize_array(array, sensitive_attrs) end def sanitize_value(key, value, sensitive_attrs) - sensitive_attrs.include?(key.to_s) ? '*' * value.to_s.length : value + sensitive_attrs.include?(key.to_s) ? "*****" : value end end end diff --git a/spec/lib/utils/hash_sanitizer_spec.rb b/spec/lib/utils/hash_sanitizer_spec.rb index bc100ab..7594cc7 100644 --- a/spec/lib/utils/hash_sanitizer_spec.rb +++ b/spec/lib/utils/hash_sanitizer_spec.rb @@ -33,7 +33,7 @@ context 'when given a hash with sensitive attributes' do let(:input_hash) { { name: 'John', password: 'secretpassword', credit_card: '1234567890123456' } } - let(:expected_subject) { { name: 'John', password: '**************', credit_card: '****************' } } + let(:expected_subject) { { name: 'John', password: '*****', credit_card: '*****' } } it 'replaces sensitive attribute values with asterisks' do expect(subject).to eq(expected_subject) @@ -42,7 +42,7 @@ context 'when given a hash with nested hashes' do let(:input_hash) { { user: { name: 'John', password: 'secretpassword' } } } - let(:expected_subject) { { user: { name: 'John', password: '**************' } } } + let(:expected_subject) { { user: { name: 'John', password: '*****' } } } it 'replaces sensitive attribute values with asterisks' do expect(subject).to eq(expected_subject) @@ -54,7 +54,7 @@ { users: [{ name: 'John', password: 'secretpassword' }, { name: 'Jane', password: 'anotherpassword' }] } end let(:expected_subject) do - { users: [{ name: 'John', password: '**************' }, { name: 'Jane', password: '***************' }] } + { users: [{ name: 'John', password: '*****' }, { name: 'Jane', password: '*****' }] } end it 'replaces sensitive attribute values with asterisks' do