Skip to content

Commit

Permalink
Merge pull request #162360 from alebcay/trojan-go-webrick-fix
Browse files Browse the repository at this point in the history
trojan-go: use TCPServer instead of WEBrick for test
  • Loading branch information
chenrui333 authored Feb 12, 2024
2 parents a732294 + bacd2e9 commit 25cf2d1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Formula/t/trojan-go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ def caveats
end

test do
require "webrick"

(testpath/"test.crt").write <<~EOS
-----BEGIN CERTIFICATE-----
MIIBuzCCASQCCQDC8CtpZ04+pTANBgkqhkiG9w0BAQsFADAhMQswCQYDVQQGEwJV
Expand Down Expand Up @@ -114,8 +112,17 @@ def caveats
EOS

http_server_port = free_port
http_server = WEBrick::HTTPServer.new Port: http_server_port
Thread.new { http_server.start }
fork do
server = TCPServer.new(http_server_port)
loop do
socket = server.accept
socket.write "HTTP/1.1 200 OK\r\n" \
"Content-Type: text/plain; charset=utf-8\r\n" \
"Content-Length: 0\r\n" \
"\r\n"
socket.close
end
end

trojan_go_server_port = free_port
(testpath/"server.yaml").write <<~EOS
Expand Down Expand Up @@ -149,13 +156,13 @@ def caveats

sleep 3
begin
system "curl", "--socks5", "127.0.0.1:#{trojan_go_client_port}", "github.com"
output = shell_output("curl --socks5 127.0.0.1:#{trojan_go_client_port} example.com")
assert_match "<title>Example Domain</title>", output
ensure
Process.kill 9, server
Process.wait server
Process.kill 9, client
Process.wait client
http_server.shutdown
end
end
end

0 comments on commit 25cf2d1

Please sign in to comment.