diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-01-14 16:21:55 -0800 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2022-01-25 19:13:45 +1300 |
commit | 78ddf81fe2a189e322c3b628046bbc41fc14d1b1 (patch) | |
tree | fa9ee2c5e48a77b0ad34ede533a4ea959c0657b0 /test | |
parent | a411e18b00fe58187eb95dd1479878631f3a7473 (diff) | |
download | rack-78ddf81fe2a189e322c3b628046bbc41fc14d1b1.tar.gz |
Require the response headers be an unfrozen hash in SPEC
This is stricter than what was previously required. However,
non-hash response headers would break most of the middleware
that accesses response headers.
Middleware in many cases adds or removes headers, so require
the hash not be frozen, so that this can be done efficiently.
Fixes #1222
Diffstat (limited to 'test')
-rwxr-xr-x | test/spec_lint.rb | 22 | ||||
-rw-r--r-- | test/spec_webrick.rb | 2 |
2 files changed, 18 insertions, 6 deletions
diff --git a/test/spec_lint.rb b/test/spec_lint.rb index 4bc28c64..d822f985 100755 --- a/test/spec_lint.rb +++ b/test/spec_lint.rb @@ -284,15 +284,24 @@ describe Rack::Lint do end it "notice header errors" do + obj = Object.new + def obj.each; end lambda { io = StringIO.new('a') io.binmode Rack::Lint.new(lambda { |env| env['rack.input'].each{ |x| } - [200, Object.new, []] + [200, obj, []] }).call(env({ "rack.input" => io })) }.must_raise(Rack::Lint::LintError). - message.must_equal "headers object should respond to #each, but doesn't (got Object as headers)" + message.must_equal "headers object should be a hash, but isn't (got Object as headers)" + lambda { + Rack::Lint.new(lambda { |env| + [200, {}.freeze, []] + }).call(env({})) + }.must_raise(Rack::Lint::LintError). + message.must_equal "headers object should not be frozen, but is" + lambda { Rack::Lint.new(lambda { |env| @@ -364,10 +373,13 @@ describe Rack::Lint do [200, { "Foo-Bar" => "one\ntwo\nthree", "Content-Length" => "0", "Content-Type" => "text/plain" }, []] }).call(env({})).first.must_equal 200 - # non-Hash header responses.must_be :allowed? - Rack::Lint.new(lambda { |env| + lambda { + Rack::Lint.new(lambda { |env| [200, [%w(Content-Type text/plain), %w(Content-Length 0)], []] - }).call(env({})).first.must_equal 200 + }).call(env({})) + }.must_raise(Rack::Lint::LintError). + message.must_equal "headers object should be a hash, but isn't (got Array as headers)" + end it "notice content-type errors" do diff --git a/test/spec_webrick.rb b/test/spec_webrick.rb index 9946a7b4..d67dd35f 100644 --- a/test/spec_webrick.rb +++ b/test/spec_webrick.rb @@ -178,7 +178,7 @@ describe Rack::Handler::WEBrick do Rack::Lint.new(lambda{ |req| [ 200, - [ [ "rack.hijack", io_lambda ] ], + { "rack.hijack" => io_lambda }, [""] ] }) |