puma 2.11.1 → 2.11.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puma might be problematic. Click here for more details.

@@ -1,39 +0,0 @@
1
- require "rbconfig"
2
- require 'test/unit'
3
- require 'puma/server'
4
-
5
- require 'socket'
6
-
7
- # UNIX sockets are not recommended on JRuby
8
- # (or Windows)
9
- unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
10
- class TestPumaUnixSocket < Test::Unit::TestCase
11
-
12
- App = lambda { |env| [200, {}, ["Works"]] }
13
-
14
- Path = "test/puma.sock"
15
-
16
- def setup
17
- @server = Puma::Server.new App
18
- @server.add_unix_listener Path
19
- @server.run
20
- end
21
-
22
- def teardown
23
- @server.stop(true)
24
- File.unlink Path if File.exist? Path
25
- end
26
-
27
- def test_server
28
- sock = UNIXSocket.new Path
29
-
30
- sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
31
-
32
- expected = "HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Length: 5\r\n\r\nWorks"
33
-
34
- assert_equal expected, sock.read(expected.size)
35
-
36
- sock.close
37
- end
38
- end
39
- end
@@ -1,89 +0,0 @@
1
- # Copyright (c) 2011 Evan Phoenix
2
- # Copyright (c) 2005 Zed A. Shaw
3
-
4
- require 'test/testhelp'
5
-
6
- include Puma
7
-
8
- class TestHandler
9
- attr_reader :ran_test
10
-
11
- def call(env)
12
- @ran_test = true
13
-
14
- [200, {"Content-Type" => "text/plain"}, ["hello!"]]
15
- end
16
- end
17
-
18
- class WebServerTest < Test::Unit::TestCase
19
-
20
- def setup
21
- @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
22
-
23
- @tester = TestHandler.new
24
-
25
- @server = Server.new @tester, Events.strings
26
- @server.add_tcp_listener "127.0.0.1", 9998
27
-
28
- @server.run
29
- end
30
-
31
- def teardown
32
- @server.stop(true)
33
- end
34
-
35
- def test_simple_server
36
- hit(['http://127.0.0.1:9998/test'])
37
- assert @tester.ran_test, "Handler didn't really run"
38
- end
39
-
40
-
41
- def do_test(string, chunk, close_after=nil, shutdown_delay=0)
42
- # Do not use instance variables here, because it needs to be thread safe
43
- socket = TCPSocket.new("127.0.0.1", 9998);
44
- request = StringIO.new(string)
45
- chunks_out = 0
46
-
47
- while data = request.read(chunk)
48
- chunks_out += socket.write(data)
49
- socket.flush
50
- sleep 0.2
51
- if close_after and chunks_out > close_after
52
- socket.close
53
- sleep 1
54
- end
55
- end
56
- sleep(shutdown_delay)
57
- socket.write(" ") # Some platforms only raise the exception on attempted write
58
- socket.flush
59
- end
60
-
61
- def test_trickle_attack
62
- do_test(@valid_request, 3)
63
- end
64
-
65
- def test_close_client
66
- assert_raises IOError do
67
- do_test(@valid_request, 10, 20)
68
- end
69
- end
70
-
71
- def test_bad_client
72
- do_test("GET /test HTTP/BAD", 3)
73
- end
74
-
75
- def test_header_is_too_long
76
- long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n"
77
- assert_raises Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EINVAL, IOError do
78
- do_test(long, long.length/2, 10)
79
- end
80
- end
81
-
82
- def test_file_streamed_request
83
- body = "a" * (Puma::Const::MAX_BODY * 2)
84
- long = "GET /test HTTP/1.1\r\nContent-length: #{body.length}\r\n\r\n" + body
85
- do_test(long, (Puma::Const::CHUNK_SIZE * 2) - 400)
86
- end
87
-
88
- end
89
-