mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Adjust test files for 'no ssl' compile
This commit is contained in:
parent
b1c760a122
commit
f291c63825
6 changed files with 63 additions and 44 deletions
|
@ -1,16 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative "helper"
|
||||
require_relative "helpers/ssl"
|
||||
require_relative "helpers/ssl" if ::Puma::HAS_SSL
|
||||
require_relative "helpers/tmp_path"
|
||||
|
||||
require "puma/binder"
|
||||
require "puma/puma_http11"
|
||||
require "puma/events"
|
||||
require "puma/configuration"
|
||||
|
||||
class TestBinderBase < Minitest::Test
|
||||
include SSLHelper
|
||||
include SSLHelper if ::Puma::HAS_SSL
|
||||
include TmpPath
|
||||
|
||||
def setup
|
||||
|
@ -58,12 +57,14 @@ class TestBinder < TestBinderBase
|
|||
end
|
||||
|
||||
def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://localhost:0?#{ssl_query}"], @events
|
||||
|
||||
assert_empty @binder.listeners
|
||||
end
|
||||
|
||||
def test_home_alters_listeners_for_ssl_addresses
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
port = UniquePort.call
|
||||
@binder.parse ["ssl://127.0.0.1:#{port}?#{ssl_query}"], @events
|
||||
|
||||
|
@ -81,7 +82,9 @@ class TestBinder < TestBinderBase
|
|||
end
|
||||
|
||||
def test_correct_zero_port_ssl
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
skip("Implement later")
|
||||
|
||||
ssl_regex = %r!ssl://127.0.0.1:(\d+)!
|
||||
|
||||
@binder.parse ["ssl://localhost:0?#{ssl_query}"], @events
|
||||
|
@ -101,7 +104,9 @@ class TestBinder < TestBinderBase
|
|||
end
|
||||
|
||||
def test_logs_all_localhost_bindings_ssl
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
skip("Incorrectly logs localhost, not 127.0.0.1")
|
||||
|
||||
@binder.parse ["ssl://localhost:0?#{ssl_query}"], @events
|
||||
|
||||
assert_match %r!ssl://127.0.0.1:(\d+)!, @events.stdout.string
|
||||
|
@ -145,18 +150,21 @@ class TestBinder < TestBinderBase
|
|||
end
|
||||
|
||||
def test_binder_parses_tlsv1_disabled
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://0.0.0.0:0?#{ssl_query}&no_tlsv1=true"], @events
|
||||
|
||||
assert ssl_context_for_binder.no_tlsv1
|
||||
end
|
||||
|
||||
def test_binder_parses_tlsv1_enabled
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://0.0.0.0:0?#{ssl_query}&no_tlsv1=false"], @events
|
||||
|
||||
refute ssl_context_for_binder.no_tlsv1
|
||||
end
|
||||
|
||||
def test_binder_parses_tlsv1_tlsv1_1_unspecified_defaults_to_enabled
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://0.0.0.0:0?#{ssl_query}"], @events
|
||||
|
||||
refute ssl_context_for_binder.no_tlsv1
|
||||
|
@ -164,18 +172,21 @@ class TestBinder < TestBinderBase
|
|||
end
|
||||
|
||||
def test_binder_parses_tlsv1_1_disabled
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://0.0.0.0:0?#{ssl_query}&no_tlsv1_1=true"], @events
|
||||
|
||||
assert ssl_context_for_binder.no_tlsv1_1
|
||||
end
|
||||
|
||||
def test_binder_parses_tlsv1_1_enabled
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://0.0.0.0:0?#{ssl_query}&no_tlsv1_1=false"], @events
|
||||
|
||||
refute ssl_context_for_binder.no_tlsv1_1
|
||||
end
|
||||
|
||||
def test_env_contains_protoenv
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://localhost:0?#{ssl_query}"], @events
|
||||
|
||||
env_hash = @binder.envs[@binder.ios.first]
|
||||
|
@ -186,6 +197,7 @@ class TestBinder < TestBinderBase
|
|||
end
|
||||
|
||||
def test_env_contains_stderr
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
@binder.parse ["ssl://localhost:0?#{ssl_query}"], @events
|
||||
|
||||
env_hash = @binder.envs[@binder.ios.first]
|
||||
|
@ -346,6 +358,7 @@ class TestBinder < TestBinderBase
|
|||
|
||||
def assert_parsing_logs_uri(order = [:unix, :tcp])
|
||||
skip UNIX_SKT_MSG if order.include?(:unix) && !UNIX_SKT_EXIST
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
|
||||
unix_path = tmp_path('.sock')
|
||||
prepared_paths = {
|
||||
|
@ -373,6 +386,8 @@ end
|
|||
|
||||
class TestBinderJRuby < TestBinderBase
|
||||
def test_binder_parses_jruby_ssl_options
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
|
||||
keystore = File.expand_path "../../examples/puma/keystore.jks", __FILE__
|
||||
ssl_cipher_list = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
||||
|
||||
|
@ -385,6 +400,8 @@ end if ::Puma::IS_JRUBY
|
|||
|
||||
class TestBinderMRI < TestBinderBase
|
||||
def test_binder_parses_ssl_cipher_filter
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
|
||||
ssl_cipher_filter = "AES@STRENGTH"
|
||||
|
||||
@binder.parse ["ssl://0.0.0.0?#{ssl_query}&ssl_cipher_filter=#{ssl_cipher_filter}"], @events
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require_relative "helper"
|
||||
require_relative "helpers/ssl"
|
||||
require_relative "helpers/ssl" if ::Puma::HAS_SSL
|
||||
require_relative "helpers/tmp_path"
|
||||
|
||||
require "puma/cli"
|
||||
require "json"
|
||||
|
||||
class TestCLI < Minitest::Test
|
||||
include SSLHelper
|
||||
include SSLHelper if ::Puma::HAS_SSL
|
||||
include TmpPath
|
||||
|
||||
def setup
|
||||
|
@ -67,6 +67,8 @@ class TestCLI < Minitest::Test
|
|||
end
|
||||
|
||||
def test_control_for_ssl
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
|
||||
require "net/http"
|
||||
control_port = UniquePort.call
|
||||
control_host = "127.0.0.1"
|
||||
|
|
|
@ -44,6 +44,7 @@ class TestConfigFile < TestConfigFileBase
|
|||
end
|
||||
|
||||
def test_ssl_configuration_from_DSL
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
conf = Puma::Configuration.new do |config|
|
||||
config.load "test/config/ssl_config.rb"
|
||||
end
|
||||
|
@ -61,6 +62,7 @@ class TestConfigFile < TestConfigFileBase
|
|||
|
||||
def test_ssl_bind
|
||||
skip_on :jruby
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
|
||||
conf = Puma::Configuration.new do |c|
|
||||
c.ssl_bind "0.0.0.0", "9292", {
|
||||
|
@ -78,6 +80,7 @@ class TestConfigFile < TestConfigFileBase
|
|||
|
||||
def test_ssl_bind_with_cipher_filter
|
||||
skip_on :jruby
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
|
||||
cipher_filter = "!aNULL:AES+SHA"
|
||||
conf = Puma::Configuration.new do |c|
|
||||
|
@ -95,6 +98,7 @@ class TestConfigFile < TestConfigFileBase
|
|||
end
|
||||
|
||||
def test_ssl_bind_with_ca
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
conf = Puma::Configuration.new do |c|
|
||||
c.ssl_bind "0.0.0.0", "9292", {
|
||||
cert: "/path/to/cert",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require_relative "helper"
|
||||
|
||||
require "puma/minissl"
|
||||
require "puma/minissl" if ::Puma::HAS_SSL
|
||||
|
||||
class TestMiniSSL < Minitest::Test
|
||||
|
||||
|
@ -26,4 +26,4 @@ class TestMiniSSL < Minitest::Test
|
|||
assert_equal("No such cert file '/no/such/cert'", exception.message)
|
||||
end
|
||||
end
|
||||
end
|
||||
end if ::Puma::HAS_SSL
|
||||
|
|
|
@ -1,45 +1,39 @@
|
|||
# Nothing in this file runs if Puma isn't compiled with ssl support
|
||||
#
|
||||
# helper is required first since it loads Puma, which needs to be
|
||||
# loaded so HAS_SSL is defined
|
||||
require_relative "helper"
|
||||
require "puma/minissl"
|
||||
require "puma/puma_http11"
|
||||
require "puma/events"
|
||||
require "net/http"
|
||||
|
||||
#———————————————————————————————————————————————————————————————————————————————
|
||||
# NOTE: ALL TESTS BYPASSED IF DISABLE_SSL IS TRUE
|
||||
#———————————————————————————————————————————————————————————————————————————————
|
||||
if ::Puma::HAS_SSL
|
||||
require "puma/minissl"
|
||||
require "puma/events"
|
||||
require "net/http"
|
||||
|
||||
class SSLEventsHelper < ::Puma::Events
|
||||
attr_accessor :addr, :cert, :error
|
||||
class SSLEventsHelper < ::Puma::Events
|
||||
attr_accessor :addr, :cert, :error
|
||||
|
||||
def ssl_error(error, peeraddr, peercert)
|
||||
self.error = error
|
||||
self.addr = peeraddr
|
||||
self.cert = peercert
|
||||
def ssl_error(error, peeraddr, peercert)
|
||||
self.error = error
|
||||
self.addr = peeraddr
|
||||
self.cert = peercert
|
||||
end
|
||||
end
|
||||
|
||||
# net/http (loaded in helper) does not necessarily load OpenSSL
|
||||
require "openssl" unless Object.const_defined? :OpenSSL
|
||||
if Puma::IS_JRUBY
|
||||
puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
|
||||
" OpenSSL",
|
||||
"OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}",
|
||||
" OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}", ""
|
||||
else
|
||||
puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
|
||||
" Puma::MiniSSL OpenSSL",
|
||||
"OPENSSL_LIBRARY_VERSION: #{Puma::MiniSSL::OPENSSL_LIBRARY_VERSION.ljust 32}#{OpenSSL::OPENSSL_LIBRARY_VERSION}",
|
||||
" OPENSSL_VERSION: #{Puma::MiniSSL::OPENSSL_VERSION.ljust 32}#{OpenSSL::OPENSSL_VERSION}", ""
|
||||
end
|
||||
end
|
||||
|
||||
DISABLE_SSL = begin
|
||||
Puma::Server.class
|
||||
Puma::MiniSSL.check
|
||||
# net/http (loaded in helper) does not necessarily load OpenSSL
|
||||
require "openssl" unless Object.const_defined? :OpenSSL
|
||||
if Puma::IS_JRUBY
|
||||
puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
|
||||
" OpenSSL",
|
||||
"OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}",
|
||||
" OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}", ""
|
||||
else
|
||||
puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
|
||||
" Puma::MiniSSL OpenSSL",
|
||||
"OPENSSL_LIBRARY_VERSION: #{Puma::MiniSSL::OPENSSL_LIBRARY_VERSION.ljust 32}#{OpenSSL::OPENSSL_LIBRARY_VERSION}",
|
||||
" OPENSSL_VERSION: #{Puma::MiniSSL::OPENSSL_VERSION.ljust 32}#{OpenSSL::OPENSSL_VERSION}", ""
|
||||
end
|
||||
rescue
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
class TestPumaServerSSL < Minitest::Test
|
||||
parallelize_me!
|
||||
def setup
|
||||
|
@ -247,7 +241,7 @@ class TestPumaServerSSL < Minitest::Test
|
|||
|
||||
assert busy_threads.zero?, "Our connection is wasn't dropped"
|
||||
end
|
||||
end unless DISABLE_SSL
|
||||
end if ::Puma::HAS_SSL
|
||||
|
||||
# client-side TLS authentication tests
|
||||
class TestPumaServerSSLClient < Minitest::Test
|
||||
|
@ -345,4 +339,4 @@ class TestPumaServerSSLClient < Minitest::Test
|
|||
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
||||
end
|
||||
end
|
||||
end unless DISABLE_SSL
|
||||
end if ::Puma::HAS_SSL
|
||||
|
|
|
@ -150,6 +150,8 @@ class TestPumaControlCli < TestConfigFileBase
|
|||
end
|
||||
|
||||
def test_control_ssl
|
||||
skip 'No ssl support' unless ::Puma::HAS_SSL
|
||||
|
||||
host = "127.0.0.1"
|
||||
port = UniquePort.call
|
||||
url = "ssl://#{host}:#{port}?#{ssl_query}"
|
||||
|
|
Loading…
Add table
Reference in a new issue