aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-17 20:40:48 +0200
committerClombrong <cromblong@egregore.fun>2025-06-17 20:40:48 +0200
commitd0c1539993c64fa10ee76ebacd02ee054205630e (patch)
treebe6cb15a8e06967982af7eebc7d66edb02cec760 /test
parent824f1c0aa9cc448d054b5b8997036bc3ce78d646 (diff)
feat(sasl): use new auth_config record for authentication
Diffstat (limited to 'test')
-rw-r--r--test/js/websockets_hello.ml26
1 files changed, 11 insertions, 15 deletions
diff --git a/test/js/websockets_hello.ml b/test/js/websockets_hello.ml
index 316ae5e..877e543 100644
--- a/test/js/websockets_hello.ml
+++ b/test/js/websockets_hello.ml
@@ -17,11 +17,9 @@ let rec run t =
then next_tick (fun () -> run t)
else ()
-let main (stream, push) localpart password =
+let main (stream, push) config =
let* _stream = Lwt_stream.get stream
- in let+ _auth = Sasl.send_auth_stanza (stream, push)
- localpart password
- Sasl.PLAIN
+ in 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)
@@ -30,15 +28,13 @@ let main (stream, push) localpart password =
let () =
run @@
- let jid = (Sys.getenv "EXAMPLE_JID")
- and password = (Sys.getenv "EXAMPLE_PASSWORD")
- in
- (* Probably not exactly compliant with https://xmpp.org/extensions/xep-0029.html,
- but it's just for simplicity's sake in the testing. *)
- let domain = (List.nth (String.split_on_char '@' jid) 1)
- and localpart = (List.nth (String.split_on_char '@' jid) 0)
- in
- let* stream, push = Stream.start domain
- in Lwt.catch
- (fun () -> main (stream, push) localpart password >|= (fun () -> push None))
+ let config : Sasl.auth_config = {
+ jid = (Sys.getenv "EXAMPLE_JID");
+ password = (Sys.getenv "EXAMPLE_PASSWORD");
+ preferred_mechanisms = []
+ }
+ 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; Lwt.fail exn)