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