aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/native/dune2
-rw-r--r--test/native/native_hello.ml37
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)