Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,18 +800,10 @@ def initialize s
def handshake port, path
key = SecureRandom.hex(11)
@sock.print "GET #{path} HTTP/1.1\r\nHost: 127.0.0.1:#{port}\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: #{key}==\r\n\r\n"
res = nil
loop do
res = @sock.readpartial 4092
break unless res.match?(/out|input/)
end
server_key = get_server_key

if res.match(/^Sec-WebSocket-Accept: (.*)\r\n/)
correct_key = Base64.strict_encode64 Digest::SHA1.digest "#{key}==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
raise "The Sec-WebSocket-Accept value: #{$1} is not valid" unless $1 == correct_key
else
raise "Unknown response: #{res}"
end
correct_key = Base64.strict_encode64 Digest::SHA1.digest "#{key}==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
raise "The Sec-WebSocket-Accept value: #{$1} is not valid" unless server_key == correct_key
end

def send msg
Expand Down Expand Up @@ -882,6 +874,19 @@ def send_close_connection
def close
@sock.close
end

private

def get_server_key
Timeout.timeout(ProtocolTestCase::TIMEOUT_SEC) do
loop do
res = @sock.readpartial 4092
if res.match(/^Sec-WebSocket-Accept: (.*)\r\n/)
return $1
end
end
end
end
end

# When constant variables are referred from modules, they have to be defined outside the class.
Expand Down