diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/rails/test_rails.rb | 2 | ||||
-rw-r--r-- | test/unit/test_http_parser_ng.rb | 4 | ||||
-rw-r--r-- | test/unit/test_tee_input.rb | 32 | ||||
-rw-r--r-- | test/unit/test_util.rb | 10 |
4 files changed, 40 insertions, 8 deletions
diff --git a/test/rails/test_rails.rb b/test/rails/test_rails.rb index 304f519..6742722 100644 --- a/test/rails/test_rails.rb +++ b/test/rails/test_rails.rb @@ -234,7 +234,7 @@ logger Logger.new('#{COMMON_TMP.path}') def test_alt_url_root_config_env # cbf to actually work on this since I never use this feature (ewong) return unless ROR_V[0] >= 2 && ROR_V[1] >= 3 - tmp = Tempfile.new(nil) + tmp = Tempfile.new('') tmp.syswrite("ENV['RAILS_RELATIVE_URL_ROOT'] = '/poo'\n") redirect_test_io do @pid = fork { exec 'unicorn_rails', "-l#@addr:#@port", "-c", tmp.path } diff --git a/test/unit/test_http_parser_ng.rb b/test/unit/test_http_parser_ng.rb index 3b9111f..7267ea0 100644 --- a/test/unit/test_http_parser_ng.rb +++ b/test/unit/test_http_parser_ng.rb @@ -172,6 +172,10 @@ class HttpParserNgTest < Test::Unit::TestCase assert_equal '', str assert ! @parser.body_eof? assert_equal "", @parser.filter_body(tmp, "\r\n0\r\n") + assert_equal "", tmp + assert @parser.body_eof? + assert_equal req, @parser.trailers(req, moo = "\r\n") + assert_equal "", moo assert @parser.body_eof? assert ! @parser.keepalive? end diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb index ee81a87..a127882 100644 --- a/test/unit/test_tee_input.rb +++ b/test/unit/test_tee_input.rb @@ -160,7 +160,7 @@ class TestTeeInput < Test::Unit::TestCase pid = fork { @rd.close 5.times { @wr.write("5\r\nabcde\r\n") } - @wr.write("0\r\n") + @wr.write("0\r\n\r\n") } @wr.close ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) @@ -199,7 +199,7 @@ class TestTeeInput < Test::Unit::TestCase rd.read(1) == "." and @wr.write("#{'%x' % [ chunk.size]}\r\n#{chunk}\r\n") end - @wr.write("0\r\n") + @wr.write("0\r\n\r\n") } ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) assert_nil @parser.content_length @@ -213,6 +213,34 @@ class TestTeeInput < Test::Unit::TestCase assert status.success? end + def test_chunked_with_trailer + @parser = Unicorn::HttpParser.new + @buf = "POST / HTTP/1.1\r\n" \ + "Host: localhost\r\n" \ + "Trailer: Hello\r\n" \ + "Transfer-Encoding: chunked\r\n" \ + "\r\n" + assert_equal @env, @parser.headers(@env, @buf) + assert_equal "", @buf + + pid = fork { + @rd.close + 5.times { @wr.write("5\r\nabcde\r\n") } + @wr.write("0\r\n") + @wr.write("Hello: World\r\n\r\n") + } + @wr.close + ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + assert_nil @parser.content_length + assert_nil ti.len + assert ! @parser.body_eof? + assert_equal 25, ti.size + assert_equal "World", @env['HTTP_HELLO'] + status = nil + assert_nothing_raised { pid, status = Process.waitpid2(pid) } + assert status.success? + end + private def init_parser(body, size = nil) diff --git a/test/unit/test_util.rb b/test/unit/test_util.rb index 4a1e21f..b267179 100644 --- a/test/unit/test_util.rb +++ b/test/unit/test_util.rb @@ -7,7 +7,7 @@ class TestUtil < Test::Unit::TestCase EXPECT_FLAGS = File::WRONLY | File::APPEND def test_reopen_logs_noop - tmp = Tempfile.new(nil) + tmp = Tempfile.new('') tmp.reopen(tmp.path, 'a') tmp.sync = true ext = tmp.external_encoding rescue nil @@ -21,14 +21,14 @@ class TestUtil < Test::Unit::TestCase end def test_reopen_logs_renamed - tmp = Tempfile.new(nil) + tmp = Tempfile.new('') tmp_path = tmp.path.freeze tmp.reopen(tmp_path, 'a') tmp.sync = true ext = tmp.external_encoding rescue nil int = tmp.internal_encoding rescue nil before = tmp.stat.inspect - to = Tempfile.new(nil) + to = Tempfile.new('') File.rename(tmp_path, to.path) assert ! File.exist?(tmp_path) Unicorn::Util.reopen_logs @@ -45,7 +45,7 @@ class TestUtil < Test::Unit::TestCase end def test_reopen_logs_renamed_with_encoding - tmp = Tempfile.new(nil) + tmp = Tempfile.new('') tmp_path = tmp.path.dup.freeze Encoding.list.each { |encoding| File.open(tmp_path, "a:#{encoding.to_s}") { |fp| @@ -68,7 +68,7 @@ class TestUtil < Test::Unit::TestCase end if STDIN.respond_to?(:external_encoding) def test_reopen_logs_renamed_with_internal_encoding - tmp = Tempfile.new(nil) + tmp = Tempfile.new('') tmp_path = tmp.path.dup.freeze Encoding.list.each { |ext| Encoding.list.each { |int| |