diff --git a/Formula/launch_socket_server.rb b/Formula/launch_socket_server.rb new file mode 100644 index 0000000000..fd94ad6825 --- /dev/null +++ b/Formula/launch_socket_server.rb @@ -0,0 +1,85 @@ +class LaunchSocketServer < Formula + desc "Bind to privileged ports without running a server as root" + homepage "https://github.com/sstephenson/launch_socket_server" + url "https://github.com/sstephenson/launch_socket_server/archive/v1.0.0.tar.gz" + sha256 "77b7eebf54a1f0e0ce250b3cf3fa19eb6bee6cb6d70989a9b6cd5b6a95695608" + + head "https://github.com/sstephenson/launch_socket_server.git" + + depends_on "go" => :build + + def install + system "make" + + sbin.install "sbin/launch_socket_server" + (libexec/"launch_socket_server").install "libexec/launch_socket_server/login_wrapper" + end + + test do + launch_port = 9272 + echo_port = 6752 + + (testpath/"launch_socket_server.plist").write <<-EOS.undent + + + + + Label + homebrew.mxcl.launch_socket_server_test + RunAtLoad + + KeepAlive + + ProgramArguments + + #{sbin/"launch_socket_server"} + /usr/bin/ruby + #{testpath/"echo_server.rb"} + + Sockets + + Socket + + SockNodeName + 127.0.0.1 + SockServiceName + #{launch_port} + + + EnvironmentVariables + + LAUNCH_PROGRAM_TCP_ADDRESS + 127.0.0.1:#{echo_port} + + StandardErrorPath + #{testpath/"launch_socket_server.log"} + StandardOutPath + #{testpath/"launch_socket_server.log"} + + + EOS + + (testpath/"echo_server.rb").write <<-EOS.undent + require "socket" + + server = TCPServer.new("127.0.0.1", "#{echo_port}") + socket = server.accept + socket.puts socket.readline + EOS + + system "launchctl", "load", testpath/"launch_socket_server.plist" + + sleep 1 + + begin + socket = TCPSocket.new "127.0.0.1", launch_port + socket.puts "hello, world" + output = socket.gets.strip + socket.close + ensure + system "launchctl", "unload", testpath/"launch_socket_server.plist" + end + + assert_equal "hello, world", output + end +end