From a42ae467c0d64bba18ca9991e2f141f2c76722cc Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Thu, 23 Nov 2023 09:28:31 +0200 Subject: [PATCH] Client - Renamed `authenticate(string username, string password)` to `authenticate_impl(string username, string password)` - Implemented `authenticate(string username, string password)` (Still a work-in-progress) Client (unitests) - Updated unittest for auth testing - Authenticate before sending a message --- source/dante/client.d | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/source/dante/client.d b/source/dante/client.d index fb5b4f9..05aadb5 100644 --- a/source/dante/client.d +++ b/source/dante/client.d @@ -106,7 +106,7 @@ public class DanteClient return makeRequest(msg); } - public Future authenticate(string username, string password) + public Future authenticate_impl(string username, string password) { import davinci.c2s.auth; import davinci; @@ -121,6 +121,28 @@ public class DanteClient return makeRequest(msg); } + public void authenticate(string username, string password) + { + import davinci.c2s.auth : AuthMessage; + import davinci; + BaseMessage response = cast(BaseMessage)authenticate_impl(username, password).await().getValue().value.object; + + // TODO: For absolute sanity we should check that + // ... it actually decoded to the type we EXPECT + // ... to be here (this would safeguard against + // ... bad server implementations) + // TODO: Make teh below a `mixin template` + Command responseCommand = response.getCommand(); + AuthMessage chanMemResp = cast(AuthMessage)responseCommand; + + if(chanMemResp is null) + { + throw ProtocolException.expectedMessageKind(AuthMessage.classinfo, responseCommand); + } + + // TODO: Check authentication status here + } + public Future enumerateChannels_imp(ulong offset, ubyte limit) { import davinci.c2s.channels : ChannelEnumerateRequest; @@ -385,7 +407,7 @@ unittest DanteClient client = new DanteClient(new UnixAddress("/tmp/renaissance.sock")); client.start(); - Future fut = client.authenticate("deavmi", "testpassword"); + Future fut = client.authenticate_impl("deavmi", "testpassword"); writeln("Awaitinf future..."); Result res = fut.await(); @@ -417,6 +439,17 @@ unittest DanteClient client = new DanteClient(new UnixAddress("/tmp/renaissance.sock")); client.start(); + + try + { + client.authenticate("deavmi", "testpassword"); + } + catch(DanteException e) + { + writeln("Got exception: ", e); + } + + try { writeln("Joining channel #general...");