Skip to content
Open
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
6 changes: 6 additions & 0 deletions config/scout_apm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ common: &defaults
production:
<<: *defaults
errors_enabled: true
# Replaces Scout's default list (the first two). InvalidType is scanner noise from junk
# Accept/Content-Type headers; Rails already answers it with a 406.
errors_ignored_exceptions:
- ActiveRecord::RecordNotFound
- ActionController::RoutingError
- ActionDispatch::Http::MimeNegotiation::InvalidType

development:
<<: *defaults
Expand Down
26 changes: 26 additions & 0 deletions spec/config/scout_apm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "rails_helper"

RSpec.describe "Scout APM config" do
let(:context) { ScoutApm::Agent.instance.context }
let(:config) do
ScoutApm::Config.with_file(context, Rails.root.join("config/scout_apm.yml").to_s, environment: "production")
end
let(:ignored_exceptions) do
ScoutApm::ErrorService::IgnoredExceptions.new(context, config.value("errors_ignored_exceptions"))
end

it "does not report invalid MIME types from junk Accept or Content-Type headers" do
exception = ActionDispatch::Http::MimeNegotiation::InvalidType.new("not a valid MIME type")

expect(ignored_exceptions.ignored?(exception)).to be true
end

it "keeps ignoring Scout's default exceptions" do
expect(ignored_exceptions.ignored?(ActiveRecord::RecordNotFound.new)).to be true
expect(ignored_exceptions.ignored?(ActionController::RoutingError.new("not found"))).to be true
end

it "still reports other errors" do
expect(ignored_exceptions.ignored?(StandardError.new)).to be false
end
end
20 changes: 20 additions & 0 deletions spec/requests/static_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,25 @@
end

it { is_expected.to be_successful }

context "with an invalid Accept header" do
subject(:request) do
get root_path, headers: {"Accept" => "../../../../../../../../etc/passwd{{"}

response
end

it { is_expected.to have_http_status(:not_acceptable) }
end

context "with an invalid Content-Type header" do
subject(:request) do
get root_path, headers: {"Content-Type" => "../../../../../../../../etc/passwd{{"}

response
end

it { is_expected.to have_http_status(:not_acceptable) }
end
end
end
Loading