Skip to content

Commit

Permalink
Merge pull request #46 from salemove/MSG-709
Browse files Browse the repository at this point in the history
Add checks to allow logging only specific datatypes
  • Loading branch information
HallikiM authored Dec 13, 2023
2 parents 0051711 + 89af667 commit f7847ad
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
lenjador (2.2.1)
lenjador (2.2.2)
lru_redux
oj (~> 3.6)

Expand Down
2 changes: 1 addition & 1 deletion lenjador.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |gem|
gem.name = 'lenjador'
gem.version = '2.2.1'
gem.version = '2.2.2'
gem.authors = ['Salemove']
gem.email = ['[email protected]']
gem.description = "It's lenjadoric"
Expand Down
5 changes: 4 additions & 1 deletion lib/lenjador/preprocessors/strategies/mask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ def process(data, pointer = '')
when Array
process_array(data, pointer)

else
when String, Numeric, Symbol, Date, Time, TrueClass, FalseClass, NilClass
data

else
MASKED_VALUE
end
end

Expand Down
5 changes: 4 additions & 1 deletion lib/lenjador/preprocessors/strategies/prune.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ def process(data, pointer = '')
when Array
process_array(data, pointer)

else
when String, Numeric, Symbol, Date, Time, TrueClass, FalseClass, NilClass
data

else
nil
end
end

Expand Down
198 changes: 195 additions & 3 deletions spec/lenjador/preprocessors/whitelist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,105 @@
end

context 'when boolean present' do
let(:data) { {bool: true} }
let(:pointers) { ['/bool'] }
let(:data) do
{
bool: true,
bool2: true
}
end

it 'masks only if not in whitelist' do
expect(processed_data).to eq({
bool: true,
bool2: '*****'
})
end
end

context 'when nil present' do
let(:pointers) { ['/nil'] }
let(:data) do
{
nil: nil,
nil2: nil
}
end

it 'masks it with asteriks' do
expect(processed_data).to eq(bool: '*****')
it 'masks only if not in whitelist' do
expect(processed_data).to eq({
nil: nil,
nil2: '*****'
})
end
end

context 'when numbers present' do
let(:data) do
{
integer: 1,
float: 2.03,
integer2: 3,
float2: 3.34324
}
end
let(:pointers) { ['/integer', '/float'] }

it 'masks only if not in whitelist' do
expect(processed_data).to eq({
integer: 1,
float: 2.03,
integer2: '*****',
float2: '*****'
})
end
end

context 'when symbol present' do
let(:data) do
{
symbol1: :symbol1,
symbol2: :symbol2
}
end
let(:pointers) { ['/symbol1'] }

it 'masks only if not in whitelist' do
expect(processed_data).to eq({
symbol1: :symbol1,
symbol2: '*****'
})
end
end

context 'when date time present' do
let(:data) do
{
date: Date.new(2023, 12, 12),
time: Time.new(2023, 12, 13),
datetime: DateTime.new(2023, 12, 14)
}
end
let(:pointers) { ['/date', '/time', '/datetime'] }

it 'shows dates' do
expect(processed_data).to eq({
date: Date.new(2023, 12, 12),
time: Time.new(2023, 12, 13),
datetime: DateTime.new(2023, 12, 14)
})
end
end

context 'when unsupported object present' do
let(:pointers) { ['/field'] }
let(:some_class) { OpenStruct.new(name: 'Rowdy', pin_code: '1234') }
let(:data) { {field: some_class} }

it 'masks the object' do
expect(processed_data).to eq(
field: '*****'
)
end
end

Expand Down Expand Up @@ -312,6 +407,103 @@ def process(pointers, data)
end
end

context 'when boolean present' do
let(:pointers) { ['/bool'] }
let(:data) do
{
bool: true,
bool2: true
}
end

it 'prunes only if not in whitelist' do
expect(processed_data).to eq({
bool: true
})
end
end

context 'when nil present' do
let(:pointers) { ['/nil'] }
let(:data) do
{
nil: nil,
nil2: nil
}
end

it 'prunes only if not in whitelist' do
expect(processed_data).to eq({
nil: nil
})
end
end

context 'when numbers present' do
let(:data) do
{
integer: 1,
float: 2.03,
integer2: 3,
float2: 3.34324
}
end
let(:pointers) { ['/integer', '/float'] }

it 'prunes only if not in whitelist' do
expect(processed_data).to eq({
integer: 1,
float: 2.03
})
end
end

context 'when symbol present' do
let(:data) do
{
symbol1: :symbol1,
symbol2: :symbol2
}
end
let(:pointers) { ['/symbol1'] }

it 'prunes only if not in whitelist' do
expect(processed_data).to eq({
symbol1: :symbol1
})
end
end

context 'when date time present' do
let(:data) do
{
date: Date.new(2023, 12, 12),
time: Time.new(2023, 12, 13),
datetime: DateTime.new(2023, 12, 14)
}
end
let(:pointers) { ['/date', '/time', '/datetime'] }

it 'shows dates' do
expect(processed_data).to eq({
date: Date.new(2023, 12, 12),
time: Time.new(2023, 12, 13),
datetime: DateTime.new(2023, 12, 14)
})
end
end

context 'when unsupported object present' do
let(:pointers) { ['/class'] }
let(:some_class) { OpenStruct.new(name: 'Rowdy', pin_code: '1234') }

let(:data) { {class: some_class} }

it 'does not return the object' do
expect(processed_data).to eq({class: nil})
end
end

def process(pointers, data)
described_class.new(pointers: pointers, action: :prune).process(data)
end
Expand Down

0 comments on commit f7847ad

Please sign in to comment.