2022-02-07 21:16:57 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe "invalid requests", type: :request do
|
2024-06-20 17:42:17 +08:00
|
|
|
before do
|
|
|
|
@orig_logger = Rails.logger
|
|
|
|
Rails.logger = @fake_logger = FakeLogger.new
|
|
|
|
end
|
2022-02-07 21:16:57 +08:00
|
|
|
|
2024-06-20 17:42:17 +08:00
|
|
|
after { Rails.logger = @orig_logger }
|
2022-02-07 21:16:57 +08:00
|
|
|
|
|
|
|
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)
|
2024-06-20 17:42:17 +08:00
|
|
|
expect(@fake_logger.warnings.length).to eq(0)
|
|
|
|
expect(@fake_logger.errors.length).to eq(0)
|
2022-02-07 21:16:57 +08:00
|
|
|
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)
|
2024-06-20 17:42:17 +08:00
|
|
|
expect(@fake_logger.warnings.length).to eq(0)
|
|
|
|
expect(@fake_logger.errors.length).to eq(0)
|
2022-02-07 21:16:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "handles invalid parameters" do
|
|
|
|
post "/latest.json", params: { "foo" => "\255bar" }
|
|
|
|
expect(response.status).to eq(404)
|
2024-06-20 17:42:17 +08:00
|
|
|
expect(@fake_logger.warnings.length).to eq(0)
|
|
|
|
expect(@fake_logger.errors.length).to eq(0)
|
2022-02-07 21:16:57 +08:00
|
|
|
end
|
|
|
|
end
|