summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2022-08-03 13:29:00 +1200
committerGitHub <noreply@github.com>2022-08-02 18:29:00 -0700
commit3012643ea6a89fefe8cc0c68d4992531c367c906 (patch)
tree142ba02da11ba64ccf3453f59b715c70622fdc95 /test
parentb961d2b4810292163051bad4feb4ff1ca4ea50d1 (diff)
downloadrack-3012643ea6a89fefe8cc0c68d4992531c367c906.tar.gz
Separate and simplify full & partial hijack. (#1939)
* Separate full and partial rack hijack. - Remove `rack.hijack_io` which is at best difficult to use and at worst buggy. - Separate full and partial hijack specifications, `rack.hijack?` implies that partial hijacking is supported, `rack.hijack` implies that full hijacking is supported.
Diffstat (limited to 'test')
-rwxr-xr-xtest/spec_lint.rb51
1 files changed, 5 insertions, 46 deletions
diff --git a/test/spec_lint.rb b/test/spec_lint.rb
index 785509c7..6a735b0d 100755
--- a/test/spec_lint.rb
+++ b/test/spec_lint.rb
@@ -793,63 +793,22 @@ describe Rack::Lint do
assert_lint 1, ''.dup
end
- it "notice hijack errors" do
+ it "notices when request env doesn't have a valid rack.hijack callback" do
lambda {
Rack::Lint.new(lambda { |env|
env['rack.hijack'].call
[201, { "content-type" => "text/plain", "content-length" => "0" }, []]
- }).call(env({ 'rack.hijack?' => false, 'rack.hijack' => Object.new }))
- }.must_raise(Rack::Lint::LintError).
- message.must_equal 'rack.hijack? is false, but rack.hijack is present'
-
- lambda {
- Rack::Lint.new(lambda { |env|
- env['rack.hijack'].call
- [201, { "content-type" => "text/plain", "content-length" => "0" }, []]
- }).call(env({ 'rack.hijack?' => false, 'rack.hijack_io' => Object.new }))
- }.must_raise(Rack::Lint::LintError).
- message.must_equal 'rack.hijack? is false, but rack.hijack_io is present'
-
- lambda {
- Rack::Lint.new(lambda { |env|
- env['rack.hijack'].call
- [201, { "content-type" => "text/plain", "content-length" => "0" }, []]
- }).call(env({ 'rack.hijack?' => true, 'rack.hijack' => Object.new }))
+ }).call(env({ 'rack.hijack' => Object.new }))
}.must_raise(Rack::Lint::LintError).
message.must_match(/rack.hijack must respond to call/)
+ end
- lambda {
- Rack::Lint.new(lambda { |env|
- env['rack.hijack'].call
- [201, { "content-type" => "text/plain", "content-length" => "0" }, []]
- }).call(env({ 'rack.hijack?' => true, 'rack.hijack' => lambda { Object.new } }))
- }.must_raise(Rack::Lint::LintError).
- message.must_match(/rack.hijack_io must respond to read/)
-
+ it "notices when the response headers don't have a valid rack.hijack callback" do
lambda {
Rack::Lint.new(lambda { |env|
[201, { "content-type" => "text/plain", "content-length" => "0", 'rack.hijack' => Object.new }, []]
- }).call(env({ 'rack.hijack?' => true, 'rack.hijack' => lambda { Object.new } }))
+ }).call(env({ 'rack.hijack?' => true }))
}.must_raise(Rack::Lint::LintError).
message.must_equal 'rack.hijack header must respond to #call'
-
- lambda {
- Rack::Lint.new(lambda { |env|
- [201, { "content-type" => "text/plain", "content-length" => "0", 'rack.hijack' => Object.new }, []]
- }).call(env({}))
- }.must_raise(Rack::Lint::LintError).
- message.must_equal 'rack.hijack header must not be present if server does not support hijacking'
-
- Rack::Lint.new(lambda { |env|
- env['rack.hijack'].call
- [201, { "content-type" => "text/plain", "content-length" => "0" }, []]
- }).call(env({ 'rack.hijack?' => true, 'rack.hijack' => lambda { StringIO.new }, 'rack.hijack_io' => StringIO.new })).
- first.must_equal 201
-
- Rack::Lint.new(lambda { |env|
- env['rack.hijack?'] = true
- [201, { "content-type" => "text/plain", "content-length" => "0", 'rack.hijack' => lambda {|io| io }, 'rack.hijack_io' => StringIO.new }, []]
- }).call(env({}))[1]['rack.hijack'].call(StringIO.new).read.must_equal ''
end
-
end