Skip to content

Commit

Permalink
Mask sanitized value length (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
KapustaB authored Sep 30, 2024
1 parent b16c65b commit 39bb2b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/treblle/utils/hash_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/utils/hash_sanitizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 39bb2b8

Please sign in to comment.