Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask sanitized value length #7

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading