diff --git a/.github/workflows/autobahn.yml b/.github/workflows/autobahn.yml new file mode 100644 index 0000000..0016f47 --- /dev/null +++ b/.github/workflows/autobahn.yml @@ -0,0 +1,57 @@ +name: Autobahn + +on: + [pull_request, push] + +permissions: read-all + +jobs: + autobahn: + strategy: + fail-fast: false + matrix: + ocaml-compiler: + - "5.1" + allow-prerelease-opam: + - true + opam-repositories: + - |- + default: https://github.com/ocaml/opam-repository.git + # include: + # - os: windows-latest + # ocaml-compiler: ocaml-variants.5.1.0+options,ocaml-option-mingw + # allow-prerelease-opam: false + # opam-repositories: |- + # windows-5.0: https://github.com/dra27/opam-repository.git#windows-5.0 + # sunset: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset + # default: https://github.com/ocaml/opam-repository.git + + runs-on: ubuntu-latest + + steps: + - name: Checkout tree + uses: actions/checkout@v4 + + - name: Set-up OCaml + uses: ocaml/setup-ocaml@v2 + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + allow-prerelease-opam: ${{ matrix.allow-prerelease-opam }} + opam-repositories: ${{ matrix.opam-repositories }} + + - name: install dependencies + run: | + opam pin atacama.0.0.5 git+https://github.com/suri-framework/atacama -y + opam pin trail git+https://github.com/suri-framework/trail -y + + opam install . --deps-only --with-test + + - run: | + eval $(opam env) + dune exec test/autobahn/server.exe + + - name: upload reports + uses: actions/upload-artifact@v4 + with: + name: report.html + path: _build/reports/clients/index.html diff --git a/nomad/adapter.ml b/nomad/adapter.ml index 25d483d..ebfa39d 100644 --- a/nomad/adapter.ml +++ b/nomad/adapter.ml @@ -80,7 +80,7 @@ let has_no_transform (res : Response.t) = let maybe_compress (req : Request.t) buf = if Bytestring.length buf = 0 then (None, None) - else ( + else let accepted_encodings = Http.Header.get req.headers "accept-encoding" |> Option.map (fun enc -> String.split_on_char ',' enc) @@ -92,7 +92,7 @@ let maybe_compress (req : Request.t) buf = if accepts_deflate then (Some (deflate buf), Some "deflate") else if accepts_gzip then (Some (gzip buf), Some "gzip") else if accepts_x_gzip then (Some (gzip buf), Some "x-gzip") - else (Some buf, None)) + else (Some buf, None) let send conn (req : Request.t) (res : Response.t) = if req.version = `HTTP_1_0 && res.status = `Continue then () diff --git a/test/autobahn/dune b/test/autobahn/dune new file mode 100644 index 0000000..408b820 --- /dev/null +++ b/test/autobahn/dune @@ -0,0 +1,4 @@ +(executable + (public_name server) + (name server) + (libraries nomad riot trail)) diff --git a/test/autobahn/run b/test/autobahn/run index 1797538..4b1194b 100755 --- a/test/autobahn/run +++ b/test/autobahn/run @@ -3,8 +3,8 @@ docker run -it --rm \ -v "${PWD}/test/autobahn/fuzzingclient.json:/fuzzingclient.json" \ -v "${PWD}/_build/reports:/reports" \ - -p 2113:2113 \ --name nomad \ + --network="host" \ crossbario/autobahn-testsuite \ wstest --mode fuzzingclient \ - -w ws://host.docker.internal:2112 + -w ws://0.0.0.0:2112 diff --git a/test/autobahn/server.ml b/test/autobahn/server.ml index 3c3a68d..0852cb3 100644 --- a/test/autobahn/server.ml +++ b/test/autobahn/server.ml @@ -4,16 +4,23 @@ module Echo_server = struct type args = unit type state = int - let init conn _args = `continue (conn, 0) + let init (_args : args) : + (state, [> `Unknown_opcode of int ]) Trail.Sock.handle_result = + `ok 1 - let handle_frame frame _conn _state = + let handle_frame frame _conn _state : + (state, [> `Unknown_opcode of int ]) Trail.Sock.handle_result = Logger.info (fun f -> f "handling frame: %a" Trail.Frame.pp frame); - `push [ frame ] + `push ([ frame ], _state) + + (* val handle_message : *) + (* Message.t -> state -> (state, [> `Unknown_opcode of int ]) handle_result *) + let handle_message _message _state : + (state, [> `Unknown_opcode of int ]) Trail.Sock.handle_result = + `ok 2 end module Test : Application.Intf = struct - let name = "test" - let start () = Logger.set_log_level (Some Debug); sleep 0.1; @@ -25,9 +32,52 @@ module Test : Application.Intf = struct conn |> Trail.Conn.upgrade (`websocket (upgrade_opts, handler)) in - let handler = Nomad.trail [ Trail.logger ~level:Debug (); ws_echo ] in + let handler = Nomad.trail [ ws_echo ] in Nomad.start_link ~port:2112 ~handler () end -let () = Riot.start ~apps:[ (module Logger); (module Test) ] () +module Autobahn = struct + let spawn_docker args = + Unix.create_process "docker" args Unix.stdin Unix.stdout Unix.stderr + + let init () = + let cwd = Unix.getcwd () in + + let config_volume = + Filename.concat cwd + "/test/autobahn/fuzzingclient.json:/fuzzingclient.json" + in + let reports_volume = Filename.concat cwd "/_build/reports:/reports" in + let args = + [| + "docker"; + "run"; + "--rm"; + "-v"; + config_volume; + "-v"; + reports_volume; + "--name"; + "nomad"; + "--net=host"; + "crossbario/autobahn-testsuite"; + "wstest"; + "--mode"; + "fuzzingclient"; + "-w"; + "ws://0.0.0.0:2112"; + |] + in + + let _ = spawn_docker args in + + match receive () with _ -> failwith "Should have never received a message" + + let start () = + let pid = spawn init in + Ok pid +end + +let () = + Riot.start ~apps:[ (module Logger); (module Test); (module Autobahn) ] ()