Skip to content
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/sentry/sanitizer/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def sanitize_hash!(event)

def sanitize_breadcrumb!(breadcrumb)
return unless breadcrumbs_json_data_fields.size.positive?
return unless breadcrumb.data
return unless breadcrumb.data.is_a? Hash

breadcrumbs_json_data_fields.each do |field|
next unless breadcrumb.data.key?(field)
Expand Down
73 changes: 42 additions & 31 deletions spec/sentry/sanitizer/cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -446,56 +446,67 @@
describe "breadcrumb" do
subject { described_class.new(Sentry.configuration.sanitize).call(breadcrumb) }

let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test") }
context "without any sanitize configuration set" do
let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test", data: { body: nil }) }

before do
Sentry.init do |config|
config.sanitize.fields = ["password"]
it "doesn't change breadcrumb" do
expect { subject }.not_to(change { breadcrumb.to_h })
end
end

it "doesn't change breadcrumb" do
expect { subject }.not_to(change { breadcrumb.to_h })
end
context "with only sanitize fields configuration set" do
let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test") }

context "with data" do
let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test", data: { body: body }) }
let(:body) { nil }
before do
Sentry.init do |config|
config.sanitize.fields = ["password"]
end
end

it "doesn't change breadcrumb" do
expect { subject }.not_to(change { breadcrumb.to_h })
end
end

context "with configuration" do
before do
Sentry.init do |config|
config.sanitize.fields = ["password"]
config.sanitize.breadcrumbs.json_data_fields = [:body]
end
context "with sanitize fields and breadcrumbs configuration set" do
before do
Sentry.init do |config|
config.sanitize.fields = ["password"]
config.sanitize.breadcrumbs.json_data_fields = [:body]
end

before { subject }
subject
end

context "when field is nil" do
it "returns the breadcrumb as is" do
expect(breadcrumb.data).to eq({ body: body })
end
context "when the field has a nil value" do
let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test", data: { body: nil }) }

it "returns the breadcrumb data as is" do
expect(breadcrumb.data).to eq({ body: nil })
end
end

context "when field has parseable JSON" do
let(:body) { JSON.dump(password: "PASSWORD") }
context "when the field has parseable JSON" do
let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test", data: { body: JSON.dump(password: "PASSWORD") }) }

it "changes breadcrumb" do
expect(breadcrumb.data[:body]).to eq(JSON.dump(password: Sentry::Sanitizer::Cleaner::DEFAULT_MASK))
end
it "sanitizes the breadcrumb data" do
expect(breadcrumb.data[:body]).to eq(JSON.dump(password: Sentry::Sanitizer::Cleaner::DEFAULT_MASK))
end
end

context "when field is something that is not parseable JSON" do
let(:body) { "not parseable JSON" }
context "when the field is something that is not parseable JSON" do
let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test", data: { body: "not parseable JSON" }) }

it "returns the breadcrumb as is" do
expect(breadcrumb.data).to eq({ body: "not parseable JSON" })
end
it "returns the breadcrumb data as is" do
expect(breadcrumb.data).to eq({ body: "not parseable JSON" })
end
end

context "when the breadcrumb data is not a Hash" do
let(:breadcrumb) { Sentry::Breadcrumb.new(message: "test", data: "just a string") }

it "returns the breadcrumb data as is" do
expect(breadcrumb.data).to eq("just a string")
end
end
end
Expand Down
Loading