mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
b638dd1948
* Bump minitest version. * Add basic test helper file. * Use minitest for web server tests. * Use Minitest for unix socket tests. * Use Minitest for ThreadPool tests. * Use Minitest for TCP-Rack tests * Use Minitest for TCPLogger tests. * Add missing helper to test helpers. * Use Minitest for Rack server tests. * Use Minitest for Rack handler tests. * Use Minitest for Puma::Server tests. * Use Minitest for Puma::Server with SSL tests. * Use Minitest for persisten connections tests. * Require puma in test_helper file. * Use minitest for Puma::NullIO tests. * Remove unnecessary requires on test files. * Use Minitest for MiniSSL tests. * Use Minitest for IOBuffer tests. * Require bundler/setup in Rakefile. * Use Minitest for HttpParser tests. * Use Minitest for Puma::Configuration tests. * Use Minitest for Puma::CLI tests. * Bump Minitest version for Ruby 2.1 Gemfile. * Use Minitest for integration tests. * Use Minitest for Puma::App::Status tests. * Remove test-unit from Gemfiles. * Add timeout helper to Minitest::Test. * Use Minitest for Puma::Binder tests. * Remove testhelp file. * Add missing require to Puma::Binder tests. * Prefer require instead of require_relative.
88 lines
2 KiB
Ruby
88 lines
2 KiB
Ruby
# Copyright (c) 2011 Evan Phoenix
|
|
# Copyright (c) 2005 Zed A. Shaw
|
|
|
|
require "test_helper"
|
|
|
|
require "puma/server"
|
|
|
|
class TestHandler
|
|
attr_reader :ran_test
|
|
|
|
def call(env)
|
|
@ran_test = true
|
|
|
|
[200, {"Content-Type" => "text/plain"}, ["hello!"]]
|
|
end
|
|
end
|
|
|
|
class WebServerTest < Minitest::Test
|
|
|
|
def setup
|
|
@valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
|
|
|
|
@tester = TestHandler.new
|
|
|
|
@server = Puma::Server.new @tester, Puma::Events.strings
|
|
@server.add_tcp_listener "127.0.0.1", 0
|
|
|
|
@server.run
|
|
end
|
|
|
|
def teardown
|
|
@server.stop(true)
|
|
end
|
|
|
|
def test_simple_server
|
|
hit(["http://127.0.0.1:#{ @server.connected_port }/test"])
|
|
assert @tester.ran_test, "Handler didn't really run"
|
|
end
|
|
|
|
|
|
def do_test(string, chunk, close_after=nil, shutdown_delay=0)
|
|
# Do not use instance variables here, because it needs to be thread safe
|
|
socket = TCPSocket.new("127.0.0.1", @server.connected_port);
|
|
request = StringIO.new(string)
|
|
chunks_out = 0
|
|
|
|
while data = request.read(chunk)
|
|
chunks_out += socket.write(data)
|
|
socket.flush
|
|
sleep 0.2
|
|
if close_after and chunks_out > close_after
|
|
socket.close
|
|
sleep 1
|
|
end
|
|
end
|
|
sleep(shutdown_delay)
|
|
socket.write(" ") # Some platforms only raise the exception on attempted write
|
|
socket.flush
|
|
end
|
|
|
|
def test_trickle_attack
|
|
do_test(@valid_request, 3)
|
|
end
|
|
|
|
def test_close_client
|
|
assert_raises IOError do
|
|
do_test(@valid_request, 10, 20)
|
|
end
|
|
end
|
|
|
|
def test_bad_client
|
|
do_test("GET /test HTTP/BAD", 3)
|
|
end
|
|
|
|
def test_header_is_too_long
|
|
long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n"
|
|
assert_raises Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EINVAL, IOError do
|
|
do_test(long, long.length/2, 10)
|
|
end
|
|
end
|
|
|
|
def test_file_streamed_request
|
|
body = "a" * (Puma::Const::MAX_BODY * 2)
|
|
long = "GET /test HTTP/1.1\r\nContent-length: #{body.length}\r\n\r\n" + body
|
|
do_test(long, (Puma::Const::CHUNK_SIZE * 2) - 400)
|
|
end
|
|
|
|
end
|