diff --git a/test/helper.rb b/test/helper.rb index ff3b6754..6dd6ffb0 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -10,6 +10,8 @@ end begin require "bundler/setup" + # bundler/setup may not load bundler + require "bundler" unless Bundler.const_defined?(:ORIGINAL_ENV) rescue LoadError warn "Failed to load bundler ... this should only happen during package building" end @@ -70,12 +72,31 @@ if ENV['CI'] end module SkipTestsBasedOnRubyEngine - def skip_on_jruby - skip "Skipped on JRuby" if Puma.jruby? + # called with one or more params, like skip_on :jruby, :windows + # 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 - def skip_on_appveyor - skip "Skipped on Appveyor" if ENV["APPVEYOR"] + # called with only one param + 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 diff --git a/test/test_binder.rb b/test/test_binder.rb index 7990085a..944f2a58 100644 --- a/test/test_binder.rb +++ b/test/test_binder.rb @@ -10,7 +10,7 @@ class TestBinder < Minitest::Test end def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses - skip_on_jruby + skip_on :jruby @binder.parse(["tcp://localhost:10001"], @events) @@ -18,8 +18,7 @@ class TestBinder < Minitest::Test end 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__ cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__ @@ -30,8 +29,7 @@ class TestBinder < Minitest::Test end 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__ cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__ @@ -45,7 +43,7 @@ class TestBinder < Minitest::Test end def test_binder_parses_jruby_ssl_options - skip unless Puma.jruby? + skip_unless :jruby 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" diff --git a/test/test_cli.rb b/test/test_cli.rb index c1d3d71b..31a7d445 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -63,8 +63,8 @@ class TestCLI < Minitest::Test t.join end - unless Puma.jruby? || Puma.windows? def test_control_clustered + skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined" url = "unix://#{@tmp_path}" cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}", @@ -102,6 +102,7 @@ class TestCLI < Minitest::Test end def test_control + skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined" url = "unix://#{@tmp_path}" cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}", @@ -125,6 +126,7 @@ class TestCLI < Minitest::Test end def test_control_stop + skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined" url = "unix://#{@tmp_path}" cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}", @@ -147,6 +149,7 @@ class TestCLI < Minitest::Test end def test_control_gc_stats + skip_on :jruby, :windows, suffix: " - Puma::Binder::UNIXServer is not defined" url = "unix://#{@tmp_path}" cli = Puma::CLI.new ["-b", "unix://#{@tmp_path2}", @@ -201,6 +204,7 @@ class TestCLI < Minitest::Test end def test_tmp_control + skip_on :jruby url = "tcp://127.0.0.1:8232" cli = Puma::CLI.new ["--state", @tmp_path, "--control", "auto"] cli.launcher.write_state @@ -217,6 +221,7 @@ class TestCLI < Minitest::Test end 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", "--state", @tmp_path ] cli.launcher.write_state @@ -227,8 +232,6 @@ class TestCLI < Minitest::Test assert_empty keys_not_stripped end - end # JRUBY or Windows - def test_state url = "tcp://127.0.0.1:8232" cli = Puma::CLI.new ["--state", @tmp_path, "--control", url] diff --git a/test/test_integration.rb b/test/test_integration.rb index 49cc99a4..3d057997 100644 --- a/test/test_integration.rb +++ b/test/test_integration.rb @@ -67,7 +67,7 @@ class TestIntegration < Minitest::Test end def restart_server_and_listen(argv) - skip_on_appveyor + skip_on :windows server(argv) s = connect initial_reply = read_body(s) @@ -115,7 +115,7 @@ class TestIntegration < Minitest::Test end def test_stop_via_pumactl - skip if Puma.jruby? || Puma.windows? + skip_on :jruby, :windows conf = Puma::Configuration.new do |c| c.quiet @@ -148,7 +148,7 @@ class TestIntegration < Minitest::Test end 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| c.quiet @@ -181,7 +181,7 @@ class TestIntegration < Minitest::Test until done @events.stdout.rewind 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(/- Worker \d \(pid: \d+\) booted, phase: 1/, log) done = true @@ -195,7 +195,7 @@ class TestIntegration < Minitest::Test end 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 # do not want to accidently kill a valid other process @@ -220,7 +220,7 @@ class TestIntegration < Minitest::Test end 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") assert_equal "Hello World", new_reply end @@ -229,7 +229,7 @@ class TestIntegration < Minitest::Test def test_restart_restores_environment # jruby has a bug where setting `nil` into the ENV or `delete` do not change the # next workers ENV - skip_on_jruby + skip_on :jruby initial_reply, new_reply = restart_server_and_listen("-q test/rackup/hello-env.ru") @@ -239,7 +239,7 @@ class TestIntegration < Minitest::Test end 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") _, status = stop_forked_server(pid) @@ -248,7 +248,7 @@ class TestIntegration < Minitest::Test end 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") _, status = stop_forked_server(pid) diff --git a/test/test_puma_server_ssl.rb b/test/test_puma_server_ssl.rb index d479203f..7ffecc36 100644 --- a/test/test_puma_server_ssl.rb +++ b/test/test_puma_server_ssl.rb @@ -1,4 +1,10 @@ require_relative "helper" +require "puma/minissl" +require "puma/puma_http11" + +#——————————————————————————————————————————————————————————————————————————————— +# NOTE: ALL TESTS BYPASSED IF DISABLE_SSL IS TRUE +#——————————————————————————————————————————————————————————————————————————————— class SSLEventsHelper < ::Puma::Events attr_accessor :addr, :cert, :error @@ -11,7 +17,11 @@ class SSLEventsHelper < ::Puma::Events end DISABLE_SSL = begin + Puma::Server.class Puma::MiniSSL.check + puts "", RUBY_REVISION + puts "Puma::MiniSSL OPENSSL_LIBRARY_VERSION: #{Puma::MiniSSL::OPENSSL_LIBRARY_VERSION}", + " OPENSSL_VERSION: #{Puma::MiniSSL::OPENSSL_VERSION}", "" rescue true else @@ -102,7 +112,7 @@ class TestPumaServerSSL < Minitest::Test end def test_ssl_v3_rejection - @http.ssl_version='SSLv3' + @http.ssl_version= :SSLv3 assert_raises(OpenSSL::SSL::SSLError) do @http.start do Net::HTTP::Get.new '/' @@ -113,7 +123,7 @@ class TestPumaServerSSL < Minitest::Test end end -end +end unless DISABLE_SSL # client-side TLS authentication tests class TestPumaServerSSLClient < Minitest::Test @@ -144,7 +154,7 @@ class TestPumaServerSSLClient < Minitest::Test http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE - blk.call(http) + yield http client_error = false begin @@ -152,7 +162,7 @@ class TestPumaServerSSLClient < Minitest::Test req = Net::HTTP::Get.new "/", {} http.request(req) end - rescue OpenSSL::SSL::SSLError + rescue OpenSSL::SSL::SSLError, EOFError client_error = true end @@ -165,7 +175,7 @@ class TestPumaServerSSLClient < Minitest::Test assert_equal host, events.addr if error assert_equal subject, events.cert.subject.to_s if subject end - + ensure server.stop(true) end @@ -211,4 +221,4 @@ class TestPumaServerSSLClient < Minitest::Test http.verify_mode = OpenSSL::SSL::VERIFY_PEER end end -end +end unless DISABLE_SSL diff --git a/test/test_rack_handler.rb b/test/test_rack_handler.rb index 767d1b50..e44517ee 100644 --- a/test/test_rack_handler.rb +++ b/test/test_rack_handler.rb @@ -48,7 +48,7 @@ class TestPathHandler < Minitest::Test def test_handler_boots - skip_on_appveyor + skip_on :windows in_handler(app) do |launcher| hit(["http://0.0.0.0:#{ launcher.connected_port }/test"]) assert_equal("/test", @input["PATH_INFO"]) diff --git a/test/test_unix_socket.rb b/test/test_unix_socket.rb index fd2e2289..6e6b993c 100644 --- a/test/test_unix_socket.rb +++ b/test/test_unix_socket.rb @@ -1,35 +1,33 @@ require_relative "helper" -# UNIX sockets are not recommended on JRuby -# (or Windows) -unless Puma.jruby? || Puma.windows? - class TestPumaUnixSocket < Minitest::Test +class TestPumaUnixSocket < Minitest::Test - App = lambda { |env| [200, {}, ["Works"]] } + App = lambda { |env| [200, {}, ["Works"]] } - Path = "test/puma.sock" + Path = "test/puma.sock" - def setup - @server = Puma::Server.new App - @server.add_unix_listener Path - @server.run - end + def setup + # UNIX sockets are not recommended on JRuby or Windows + skip_on :jruby, :windows, suffix: " - UNIX sockets are not recommended" + @server = Puma::Server.new App + @server.add_unix_listener Path + @server.run + end - def teardown - @server.stop(true) - File.unlink Path if File.exist? Path - end + def teardown + @server.stop(true) if @server + File.unlink Path if File.exist? Path + end - def test_server - sock = UNIXSocket.new Path + def test_server + 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 - end + sock.close end end