From 1389ea74ad01356d06d7bd18d0a759cb0da8f4f0 Mon Sep 17 00:00:00 2001 From: Clombrong Date: Fri, 13 Jun 2025 09:13:36 +0200 Subject: feat(sasl): replace full jid with node part in SASL auth sasl'ing with the full jid is not compliant (and works with ejabberd only) --- test/js/websockets_hello.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/js/websockets_hello.ml b/test/js/websockets_hello.ml index 6882c5b..d417e62 100644 --- a/test/js/websockets_hello.ml +++ b/test/js/websockets_hello.ml @@ -16,23 +16,29 @@ let rec run t = then next_tick (fun () -> run t) else () -let main (stream, push) jid password = +let main (stream, push) localpart password = let* _stream = Lwt_stream.get stream in let+ _auth = Sasl.send_auth_stanza (stream, push) - jid password + localpart password Sasl.PLAIN in push None; 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 () = run @@ let jid = (Sys.getenv "EXAMPLE_JID") and password = (Sys.getenv "EXAMPLE_PASSWORD") - in let domain = (List.nth (String.split_on_char '@' jid) 1) in + 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) jid password) + (fun () -> main (stream, push) localpart password) (fun exn -> push None; Lwt.fail exn) -- cgit v1.2.3