Skip to content

Commit

Permalink
regression tests for existing kinds of bad params currently handled okay
Browse files Browse the repository at this point in the history
But in past versions of bl_range_limit i know from my own app resulted in uncaught exception 500s
  • Loading branch information
jrochkind committed Dec 2, 2024
1 parent 1bacfec commit 4577900
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions spec/requests/bad_param_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

describe CatalogController, type: :request do
let(:range_facet_field) { "pub_date_si" }

let(:parsed_body) { Nokogiri::HTML(response.body) }

describe "bad params should not produce uncaught exception when" do
it "bad root range" do
get "/catalog?range=bad"

expect(response.code).to eq("200")
expect(parsed_body.css("span.applied-filter")).not_to be_present
end

it "facet params are ill structured" do
get "/catalog?#{ {"f" => { range_facet_field => [{"=Library&q="=>""}] } }.to_param }"

expect(response.code).to eq("200")
expect(parsed_body.css("span.applied-filter")).not_to be_present
end

it "newline in range facet does not interupt facet" do
get "/catalog?#{ {"range"=>{ range_facet_field => {"begin"=>"1588\n", "end"=>"2020\n"}}}.to_param }"

expect(response.code).to eq("200")
expect(parsed_body.css("span.applied-filter")).to be_present
expect(parsed_body.css("span.applied-filter").collect(&:text)).to include(/1588.*to.*2020/)
end

it "weird attack in range value is ignored" do
param_hash = {"range"=>{"year_facet_isim"=>{"begin"=>"1989',(;))#- --", "end"=>"1989',(;))#- --"}}}
get "/catalog?#{ param_hash.to_param }"

expect(response.code).to eq("200")
expect(parsed_body.css("span.applied-filter")).not_to be_present
end

it "empty range param is ignored" do
get "/catalog?#{ { "range" => { "year_facet_isim" => nil } }.to_param }"

expect(response.code).to eq("200")
expect(parsed_body.css("span.applied-filter")).not_to be_present
end
end
end

0 comments on commit 4577900

Please sign in to comment.