2019-07-27 09:47:19 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-12 12:16:55 -07:00
|
|
|
require_relative "helper"
|
2020-07-12 20:00:29 +03:00
|
|
|
require_relative "helpers/tmp_path"
|
2011-09-27 10:53:45 -07:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
class TestPumaUnixSocket < Minitest::Test
|
2020-07-12 20:00:29 +03:00
|
|
|
include TmpPath
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
App = lambda { |env| [200, {}, ["Works"]] }
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2021-04-24 18:24:44 -05:00
|
|
|
def teardown
|
|
|
|
return if skipped?
|
|
|
|
@server.stop(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_unix(type)
|
|
|
|
@tmp_socket_path = type == :unix ? tmp_path('.sock') : "@TestPumaUnixSocket"
|
2018-08-21 20:08:06 -05:00
|
|
|
@server = Puma::Server.new App
|
2020-07-12 20:00:29 +03:00
|
|
|
@server.add_unix_listener @tmp_socket_path
|
2018-08-21 20:08:06 -05:00
|
|
|
@server.run
|
|
|
|
end
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2021-04-24 18:24:44 -05:00
|
|
|
def test_server_unix
|
2021-03-15 09:10:43 -05:00
|
|
|
skip_unless :unix
|
2021-04-24 18:24:44 -05:00
|
|
|
server_unix :unix
|
2020-07-12 20:00:29 +03:00
|
|
|
sock = UNIXSocket.new @tmp_socket_path
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
assert_equal expected, sock.read(expected.size)
|
2011-09-27 10:53:45 -07:00
|
|
|
end
|
2021-04-24 18:24:44 -05:00
|
|
|
|
|
|
|
def test_server_aunix
|
|
|
|
skip_unless :aunix
|
|
|
|
server_unix :aunix
|
|
|
|
sock = UNIXSocket.new @tmp_socket_path.sub(/\A@/, "\0")
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
assert_equal expected, sock.read(expected.size)
|
|
|
|
end
|
2012-01-08 16:55:57 -03:00
|
|
|
end
|