From 89cf5d13cdfeae9d7d72e1eed911521c1e6cb0a5 Mon Sep 17 00:00:00 2001 From: hustf Date: Sun, 10 Jun 2018 13:58:18 +0200 Subject: [PATCH] Fix browser tests, move to test/optional. Now working fully locally. modified: benchmark/bce.html Add header for IE11 deleted: test/HttpServer.jl code exist elsewhere, delete renamed: test/browsertest.html -> test/optional/browsertest.html renamed: test/browsertest.jl -> test/optional/browsertest.jl renamed: test/browsertest2.html -> test/optional/browsertest2.html renamed: test/favicon.ico -> test/optional/favicon.ico renamed: test/functions_log_test.jl -> test/optional/functions_log_test.jl renamed: test/functions_open_browsers.jl -> test/optional/functions_open_browsers.jl renamed: test/functions_server.jl -> test/optional/functions_server.jl renamed: test/handler_functions_events.jl -> test/optional/handler_functions_events.jl renamed: test/handler_functions_websockets_general_test.jl -> test/optional/handler_functions_websockets_general_test.jl renamed: test/handler_functions_websockets_subprotocol_test.jl -> test/optional/handler_functions_websockets_subprotocol_test.jl renamed: test/phantom.js -> test/optional/phantom.js --- benchmark/bce.html | 2 +- test/HttpServer.jl | 211 ------------------ test/{ => optional}/browsertest.html | 21 +- test/{ => optional}/browsertest.jl | 21 +- test/{ => optional}/browsertest2.html | 15 +- test/{ => optional}/favicon.ico | Bin test/{ => optional}/functions_log_test.jl | 0 .../{ => optional}/functions_open_browsers.jl | 1 + test/{ => optional}/functions_server.jl | 0 .../handler_functions_events.jl | 0 ...ndler_functions_websockets_general_test.jl | 0 ...r_functions_websockets_subprotocol_test.jl | 2 +- test/{ => optional}/phantom.js | 0 13 files changed, 45 insertions(+), 228 deletions(-) delete mode 100644 test/HttpServer.jl rename test/{ => optional}/browsertest.html (91%) rename test/{ => optional}/browsertest.jl (87%) rename test/{ => optional}/browsertest2.html (95%) rename test/{ => optional}/favicon.ico (100%) rename test/{ => optional}/functions_log_test.jl (100%) rename test/{ => optional}/functions_open_browsers.jl (99%) rename test/{ => optional}/functions_server.jl (100%) rename test/{ => optional}/handler_functions_events.jl (100%) rename test/{ => optional}/handler_functions_websockets_general_test.jl (100%) rename test/{ => optional}/handler_functions_websockets_subprotocol_test.jl (98%) rename test/{ => optional}/phantom.js (100%) diff --git a/benchmark/bce.html b/benchmark/bce.html index ff2e031..9c46773 100644 --- a/benchmark/bce.html +++ b/benchmark/bce.html @@ -3,7 +3,7 @@ - + WS text diff --git a/test/HttpServer.jl b/test/HttpServer.jl deleted file mode 100644 index d08060c..0000000 --- a/test/HttpServer.jl +++ /dev/null @@ -1,211 +0,0 @@ -@testset "HttpServer" begin - -using HttpServer -using WebSockets -import WebSockets: generate_websocket_key, - write_fragment, - read_frame, - websocket_handshake - # is_websocket_handshake, - # handle -import HttpCommon: Request, Response - - -@sync yield() # avoid mixing of output with possible deprecation warnings from .juliarc -info("Starting test WebSockets...") -#is_control_frame is one line, checking one bit. -#get_websocket_key grabs a header. -#is_websocket_handshake grabs a header. -#generate_websocket_key makes a call to a library. -info("Test generate_websocket_key") -@test generate_websocket_key("dGhlIHNhbXBsZSBub25jZQ==") == "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=" - -# Test writing - -function xor_payload(maskkey, data) - out = Array{UInt8,1}(length(data)) - for i in 1:length(data) - d = data[i] - d = xor(d , maskkey[mod(i - 1, 4) + 1]) - out[i] = d - end - out -end - -const io = IOBuffer() - -info("Test length less than 126") -for len = [8, 125], op = (rand(UInt8) & 0b1111), fin=[true, false] - - test_str = randstring(len) - write_fragment(io, fin, op, false, Vector{UInt8}(test_str)) - - frame = take!(io) - - @test bits(frame[1]) == (fin ? "1" : "0") * "000" * bits(op)[end-3:end] - @test frame[2] == UInt8(len) - @test String(frame[3:end]) == test_str - - # The new WebSockets can handle both client and server so can handle no masks - # =========================================================================== - # # Check to see if reading message without a mask fails - # in_buf = IOBuffer(String(frame)) - # @test_throws ErrorException read_frame(in_buf) - # close(in_buf) - - # add a mask - maskkey = rand(UInt8, 4) - data = vcat( - frame[1], - frame[2] | 0b1000_0000, - maskkey, - xor_payload(maskkey, frame[3:end]) - ) - frame_back = read_frame(WebSocket(IOBuffer(data),true)) - - @test frame_back.is_last == fin - @test frame_back.rsv1 == false - @test frame_back.rsv2 == false - @test frame_back.rsv3 == false - @test frame_back.opcode == op - @test frame_back.is_masked == true - @test frame_back.payload_len == len - @test all(map(==, frame_back.maskkey, maskkey)) - @test test_str == String(frame_back.data) -end - -info("Test length 126 or more") -for len = 126:129, op = 0b1111, fin=[true, false] - - test_str = randstring(len) - write_fragment(io, fin, op, false, Vector{UInt8}(test_str)) - - frame = take!(io) - - @test bits(frame[1]) == (fin ? "1" : "0") * "000" * bits(op)[end-3:end] - @test frame[2] == 126 - - @test bits(frame[4])*bits(frame[3]) == bits(hton(UInt16(len))) - - # add a mask - maskkey = rand(UInt8, 4) - data = vcat( - frame[1], - frame[2] | 0b1000_0000, - frame[3], - frame[4], - maskkey, - xor_payload(maskkey, frame[5:end]) - ) - frame_back = read_frame(WebSocket(IOBuffer(data),true)) - - @test frame_back.is_last == fin - @test frame_back.rsv1 == false - @test frame_back.rsv2 == false - @test frame_back.rsv3 == false - @test frame_back.opcode == op - @test frame_back.is_masked == true - @test frame_back.payload_len == len - @test all(map(==, frame_back.maskkey, maskkey)) - @test test_str == String(frame_back.data) -end - -# TODO: test for length > typemax(Uint32) - -info("Tests for is_websocket_handshake") -chromeheaders = Dict{String, String}( - "Connection"=>"Upgrade", - "Upgrade"=>"websocket" - ) -chromerequest = HttpCommon.Request( - "GET", - "", - chromeheaders, - "" - ) - -firefoxheaders = Dict{String, String}( - "Connection"=>"keep-alive, Upgrade", - "Upgrade"=>"websocket" - ) - -firefoxrequest= Request( - "GET", - "", - firefoxheaders, - "" - ) - -wshandler = WebSocketHandler((x,y)->nothing);#Dummy wshandler - -for request in [chromerequest, firefoxrequest] - @test HttpServer.is_websocket_handshake(wshandler,request) == true -end - -info("Test of handshake response") -takefirstline(buf) = split(buf |> take! |> String, "\r\n")[1] - -take!(io) -Base.write(io, "test") -@test takefirstline(io) == "test" - -info("Test reject / switch format") -const SWITCH = "HTTP/1.1 101 Switching Protocols " -const REJECT = "HTTP/1.1 400 Bad Request " -Base.write(io, Response(400)) -@test takefirstline(io) == REJECT -Base.write(io, Response(101)) -@test takefirstline(io) == SWITCH - -function handshakeresponse(request) - cli = HttpServer.Client(2, IOBuffer()) - websocket_handshake(request, cli) - takefirstline(cli.sock) -end - -info("Test simple handshakes that are unacceptable") -for request in [chromerequest, firefoxrequest] - @test handshakeresponse(request) == REJECT - push!(request.headers, "Sec-WebSocket-Version" => "13") - @test handshakeresponse(request) == REJECT - push!(request.headers, "Sec-WebSocket-Key" => "mumbojumbobo") - @test handshakeresponse(request) == REJECT - push!(request.headers, "Sec-WebSocket-Version" => "11") - push!(request.headers, "Sec-WebSocket-Key" => "zkG1WqHM8BJdQMXytFqiUw==") - @test handshakeresponse(request) == REJECT -end - -info("Test simple handshakes, acceptable") -for request in [chromerequest, firefoxrequest] - push!(request.headers, "Sec-WebSocket-Version" => "13") - push!(request.headers, "Sec-WebSocket-Key" => "zkG1WqHM8BJdQMXytFqiUw==") - @test handshakeresponse(request) == SWITCH -end - -info("Test unacceptable subprotocol handshake subprotocol") -for request in [chromerequest, firefoxrequest] - push!(request.headers, "Sec-WebSocket-Version" => "13") - push!(request.headers, "Sec-WebSocket-Key" => "zkG1WqHM8BJdQMXytFqiUw==") - push!(request.headers, "Sec-WebSocket-Protocol" => "my.server/json-zmq") - @test handshakeresponse(request) == REJECT -end - -info("add simple subprotocol to acceptable list") -@test true == WebSockets.addsubproto("xml") - -info("add subprotocol with difficult name") -@test true == WebSockets.addsubproto("my.server/json-zmq") - -info("Test handshake subprotocol now acceptable") -for request in [chromerequest, firefoxrequest] - push!(request.headers, "Sec-WebSocket-Version" => "13") - push!(request.headers, "Sec-WebSocket-Key" => "zkG1WqHM8BJdQMXytFqiUw==") - push!(request.headers, "Sec-WebSocket-Protocol" => "xml") - @test handshakeresponse(request) == SWITCH - push!(request.headers, "Sec-WebSocket-Protocol" => "my.server/json-zmq") - @test handshakeresponse(request) == SWITCH -end -close(io) -include("browsertest.jl") - -end \ No newline at end of file diff --git a/test/browsertest.html b/test/optional/browsertest.html similarity index 91% rename from test/browsertest.html rename to test/optional/browsertest.html index 09f82c3..5147232 100644 --- a/test/browsertest.html +++ b/test/optional/browsertest.html @@ -2,8 +2,8 @@ + - WS text @@ -27,12 +27,21 @@