mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Update test files
1. Update skip handling 2. Stability changes 3. Add Ruby & OpenSSL version info output 4. Bypassed SSL tests on DISABLE_SSL ?
This commit is contained in:
parent
84c9a5685c
commit
6a7112d51b
7 changed files with 81 additions and 51 deletions
|
@ -10,6 +10,8 @@ end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require "bundler/setup"
|
require "bundler/setup"
|
||||||
|
# bundler/setup may not load bundler
|
||||||
|
require "bundler" unless Bundler.const_defined?(:ORIGINAL_ENV)
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
warn "Failed to load bundler ... this should only happen during package building"
|
warn "Failed to load bundler ... this should only happen during package building"
|
||||||
end
|
end
|
||||||
|
@ -70,12 +72,31 @@ if ENV['CI']
|
||||||
end
|
end
|
||||||
|
|
||||||
module SkipTestsBasedOnRubyEngine
|
module SkipTestsBasedOnRubyEngine
|
||||||
def skip_on_jruby
|
# called with one or more params, like skip_on :jruby, :windows
|
||||||
skip "Skipped on JRuby" if Puma.jruby?
|
# optional suffix kwarg is appended to the skip message
|
||||||
|
# optional suffix bt should generally not used
|
||||||
|
def skip_on(*engs, suffix: '', bt: caller)
|
||||||
|
skip_msg = false
|
||||||
|
engs.each do |eng|
|
||||||
|
skip_msg = case eng
|
||||||
|
when :jruby then "Skipped on JRuby#{suffix}" if Puma.jruby?
|
||||||
|
when :windows then "Skipped on Windows#{suffix}" if Puma.windows?
|
||||||
|
when :appveyor then "Skipped on Appveyor#{suffix}" if ENV["APPVEYOR"]
|
||||||
|
when :ci then "Skipped on ENV['CI']#{suffix}" if ENV["CI"]
|
||||||
|
else false
|
||||||
|
end
|
||||||
|
skip skip_msg, bt if skip_msg
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip_on_appveyor
|
# called with only one param
|
||||||
skip "Skipped on Appveyor" if ENV["APPVEYOR"]
|
def skip_unless(eng, bt: caller)
|
||||||
|
skip_msg = case eng
|
||||||
|
when :jruby then "Skip unless JRuby" unless Puma.jruby?
|
||||||
|
when :windows then "Skip unless Windows" unless Puma.windows?
|
||||||
|
else false
|
||||||
|
end
|
||||||
|
skip skip_msg, bt if skip_msg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class TestBinder < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
|
def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
|
||||||
skip_on_jruby
|
skip_on :jruby
|
||||||
|
|
||||||
@binder.parse(["tcp://localhost:10001"], @events)
|
@binder.parse(["tcp://localhost:10001"], @events)
|
||||||
|
|
||||||
|
@ -18,8 +18,7 @@ class TestBinder < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses
|
def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses
|
||||||
skip_on_appveyor
|
skip_on :jruby
|
||||||
skip_on_jruby
|
|
||||||
|
|
||||||
key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
|
key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
|
||||||
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__
|
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__
|
||||||
|
@ -30,8 +29,7 @@ class TestBinder < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_binder_parses_ssl_cipher_filter
|
def test_binder_parses_ssl_cipher_filter
|
||||||
skip_on_appveyor
|
skip_on :jruby
|
||||||
skip_on_jruby
|
|
||||||
|
|
||||||
key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
|
key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__
|
||||||
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__
|
cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__
|
||||||
|
@ -45,7 +43,7 @@ class TestBinder < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_binder_parses_jruby_ssl_options
|
def test_binder_parses_jruby_ssl_options
|
||||||
skip unless Puma.jruby?
|
skip_unless :jruby
|
||||||
|
|
||||||
keystore = File.expand_path "../../examples/puma/keystore.jks", __FILE__
|
keystore = File.expand_path "../../examples/puma/keystore.jks", __FILE__
|
||||||
ssl_cipher_list = "TLS_DHE_RSA_WITH_DES_CBC_SHA,TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA"
|
ssl_cipher_list = "TLS_DHE_RSA_WITH_DES_CBC_SHA,TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA"
|
||||||
|
|
|
@ -63,8 +63,8 @@ class TestCLI < Minitest::Test
|
||||||
t.join
|
t.join
|
||||||
end
|
end
|
||||||
|
|
||||||
unless Puma.jruby? || Puma.windows?
|
|
||||||
def test_control_clustered
|
def test_control_clustered
|
||||||
|
skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined"
|
||||||
url = "unix://#{@tmp_path}"
|
url = "unix://#{@tmp_path}"
|
||||||
|
|
||||||
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
||||||
|
@ -102,6 +102,7 @@ class TestCLI < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_control
|
def test_control
|
||||||
|
skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined"
|
||||||
url = "unix://#{@tmp_path}"
|
url = "unix://#{@tmp_path}"
|
||||||
|
|
||||||
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
||||||
|
@ -125,6 +126,7 @@ class TestCLI < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_control_stop
|
def test_control_stop
|
||||||
|
skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined"
|
||||||
url = "unix://#{@tmp_path}"
|
url = "unix://#{@tmp_path}"
|
||||||
|
|
||||||
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
||||||
|
@ -147,6 +149,7 @@ class TestCLI < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_control_gc_stats
|
def test_control_gc_stats
|
||||||
|
skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined"
|
||||||
url = "unix://#{@tmp_path}"
|
url = "unix://#{@tmp_path}"
|
||||||
|
|
||||||
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}",
|
||||||
|
@ -201,6 +204,7 @@ class TestCLI < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tmp_control
|
def test_tmp_control
|
||||||
|
skip_on :jruby
|
||||||
url = "tcp://127.0.0.1:8232"
|
url = "tcp://127.0.0.1:8232"
|
||||||
cli = Puma::CLI.new ["--state", @tmp_path, "--control", "auto"]
|
cli = Puma::CLI.new ["--state", @tmp_path, "--control", "auto"]
|
||||||
cli.launcher.write_state
|
cli.launcher.write_state
|
||||||
|
@ -217,6 +221,7 @@ class TestCLI < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_state_file_callback_filtering
|
def test_state_file_callback_filtering
|
||||||
|
skip_on :jruby, :windows, suffix: " - worker mode not supported"
|
||||||
cli = Puma::CLI.new [ "--config", "test/config/state_file_testing_config.rb",
|
cli = Puma::CLI.new [ "--config", "test/config/state_file_testing_config.rb",
|
||||||
"--state", @tmp_path ]
|
"--state", @tmp_path ]
|
||||||
cli.launcher.write_state
|
cli.launcher.write_state
|
||||||
|
@ -227,8 +232,6 @@ class TestCLI < Minitest::Test
|
||||||
assert_empty keys_not_stripped
|
assert_empty keys_not_stripped
|
||||||
end
|
end
|
||||||
|
|
||||||
end # JRUBY or Windows
|
|
||||||
|
|
||||||
def test_state
|
def test_state
|
||||||
url = "tcp://127.0.0.1:8232"
|
url = "tcp://127.0.0.1:8232"
|
||||||
cli = Puma::CLI.new ["--state", @tmp_path, "--control", url]
|
cli = Puma::CLI.new ["--state", @tmp_path, "--control", url]
|
||||||
|
|
|
@ -67,7 +67,7 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def restart_server_and_listen(argv)
|
def restart_server_and_listen(argv)
|
||||||
skip_on_appveyor
|
skip_on :windows
|
||||||
server(argv)
|
server(argv)
|
||||||
s = connect
|
s = connect
|
||||||
initial_reply = read_body(s)
|
initial_reply = read_body(s)
|
||||||
|
@ -115,7 +115,7 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_stop_via_pumactl
|
def test_stop_via_pumactl
|
||||||
skip if Puma.jruby? || Puma.windows?
|
skip_on :jruby, :windows
|
||||||
|
|
||||||
conf = Puma::Configuration.new do |c|
|
conf = Puma::Configuration.new do |c|
|
||||||
c.quiet
|
c.quiet
|
||||||
|
@ -148,7 +148,7 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_phased_restart_via_pumactl
|
def test_phased_restart_via_pumactl
|
||||||
skip if Puma.jruby? || Puma.windows? || ENV['CI']
|
skip_on :jruby, :windows, :ci, suffix: " - UNIX sockets are not recommended"
|
||||||
|
|
||||||
conf = Puma::Configuration.new do |c|
|
conf = Puma::Configuration.new do |c|
|
||||||
c.quiet
|
c.quiet
|
||||||
|
@ -181,7 +181,7 @@ class TestIntegration < Minitest::Test
|
||||||
until done
|
until done
|
||||||
@events.stdout.rewind
|
@events.stdout.rewind
|
||||||
log = @events.stdout.readlines.join("")
|
log = @events.stdout.readlines.join("")
|
||||||
if log.match(/- Worker \d \(pid: \d+\) booted, phase: 1/)
|
if log =~ /- Worker \d \(pid: \d+\) booted, phase: 1/
|
||||||
assert_match(/TERM sent/, log)
|
assert_match(/TERM sent/, log)
|
||||||
assert_match(/- Worker \d \(pid: \d+\) booted, phase: 1/, log)
|
assert_match(/- Worker \d \(pid: \d+\) booted, phase: 1/, log)
|
||||||
done = true
|
done = true
|
||||||
|
@ -195,7 +195,7 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_kill_unknown_via_pumactl
|
def test_kill_unknown_via_pumactl
|
||||||
skip if Puma.jruby? || Puma.windows?
|
skip_on :jruby, :windows
|
||||||
|
|
||||||
# we run ls to get a 'safe' pid to pass off as puma in cli stop
|
# we run ls to get a 'safe' pid to pass off as puma in cli stop
|
||||||
# do not want to accidently kill a valid other process
|
# do not want to accidently kill a valid other process
|
||||||
|
@ -220,7 +220,7 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_restart_closes_keepalive_sockets_workers
|
def test_restart_closes_keepalive_sockets_workers
|
||||||
skip_on_jruby
|
skip_on :jruby
|
||||||
_, new_reply = restart_server_and_listen("-q -w 2 test/rackup/hello.ru")
|
_, new_reply = restart_server_and_listen("-q -w 2 test/rackup/hello.ru")
|
||||||
assert_equal "Hello World", new_reply
|
assert_equal "Hello World", new_reply
|
||||||
end
|
end
|
||||||
|
@ -229,7 +229,7 @@ class TestIntegration < Minitest::Test
|
||||||
def test_restart_restores_environment
|
def test_restart_restores_environment
|
||||||
# jruby has a bug where setting `nil` into the ENV or `delete` do not change the
|
# jruby has a bug where setting `nil` into the ENV or `delete` do not change the
|
||||||
# next workers ENV
|
# next workers ENV
|
||||||
skip_on_jruby
|
skip_on :jruby
|
||||||
|
|
||||||
initial_reply, new_reply = restart_server_and_listen("-q test/rackup/hello-env.ru")
|
initial_reply, new_reply = restart_server_and_listen("-q test/rackup/hello-env.ru")
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_term_signal_exit_code_in_single_mode
|
def test_term_signal_exit_code_in_single_mode
|
||||||
skip if Puma.jruby? || Puma.windows?
|
skip_on :jruby, :windows
|
||||||
|
|
||||||
pid = start_forked_server("test/rackup/hello.ru")
|
pid = start_forked_server("test/rackup/hello.ru")
|
||||||
_, status = stop_forked_server(pid)
|
_, status = stop_forked_server(pid)
|
||||||
|
@ -248,7 +248,7 @@ class TestIntegration < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_term_signal_exit_code_in_clustered_mode
|
def test_term_signal_exit_code_in_clustered_mode
|
||||||
skip if Puma.jruby? || Puma.windows?
|
skip_on :jruby, :windows
|
||||||
|
|
||||||
pid = start_forked_server("-w 2 test/rackup/hello.ru")
|
pid = start_forked_server("-w 2 test/rackup/hello.ru")
|
||||||
_, status = stop_forked_server(pid)
|
_, status = stop_forked_server(pid)
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
require "puma/minissl"
|
||||||
|
require "puma/puma_http11"
|
||||||
|
|
||||||
|
#———————————————————————————————————————————————————————————————————————————————
|
||||||
|
# NOTE: ALL TESTS BYPASSED IF DISABLE_SSL IS TRUE
|
||||||
|
#———————————————————————————————————————————————————————————————————————————————
|
||||||
|
|
||||||
class SSLEventsHelper < ::Puma::Events
|
class SSLEventsHelper < ::Puma::Events
|
||||||
attr_accessor :addr, :cert, :error
|
attr_accessor :addr, :cert, :error
|
||||||
|
@ -11,7 +17,11 @@ class SSLEventsHelper < ::Puma::Events
|
||||||
end
|
end
|
||||||
|
|
||||||
DISABLE_SSL = begin
|
DISABLE_SSL = begin
|
||||||
|
Puma::Server.class
|
||||||
Puma::MiniSSL.check
|
Puma::MiniSSL.check
|
||||||
|
puts "", RUBY_REVISION
|
||||||
|
puts "Puma::MiniSSL OPENSSL_LIBRARY_VERSION: #{Puma::MiniSSL::OPENSSL_LIBRARY_VERSION}",
|
||||||
|
" OPENSSL_VERSION: #{Puma::MiniSSL::OPENSSL_VERSION}", ""
|
||||||
rescue
|
rescue
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
@ -102,7 +112,7 @@ class TestPumaServerSSL < Minitest::Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ssl_v3_rejection
|
def test_ssl_v3_rejection
|
||||||
@http.ssl_version='SSLv3'
|
@http.ssl_version= :SSLv3
|
||||||
assert_raises(OpenSSL::SSL::SSLError) do
|
assert_raises(OpenSSL::SSL::SSLError) do
|
||||||
@http.start do
|
@http.start do
|
||||||
Net::HTTP::Get.new '/'
|
Net::HTTP::Get.new '/'
|
||||||
|
@ -113,7 +123,7 @@ class TestPumaServerSSL < Minitest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end unless DISABLE_SSL
|
||||||
|
|
||||||
# client-side TLS authentication tests
|
# client-side TLS authentication tests
|
||||||
class TestPumaServerSSLClient < Minitest::Test
|
class TestPumaServerSSLClient < Minitest::Test
|
||||||
|
@ -144,7 +154,7 @@ class TestPumaServerSSLClient < Minitest::Test
|
||||||
http.use_ssl = true
|
http.use_ssl = true
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
|
||||||
blk.call(http)
|
yield http
|
||||||
|
|
||||||
client_error = false
|
client_error = false
|
||||||
begin
|
begin
|
||||||
|
@ -152,7 +162,7 @@ class TestPumaServerSSLClient < Minitest::Test
|
||||||
req = Net::HTTP::Get.new "/", {}
|
req = Net::HTTP::Get.new "/", {}
|
||||||
http.request(req)
|
http.request(req)
|
||||||
end
|
end
|
||||||
rescue OpenSSL::SSL::SSLError
|
rescue OpenSSL::SSL::SSLError, EOFError
|
||||||
client_error = true
|
client_error = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -165,7 +175,7 @@ class TestPumaServerSSLClient < Minitest::Test
|
||||||
assert_equal host, events.addr if error
|
assert_equal host, events.addr if error
|
||||||
assert_equal subject, events.cert.subject.to_s if subject
|
assert_equal subject, events.cert.subject.to_s if subject
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
server.stop(true)
|
server.stop(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -211,4 +221,4 @@ class TestPumaServerSSLClient < Minitest::Test
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end unless DISABLE_SSL
|
||||||
|
|
|
@ -48,7 +48,7 @@ class TestPathHandler < Minitest::Test
|
||||||
|
|
||||||
|
|
||||||
def test_handler_boots
|
def test_handler_boots
|
||||||
skip_on_appveyor
|
skip_on :windows
|
||||||
in_handler(app) do |launcher|
|
in_handler(app) do |launcher|
|
||||||
hit(["http://0.0.0.0:#{ launcher.connected_port }/test"])
|
hit(["http://0.0.0.0:#{ launcher.connected_port }/test"])
|
||||||
assert_equal("/test", @input["PATH_INFO"])
|
assert_equal("/test", @input["PATH_INFO"])
|
||||||
|
|
|
@ -1,35 +1,33 @@
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
# UNIX sockets are not recommended on JRuby
|
class TestPumaUnixSocket < Minitest::Test
|
||||||
# (or Windows)
|
|
||||||
unless Puma.jruby? || Puma.windows?
|
|
||||||
class TestPumaUnixSocket < Minitest::Test
|
|
||||||
|
|
||||||
App = lambda { |env| [200, {}, ["Works"]] }
|
App = lambda { |env| [200, {}, ["Works"]] }
|
||||||
|
|
||||||
Path = "test/puma.sock"
|
Path = "test/puma.sock"
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@server = Puma::Server.new App
|
# UNIX sockets are not recommended on JRuby or Windows
|
||||||
@server.add_unix_listener Path
|
skip_on :jruby, :windows, suffix: " - UNIX sockets are not recommended"
|
||||||
@server.run
|
@server = Puma::Server.new App
|
||||||
end
|
@server.add_unix_listener Path
|
||||||
|
@server.run
|
||||||
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@server.stop(true)
|
@server.stop(true) if @server
|
||||||
File.unlink Path if File.exist? Path
|
File.unlink Path if File.exist? Path
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_server
|
def test_server
|
||||||
sock = UNIXSocket.new Path
|
sock = UNIXSocket.new Path
|
||||||
|
|
||||||
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
|
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
|
||||||
|
|
||||||
expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"
|
expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"
|
||||||
|
|
||||||
assert_equal expected, sock.read(expected.size)
|
assert_equal expected, sock.read(expected.size)
|
||||||
|
|
||||||
sock.close
|
sock.close
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue