yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
b4e338c057ded87ff86e835f90637b515740554a blob 1918 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
# Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
# License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# frozen_string_literal: true
require_relative 'server_helper'

class TestUnixSocket < Testcase
  ENV["N"].to_i > 1 and parallelize_me!
  include ServerHelper
  alias setup server_helper_setup
  alias teardown server_helper_teardown

  def unix_socket(path)
    Timeout.timeout(30) do
      begin
        return UNIXSocket.new(path)
      rescue Errno::ENOENT
        sleep 0.01
        retry
      end
    end
  end

  def test_socket
    tmpdir = yahns_mktmpdir
    err, cfg = @err, Yahns::Config.new
    sock = "#{tmpdir}/sock"
    cfg.instance_eval do
      ru = lambda { |_| [ 200, {'Content-Length'=>'2'}, ['HI'] ] }
      GTL.synchronize { app(:rack, ru) { listen sock } }
      stderr_path err.path
    end
    pid = mkserver(cfg)
    c = unix_socket(sock)
    c.write "GET / HTTP/1.0\r\n\r\n"
    assert_equal c, c.wait(30)
    buf = c.read
    assert_match %r{\AHTTP/1\.1 200 OK\r\n}, buf
    assert_match %r{\r\n\r\nHI\z}, buf
    st = File.stat(sock)
    assert st.world_readable?
    assert st.world_writable?
    c.close
  ensure
    quit_wait(pid)
    FileUtils.rm_rf(tmpdir)
  end

  def test_socket_perms
    tmpdir = yahns_mktmpdir
    err, cfg = @err, Yahns::Config.new
    sock = "#{tmpdir}/sock"
    cfg.instance_eval do
      ru = lambda { |_| [ 200, {'Content-Length'=>'2'}, ['HI'] ] }
      GTL.synchronize { app(:rack, ru) { listen sock, umask: 0077 } }
      stderr_path err.path
    end
    pid = mkserver(cfg)
    c = unix_socket(sock)
    c.write "GET / HTTP/1.0\r\n\r\n"
    assert_equal c, c.wait(30)
    buf = c.read
    assert_match %r{\AHTTP/1\.1 200 OK\r\n}, buf
    assert_match %r{\r\n\r\nHI\z}, buf
    st = File.stat(sock)
    refute st.world_readable?
    refute st.world_writable?
  ensure
    quit_wait(pid)
    FileUtils.rm_rf(tmpdir)
  end
end
debug log:

solving b4e338c ...
found b4e338c in https://yhbt.net/yahns.git

Code repositories for project(s) associated with this inbox:

	../../../yahns.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).