Skip to content

Commit

Permalink
Add negative checks to redacted_keys specs
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Oct 5, 2021
1 parent c899ace commit 358f381
Showing 1 changed file with 93 additions and 27 deletions.
120 changes: 93 additions & 27 deletions spec/cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,51 +278,95 @@ def id

describe "redacted keys" do
it "redacts exact string match" do
object = { events: { metaData: { foo: 'bar' } } }
object = { events: { metaData: { foo: 'bar', bar: 'foo' } } }

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set['foo']

cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: '[FILTERED]' } } })
expect(cleaner.clean_object(object)).to eq({
events: {
metaData: {
foo: '[FILTERED]',
bar: 'foo'
}
}
})

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set['bar']

cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: 'bar' } } })
expect(cleaner.clean_object(object)).to eq({
events: {
metaData: {
foo: 'bar',
bar: '[FILTERED]'
}
}
})
end

it "redacts case insensitive string match" do
object = { events: { metaData: { foo: 'bar' } } }
object = { events: { metaData: { foo: 'bar', bar: 'foo' } } }

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set['FOO']

cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: '[FILTERED]' } } })
cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({
events: {
metaData: {
foo: '[FILTERED]',
bar: 'foo'
}
}
})

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set['bar']
configuration.redacted_keys = Set['bAr']

cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: 'bar' } } })
cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({
events: {
metaData: {
foo: 'bar',
bar: '[FILTERED]'
}
}
})
end

it "redacts by regular expression" do
object = { events: { metaData: { foo: 'bar' } } }
object = { events: { metaData: { foo: 'bar', bar: 'foo' } } }

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set[/fb?/]

cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: '[FILTERED]' } } })
expect(cleaner.clean_object(object)).to eq({
events: {
metaData: {
foo: '[FILTERED]',
bar: 'foo'
}
}
})

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set[/fb+/]

cleaner = Bugsnag::Cleaner.new(configuration)
expect(cleaner.clean_object(object)).to eq({ events: { metaData: { foo: 'bar' } } })
expect(cleaner.clean_object(object)).to eq({
events: {
metaData: {
foo: 'bar',
bar: 'foo'
}
}
})
end

it "redacts deeply nested keys" do
Expand All @@ -331,8 +375,17 @@ def id

cleaner = Bugsnag::Cleaner.new(configuration)

params = { events: { metaData: { foo: { bar: 'baz' } } } }
expect(cleaner.clean_object(params)).to eq({ events: { metaData: { foo: { bar: '[FILTERED]' } } } })
params = { events: { metaData: { foo: { bar: 'baz', baz: 'bar' } } } }
expect(cleaner.clean_object(params)).to eq({
events: {
metaData: {
foo: {
bar: '[FILTERED]',
baz: 'bar'
}
}
}
})
end

it "redacts deeply nested request parameters" do
Expand All @@ -341,66 +394,79 @@ def id

cleaner = Bugsnag::Cleaner.new(configuration)

params = { events: { metaData: { request: { params: { foo: { bar: 'baz' } } } } } }
expect(cleaner.clean_object(params)).to eq({ events: { metaData: { request: { params: { foo: { bar: '[FILTERED]' } } } } } })
params = { events: { metaData: { request: { params: { foo: { bar: 'baz', baz: 'bar' } } } } } }
expect(cleaner.clean_object(params)).to eq({
events: {
metaData: {
request: {
params: {
foo: {
bar: '[FILTERED]',
baz: 'bar'
}
}
}
}
}
})
end

it "doesn't filter by string inclusion when the scope is not in 'scopes_to_filter'" do
object = { foo: 'bar' }
it "doesn't filter by string match when the scope is not in 'scopes_to_filter'" do
object = { foo: 'bar', bar: 'foo' }

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set['f']
configuration.redacted_keys = Set['foo']

cleaner = Bugsnag::Cleaner.new(configuration)

expect(cleaner.clean_object(object)).to eq({ foo: 'bar' })
expect(cleaner.clean_object(object)).to eq({ foo: 'bar', bar: 'foo' })

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set['b']
configuration.redacted_keys = Set['bar']

cleaner = Bugsnag::Cleaner.new(configuration)

expect(cleaner.clean_object(object)).to eq({ foo: 'bar' })
expect(cleaner.clean_object(object)).to eq({ foo: 'bar', bar: 'foo' })
end

it "doesn't filter by regular expression when the scope is not in 'scopes_to_filter'" do
object = { foo: 'bar' }
object = { foo: 'bar', bar: 'foo' }

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set[/fb?/]

cleaner = Bugsnag::Cleaner.new(configuration)

expect(cleaner.clean_object(object)).to eq({ foo: 'bar' })
expect(cleaner.clean_object(object)).to eq({ foo: 'bar', bar: 'foo' })

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set[/fb+/]

cleaner = Bugsnag::Cleaner.new(configuration)

expect(cleaner.clean_object(object)).to eq({ foo: 'bar' })
expect(cleaner.clean_object(object)).to eq({ foo: 'bar', bar: 'foo' })
end

it "doesn't filter deeply nested keys when the scope is not in 'scopes_to_filter'" do
params = { foo: { bar: 'baz' } }
params = { foo: { bar: 'baz', baz: 'bar' } }

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set[/^foo\.bar/]

cleaner = Bugsnag::Cleaner.new(configuration)

expect(cleaner.clean_object(params)).to eq({ foo: { bar: 'baz' } })
expect(cleaner.clean_object(params)).to eq({ foo: { bar: 'baz', baz: 'bar' } })
end

it "doesn't filter deeply nested request parameters when the scope is not in 'scopes_to_filter'" do
params = { request: { params: { foo: { bar: 'baz' } } } }
params = { request: { params: { foo: { bar: 'baz', baz: 'bar' } } } }

configuration = Bugsnag::Configuration.new
configuration.redacted_keys = Set[/^foo\.bar/]

cleaner = Bugsnag::Cleaner.new(configuration)

expect(cleaner.clean_object(params)).to eq({ request: { params: { foo: { bar: 'baz' } } } })
expect(cleaner.clean_object(params)).to eq({ request: { params: { foo: { bar: 'baz', baz: 'bar' } } } })
end
end

Expand Down

0 comments on commit 358f381

Please sign in to comment.