inlets 2.0.3
This commit updates the inlets release from 0.6.3 to 2.0.3, the test has been completely reimplemented following the switch to using @ibuildthecloud's rancher/remotedialer and is a more representative test involving a fully e2e scenario. Signed-off-by: John McCabe <john@johnmccabe.net> Closes #40460. Signed-off-by: FX Coudert <fxcoudert@gmail.com>
This commit is contained in:
parent
9e534a1870
commit
c87dace781
1 changed files with 69 additions and 73 deletions
|
@ -2,8 +2,8 @@ class Inlets < Formula
|
||||||
desc "Expose your local endpoints to the Internet"
|
desc "Expose your local endpoints to the Internet"
|
||||||
homepage "https://github.com/alexellis/inlets"
|
homepage "https://github.com/alexellis/inlets"
|
||||||
url "https://github.com/alexellis/inlets.git",
|
url "https://github.com/alexellis/inlets.git",
|
||||||
:tag => "0.6.3",
|
:tag => "2.0.3",
|
||||||
:revision => "01b26ba23791041121e4996609c96cfa4e25bf64"
|
:revision => "fc8ffa2067ae3a7751bc6ad9434c2186502469f7"
|
||||||
|
|
||||||
bottle do
|
bottle do
|
||||||
cellar :any_skip_relocation
|
cellar :any_skip_relocation
|
||||||
|
@ -27,85 +27,66 @@ class Inlets < Formula
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cleanup(name, pid)
|
||||||
|
puts "Tearing down #{name} on PID #{pid}"
|
||||||
|
Process.kill("TERM", pid)
|
||||||
|
Process.wait(pid)
|
||||||
|
end
|
||||||
|
|
||||||
|
MOCK_RESPONSE = "INLETS OK".freeze
|
||||||
|
|
||||||
test do
|
test do
|
||||||
server = TCPServer.new(0)
|
upstream_server = TCPServer.new(0)
|
||||||
port = server.addr[1]
|
upstream_port = upstream_server.addr[1]
|
||||||
server.close
|
remote_server = TCPServer.new(0)
|
||||||
|
remote_port = remote_server.addr[1]
|
||||||
|
upstream_server.close
|
||||||
|
remote_server.close
|
||||||
|
|
||||||
puts "Listening on: #{port}"
|
puts "Starting mock server on: localhost:#{upstream_port}"
|
||||||
|
|
||||||
(testpath/"ws_server.rb").write <<~EOS
|
(testpath/"mock_upstream_server.rb").write <<~EOS
|
||||||
require "socket"
|
require 'socket'
|
||||||
require "digest/sha1"
|
|
||||||
|
|
||||||
server = TCPServer.new("127.0.0.1", #{port})
|
server = TCPServer.new('localhost', #{upstream_port})
|
||||||
websocket_port = server.addr[1]
|
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
socket = server.accept
|
socket = server.accept
|
||||||
puts 'Incoming Request'
|
request = socket.gets
|
||||||
|
STDERR.puts request
|
||||||
|
|
||||||
http_request = ""
|
response = "OK\\n"
|
||||||
while (line = socket.gets) && (line != "\\r\\n")
|
shutdown = false
|
||||||
http_request += line
|
|
||||||
|
if request.include? "inlets-test"
|
||||||
|
response = "#{MOCK_RESPONSE}\\n"
|
||||||
|
shutdown = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if matches = http_request.match(/^Sec-WebSocket-Key: (\\S+)/)
|
socket.print "HTTP/1.1 200 OK\\r\\n" +
|
||||||
websocket_key = matches[1]
|
"Content-Type: text/plain\\r\\n" +
|
||||||
puts "Websocket handshake detected with key: \#\{websocket_key\}"
|
"Content-Length: \#\{response.bytesize\}\\r\\n" +
|
||||||
else
|
"Connection: close\\r\\n"
|
||||||
puts "Ignoring non-websocket connection"
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
response_key = Digest::SHA1.base64digest([websocket_key, "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"].join)
|
socket.print "\\r\\n"
|
||||||
puts "Responding to handshake with key: \#\{response_key\}"
|
socket.print response
|
||||||
|
socket.close
|
||||||
|
|
||||||
response = "HTTP/1.1 101 Switching Protocols\\n" +
|
if shutdown
|
||||||
"Upgrade: websocket\\n" +
|
puts "Exiting test server"
|
||||||
"Connection: Upgrade\\n" +
|
exit 0
|
||||||
"Sec-WebSocket-Accept: \#\{response_key\}\\n" +
|
|
||||||
"\\n"
|
|
||||||
|
|
||||||
socket.write response
|
|
||||||
|
|
||||||
puts 'Handshake completed. Starting to parse the websocket frame.'
|
|
||||||
|
|
||||||
count = 0
|
|
||||||
loop do
|
|
||||||
count += 1
|
|
||||||
first_byte = socket.getbyte
|
|
||||||
fin = first_byte & 0b10000000
|
|
||||||
opcode = first_byte & 0b00001111
|
|
||||||
|
|
||||||
second_byte = socket.getbyte
|
|
||||||
is_masked = second_byte & 0b10000000
|
|
||||||
payload_size = second_byte & 0b01111111
|
|
||||||
|
|
||||||
keys = socket.read(4).bytes
|
|
||||||
|
|
||||||
# Ping Message - see rfc6455
|
|
||||||
if opcode == 9
|
|
||||||
puts 'Received Ping'
|
|
||||||
puts 'Sending Pong'
|
|
||||||
output = [0b10001010, 0, ""]
|
|
||||||
socket.write output.pack("CCA0")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Exit after 2 ping-pongs
|
|
||||||
if count == 2
|
|
||||||
puts 'Exiting websocket server'
|
|
||||||
exit 0
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
pid = fork do
|
mock_upstream_server_pid = fork do
|
||||||
exec "ruby ws_server.rb"
|
exec "ruby mock_upstream_server.rb"
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
require "uri"
|
||||||
|
require "net/http"
|
||||||
|
|
||||||
stable_resource = stable.instance_variable_get(:@resource)
|
stable_resource = stable.instance_variable_get(:@resource)
|
||||||
commit = stable_resource.instance_variable_get(:@specs)[:revision]
|
commit = stable_resource.instance_variable_get(:@specs)[:revision]
|
||||||
|
|
||||||
|
@ -114,19 +95,34 @@ class Inlets < Formula
|
||||||
assert_match /\s#{commit}$/, inlets_version
|
assert_match /\s#{commit}$/, inlets_version
|
||||||
assert_match /\s#{version}$/, inlets_version
|
assert_match /\s#{version}$/, inlets_version
|
||||||
|
|
||||||
# Client websocket ping-pong test
|
# Client/Server e2e test
|
||||||
sleep 3 # wait for server to start
|
# This test involves establishing a client-server inlets tunnel on the
|
||||||
output = shell_output("#{bin}/inlets client -r 127.0.0.1:#{port} -u http://127.0.0.1:8080 -p 1s 2>&1")
|
# remote_port, running a mock server on the upstream_port and then
|
||||||
assert_match %r{\sUpstream: => http://127.0.0.1:8080$}, output
|
# testing that we can hit the mock server upstream_port via the tunnel remote_port
|
||||||
assert_match %r{\sconnecting to ws://127\.0\.0\.1:#{port}/tunnel with ping=1s$}, output
|
puts "Waiting for mock server"
|
||||||
assert_match /\sPing duration: 1.000000s$/, output
|
sleep 3
|
||||||
assert_match /\sConnected to websocket: 127.0.0.1/, output
|
server_pid = fork do
|
||||||
|
puts "Starting inlets server with port #{remote_port}"
|
||||||
|
exec "#{bin}/inlets server --port #{remote_port}"
|
||||||
|
end
|
||||||
|
|
||||||
ping_ping_count = output.scan(/PongHandler\. Extend deadline/).size
|
client_pid = fork do
|
||||||
assert_equal ping_ping_count, 2
|
puts "Starting inlets client with remote localhost:#{remote_port}, upstream localhost:#{upstream_port}"
|
||||||
|
exec "#{bin}/inlets client --remote localhost:#{remote_port} --upstream localhost:#{upstream_port}"
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Waiting for inlets websocket tunnel"
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
uri = URI("http://localhost:#{remote_port}/inlets-test")
|
||||||
|
puts "Querying upstream endpoint via inlets remote: #{uri}"
|
||||||
|
response = Net::HTTP.get_response(uri)
|
||||||
|
assert_match MOCK_RESPONSE, response.body
|
||||||
|
assert_equal response.code, "200"
|
||||||
ensure
|
ensure
|
||||||
Process.kill("TERM", pid)
|
cleanup("Mock Server", mock_upstream_server_pid)
|
||||||
Process.wait(pid)
|
cleanup("Inlets Server", server_pid)
|
||||||
|
cleanup("Inlets Client", client_pid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue