PHP 8.2.31
Preview: spec_showstatus.rb Size: 2.74 KB
/proc/thread-self/root/opt/alt/ruby23/lib64/ruby/gems/2.3.0/gems/rack-1.6.4/test/spec_showstatus.rb

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

Directory Contents

Dirs: 7 × Files: 51

Name Size Perms Modified Actions
builder DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
cgi DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
multipart DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
rackup DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
static DIR
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
- drwxr-xr-x 2024-03-03 22:53:12
Edit Download
298 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.26 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
8.08 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.20 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
6.20 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.11 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.92 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.87 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.37 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.28 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
544 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.80 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.47 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
10.04 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.19 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.84 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
3.08 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
6.32 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.87 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.36 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
19.23 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.23 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
4.33 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
622 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.38 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.81 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
9.34 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
5.73 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
23.62 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
514 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.83 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
42.52 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
10.08 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.78 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.53 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
4.12 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
5.57 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.29 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
12.94 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
11.12 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
6.53 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.01 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.74 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
4.60 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.57 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
2.55 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
8.82 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
24.89 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
504 B lrw-r--r-- 2019-12-05 23:22:18
Edit Download
5.50 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download
1.96 KB lrw-r--r-- 2019-12-05 23:22:18
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).