From 47f7c7fb2df0149705a4dfa06813baecce87afcf Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Tue, 1 Oct 2019 11:33:00 +0200 Subject: [PATCH] Binder fixes for 4.2.1 (#2006) * Adds failing test for #1986. We now have failing tests for both that issue and #1994 * Fix #1986. Fix #1994 * Fixup and reorder test a bit Original test was using localhost + port 0 for ssl, two things which will not be corretly supported in 4.2.1. Instead, test for 127.0.0.1 and a real port with SSL, which we do support correctly today. Also re-use test method for the ssl test. --- lib/puma/binder.rb | 1 + test/test_binder.rb | 32 +++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/puma/binder.rb b/lib/puma/binder.rb index bacd02e5..a5e48c8c 100644 --- a/lib/puma/binder.rb +++ b/lib/puma/binder.rb @@ -105,6 +105,7 @@ module Puma io = add_tcp_listener uri.host, uri.port, opt, bak @ios.each do |i| + next unless TCPServer === i addr = if i.local_address.ipv6? "[#{i.local_address.ip_unpack[0]}]:#{i.local_address.ip_unpack[1]}" else diff --git a/test/test_binder.rb b/test/test_binder.rb index 882a7989..dc45adfb 100644 --- a/test/test_binder.rb +++ b/test/test_binder.rb @@ -66,12 +66,38 @@ class TestBinder < TestBinderBase end end - def test_correct_doublebind - @binder.parse(["ssl://localhost:0?key=#{key}&cert=#{cert}", "tcp://localhost:0"], @events) + def test_allows_both_ssl_and_tcp + assert_parsing_logs_uri [:ssl, :tcp] + end + def test_allows_both_unix_and_tcp + assert_parsing_logs_uri [:unix, :tcp] + end + + def test_allows_both_tcp_and_unix + assert_parsing_logs_uri [:tcp, :unix] + end + + private + + def assert_parsing_logs_uri(order = [:unix, :tcp]) + skip UNIX_SKT_MSG if order.include?(:unix) && !UNIX_SKT_EXIST + + prepared_paths = { + ssl: "ssl://127.0.0.1:#{UniquePort.call}?key=#{key}&cert=#{cert}", + tcp: "tcp://127.0.0.1:#{UniquePort.call}", + unix: "unix://test/#{name}_server.sock" + } + + tested_paths = [prepared_paths[order[0]], prepared_paths[order[1]]] + + @binder.parse(tested_paths, @events) stdout = @events.stdout.string - # Unsure of what to actually assert on here yet + assert stdout.include?(prepared_paths[order[0]]), "\n#{stdout}\n" + assert stdout.include?(prepared_paths[order[1]]), "\n#{stdout}\n" + ensure + @binder.close_unix_paths if order.include?(:unix) && UNIX_SKT_EXIST end end