0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 10:42:34 +08:00
discourse/spec/integration/invalid_request_spec.rb
David Taylor 1b8f8e7169
FIX: Correctly rescue failed embed_mode parsing (#40298)
Rails already handles this situation gracefully. However, our own
parsing of the query parameter in the request_tracker middleware would
not. This commit adds handling, and adds a new invalid_request_spec to
verify the behavior.
2026-05-26 15:29:48 +01:00

45 lines
1.4 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "invalid requests", type: :request do
let(:fake_logger) { FakeLogger.new }
before { Rails.logger.broadcast_to(fake_logger) }
after { Rails.logger.stop_broadcasting_to(fake_logger) }
it "handles NotFound with invalid json body" do
post "/latest.json",
params: "{some: malformed: json",
headers: {
"content-type" => "application/json",
}
expect(response.status).to eq(404)
expect(fake_logger.warnings).to be_empty
expect(fake_logger.errors).to have_attributes(size: 1)
end
it "handles EOFError when multipart request is malformed" do
post "/latest.json",
params: "somecontent",
headers: {
"content-type" => "multipart/form-data; boundary=abcde",
"content-length" => "1",
}
expect(response.status).to eq(400)
expect(fake_logger.warnings).to be_empty
expect(fake_logger.errors).to have_attributes(size: 1)
end
it "handles invalid parameters" do
post "/latest.json", params: { "foo" => "\255bar" }
expect(response.status).to eq(404)
expect(fake_logger.warnings).to be_empty
expect(fake_logger.errors).to have_attributes(size: 1)
end
it "handles query strings whose key types collide" do
get "/?foo=1&foo%5B1%5D=2"
expect(response.status).to eq(400)
expect(fake_logger.warnings).to be_empty
end
end