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