diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-26 11:48:00 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-26 16:26:14 +0200 |
commit | d3bb6df8d8a728a10dfa6c23328c03824a24f602 (patch) | |
tree | 46ad3ef9000adb0a28b12993ac64467d9d88e9e5 /test | |
parent | 9a980f417805ee2c0fd913f7fde6e00e8add0159 (diff) |
feat(native_hello): include Flesh testing
Diffstat (limited to 'test')
-rw-r--r-- | test/native/dune | 2 | ||||
-rw-r--r-- | test/native/native_hello.ml | 37 |
2 files changed, 30 insertions, 9 deletions
diff --git a/test/native/dune b/test/native/dune index 895134a..faa247d 100644 --- a/test/native/dune +++ b/test/native/dune @@ -1,3 +1,3 @@ (test (name native_hello) - (libraries portal_tcp markup)) + (libraries portal_tcp markup flesh)) diff --git a/test/native/native_hello.ml b/test/native/native_hello.ml index f2d1546..a5f9323 100644 --- a/test/native/native_hello.ml +++ b/test/native/native_hello.ml @@ -1,12 +1,33 @@ open! Lwt.Syntax -open! Portal +open! Lwt.Infix +open! Flesh + +let main (stream, push) config = + let+ _auth = Sasl.authenticate (stream, push) config + in match _auth with + | Error (NotAuthorized, Some (_, text)) -> print_endline ("Not authorized: " ^ text) + | Error (MalformedRequest, Some (_, text)) -> print_endline ("Malformed request: " ^ text) + | Error _ -> print_endline "Error!" + | Ok _ -> print_endline "Success!" + let () = Lwt_main.run @@ - let jid = Sys.getenv "FLESH_JID" - and _password = Sys.getenv "FLESH_PASSWORD" - in let domain = (List.nth (String.split_on_char '@' jid) 1) - in let* stream, push = connect domain - in Portal.stanza_open domain |> Option.some |> push; - let+ _s = Markup_lwt.next stream - in Portal.stanza_close |> Option.some |> push; + let config : Sasl.auth_config = { + jid = (Sys.getenv "FLESH_JID"); + password = (Sys.getenv "FLESH_PASSWORD"); + preferred_mechanisms = [Stream.PLAIN] + } + in let domain = (List.nth (String.split_on_char '@' config.jid) 1) in + let* stream, push = Stream.start domain in + Lwt.catch + (fun () -> main (stream, push) config >|= (fun () -> push None)) + (fun exn -> + push None; + (* I suspect JavaScript's [wrap_callback] swallows the Exceptions thrown by + OCaml, so... The next best thing is probably printing something. *) + print_endline + (match exn with + | Stream.InvalidStanza stanza -> "Invalid stanza: " ^ stanza + | _ -> "... and so I stumble back to bed."); + Lwt.fail exn) |