2019-11-20 22:51:18 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe Middleware::DiscoursePublicExceptions do
|
2019-11-20 22:51:18 -06:00
|
|
|
before do
|
|
|
|
@orig_logger = Rails.logger
|
|
|
|
Rails.logger = @fake_logger = FakeLogger.new
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
after { Rails.logger = @orig_logger }
|
2019-11-20 22:51:18 -06:00
|
|
|
|
|
|
|
def env(opts = {})
|
|
|
|
{
|
|
|
|
"HTTP_HOST" => "http://test.com",
|
|
|
|
"REQUEST_URI" => "/path?bla=1",
|
|
|
|
"REQUEST_METHOD" => "GET",
|
2023-01-09 05:18:21 -06:00
|
|
|
"rack.input" => "",
|
2019-11-20 22:51:18 -06:00
|
|
|
}.merge(opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not log for invalid mime type requests" do
|
|
|
|
ex = Middleware::DiscoursePublicExceptions.new("/test")
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
ex.call(
|
|
|
|
env(
|
|
|
|
"HTTP_ACCEPT" => "../broken../",
|
|
|
|
"action_dispatch.exception" => ActionController::RoutingError.new("abc"),
|
|
|
|
),
|
|
|
|
)
|
2019-11-20 22:51:18 -06:00
|
|
|
|
|
|
|
expect(@fake_logger.warnings.length).to eq(0)
|
|
|
|
end
|
|
|
|
end
|