|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe CatalogController, type: :request do |
| 4 | + let(:range_facet_field) { "pub_date_si" } |
| 5 | + |
| 6 | + let(:parsed_body) { Nokogiri::HTML(response.body) } |
| 7 | + |
| 8 | + describe "bad params should not produce uncaught exception when" do |
| 9 | + it "bad root range" do |
| 10 | + get "/catalog?range=bad" |
| 11 | + |
| 12 | + expect(response.code).to eq("200") |
| 13 | + expect(parsed_body.css("span.applied-filter")).not_to be_present |
| 14 | + end |
| 15 | + |
| 16 | + it "facet params are ill structured" do |
| 17 | + get "/catalog?#{ {"f" => { range_facet_field => [{"=Library&q="=>""}] } }.to_param }" |
| 18 | + |
| 19 | + expect(response.code).to eq("200") |
| 20 | + expect(parsed_body.css("span.applied-filter")).not_to be_present |
| 21 | + end |
| 22 | + |
| 23 | + it "newline in range facet does not interupt facet" do |
| 24 | + get "/catalog?#{ {"range"=>{ range_facet_field => {"begin"=>"1588\n", "end"=>"2020\n"}}}.to_param }" |
| 25 | + |
| 26 | + expect(response.code).to eq("200") |
| 27 | + expect(parsed_body.css("span.applied-filter")).to be_present |
| 28 | + expect(parsed_body.css("span.applied-filter").collect(&:text)).to include(/1588.*to.*2020/) |
| 29 | + end |
| 30 | + |
| 31 | + it "weird attack in range value is ignored" do |
| 32 | + param_hash = {"range"=>{"year_facet_isim"=>{"begin"=>"1989',(;))#- --", "end"=>"1989',(;))#- --"}}} |
| 33 | + get "/catalog?#{ param_hash.to_param }" |
| 34 | + |
| 35 | + expect(response.code).to eq("200") |
| 36 | + expect(parsed_body.css("span.applied-filter")).not_to be_present |
| 37 | + end |
| 38 | + |
| 39 | + it "empty range param is ignored" do |
| 40 | + get "/catalog?#{ { "range" => { "year_facet_isim" => nil } }.to_param }" |
| 41 | + |
| 42 | + expect(response.code).to eq("200") |
| 43 | + expect(parsed_body.css("span.applied-filter")).not_to be_present |
| 44 | + end |
| 45 | + end |
| 46 | +end |
0 commit comments