aboutsummaryrefslogtreecommitdiff
path: root/test/native/native_hello.ml
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-26 11:48:00 +0200
committerClombrong <cromblong@egregore.fun>2025-06-26 16:26:14 +0200
commitd3bb6df8d8a728a10dfa6c23328c03824a24f602 (patch)
tree46ad3ef9000adb0a28b12993ac64467d9d88e9e5 /test/native/native_hello.ml
parent9a980f417805ee2c0fd913f7fde6e00e8add0159 (diff)
feat(native_hello): include Flesh testing
Diffstat (limited to 'test/native/native_hello.ml')
-rw-r--r--test/native/native_hello.ml37
1 files changed, 29 insertions, 8 deletions
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)