Skip to content

Commit

Permalink
Binder fixes for 4.2.1 (#2006)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
nateberkopec committed Oct 1, 2019
1 parent e0cf703 commit 47f7c7f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/puma/binder.rb
Expand Up @@ -105,6 +105,7 @@ def parse(binds, logger)
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
Expand Down
32 changes: 29 additions & 3 deletions test/test_binder.rb
Expand Up @@ -66,12 +66,38 @@ def test_correct_zero_port_ssl
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

Expand Down

0 comments on commit 47f7c7f

Please sign in to comment.