From 375b167d3e66c459aea06f8678fa89683f04c32e Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 15 Sep 2023 15:09:45 +0400 Subject: [PATCH] core: test group members are assigned different LDNs in group when direct connections aren't created --- src/Simplex/Chat.hs | 4 +- tests/ChatClient.hs | 4 +- tests/ChatTests/Groups.hs | 88 +++++++++++++++++++++++++++++++++++---- 3 files changed, 84 insertions(+), 12 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index d96baba18c..36cf9f3d68 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -3093,7 +3093,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do groupConnReq@(CRInvitationUri _ _) -> case cmdFunction of -- [async agent commands] XGrpMemIntro continuation on receiving INV CFCreateConnGrpMemInv - | isCompatibleRange (fromJVersionRange $ peerChatVRange conn) groupNoDirectVRange -> sendWithDirectCReq -- sendWithoutDirectCReq + | isCompatibleRange (fromJVersionRange $ peerChatVRange conn) groupNoDirectVRange -> sendWithoutDirectCReq -- sendWithDirectCReq -- sendWithoutDirectCReq | otherwise -> sendWithDirectCReq where sendWithoutDirectCReq = do @@ -4349,7 +4349,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do directConnIds <- case memberChatVRange of Nothing -> Just <$> createConn subMode Just mcvr - | isCompatibleRange (fromChatVRange mcvr) groupNoDirectVRange -> Just <$> createConn subMode -- pure Nothing + | isCompatibleRange (fromChatVRange mcvr) groupNoDirectVRange -> pure Nothing -- Just <$> createConn subMode -- pure Nothing | otherwise -> Just <$> createConn subMode let customUserProfileId = if memberIncognito membership then Just (localProfileId $ memberProfile membership) else Nothing void $ withStore $ \db -> createIntroReMember db user gInfo m memInfo groupConnIds directConnIds customUserProfileId subMode diff --git a/tests/ChatClient.hs b/tests/ChatClient.hs index 9e5d4fe1c0..cc257fb8f1 100644 --- a/tests/ChatClient.hs +++ b/tests/ChatClient.hs @@ -258,8 +258,8 @@ getTermLine cc = 5000000 `timeout` atomically (readTQueue $ termQ cc) >>= \case Just s -> do -- remove condition to always echo virtual terminal - when (printOutput cc) $ do - -- when True $ do + -- when (printOutput cc) $ do + when True $ do name <- userName cc putStrLn $ name <> ": " <> s pure s diff --git a/tests/ChatTests/Groups.hs b/tests/ChatTests/Groups.hs index d476285fcd..268611ca1e 100644 --- a/tests/ChatTests/Groups.hs +++ b/tests/ChatTests/Groups.hs @@ -68,19 +68,20 @@ chatGroupTests = do it "should send delivery receipts in group depending on configuration" testConfigureGroupDeliveryReceipts describe "direct connections in group are not established based on chat protocol version" $ do describe "3 members group" $ do - testNoDirect _0 _0 False -- True - testNoDirect _0 _1 False -- True + testNoDirect _0 _0 True -- False -- True + testNoDirect _0 _1 True -- False -- True testNoDirect _1 _0 False testNoDirect _1 _1 False describe "4 members group" $ do - testNoDirect4 _0 _0 _0 False False False -- True True True - testNoDirect4 _0 _0 _1 False False False -- True True True - testNoDirect4 _0 _1 _0 False False False -- True True False - testNoDirect4 _0 _1 _1 False False False -- True True False - testNoDirect4 _1 _0 _0 False False False -- False False True - testNoDirect4 _1 _0 _1 False False False -- False False True + testNoDirect4 _0 _0 _0 True True True -- False False False -- True True True + testNoDirect4 _0 _0 _1 True True True -- False False False -- True True True + testNoDirect4 _0 _1 _0 True True False -- False False False -- True True False + testNoDirect4 _0 _1 _1 True True False -- False False False -- True True False + testNoDirect4 _1 _0 _0 False False True -- False False False -- False False True + testNoDirect4 _1 _0 _1 False False True -- False False False -- False False True testNoDirect4 _1 _1 _0 False False False testNoDirect4 _1 _1 _1 False False False + it "members have different local display names in different groups" testNoDirectDifferentLDNs where _0 = supportedChatVRange -- don't create direct connections _1 = groupCreateDirectVRange @@ -2686,3 +2687,74 @@ testNoGroupDirectConns4Members hostVRange mem2VRange mem3VRange mem4VRange noCon cc1 <## ("no contact " <> name2) cc2 ##> ("@" <> name1 <> " hi") cc2 <## ("no contact " <> name1) + +testNoDirectDifferentLDNs :: HasCallStack => FilePath -> IO () +testNoDirectDifferentLDNs = + testChat3 aliceProfile bobProfile cathProfile $ + \alice bob cath -> do + createGroup3 "team" alice bob cath + + alice ##> "/g club" + alice <## "group #club is created" + alice <## "to add members use /a club or /create link #club" + addMember "club" alice bob GRAdmin + bob ##> "/j club" + concurrently_ + (alice <## "#club: bob joined the group") + (bob <## "#club: you joined the group") + addMember "club" alice cath GRAdmin + cath ##> "/j club" + concurrentlyN_ + [ alice <## "#club: cath joined the group", + do + cath <## "#club: you joined the group" + cath <## "#club: member bob_1 (Bob) is connected", + do + bob <## "#club: alice added cath_1 (Catherine) to the group (connecting...)" + bob <## "#club: new member cath_1 is connected" + ] + + testGroupLDNs alice bob cath "team" "bob" "cath" + testGroupLDNs alice bob cath "club" "bob_1" "cath_1" + + alice `hasContactProfiles` ["alice", "bob", "cath"] + bob `hasContactProfiles` ["bob", "alice", "cath", "cath"] + cath `hasContactProfiles` ["cath", "alice", "bob", "bob"] + where + testGroupLDNs alice bob cath gName bobLDN cathLDN = do + alice ##> ("/ms " <> gName) + alice + <### [ "alice (Alice): owner, you, created group", + "bob (Bob): admin, invited, connected", + "cath (Catherine): admin, invited, connected" + ] + + bob ##> ("/ms " <> gName) + bob + <### [ "alice (Alice): owner, host, connected", + "bob (Bob): admin, you, connected", + ConsoleString (cathLDN <> " (Catherine): admin, connected") + ] + + cath ##> ("/ms " <> gName) + cath + <### [ "alice (Alice): owner, host, connected", + ConsoleString (bobLDN <> " (Bob): admin, connected"), + "cath (Catherine): admin, you, connected" + ] + + alice #> ("#" <> gName <> " hello") + concurrentlyN_ + [ bob <# ("#" <> gName <> " alice> hello"), + cath <# ("#" <> gName <> " alice> hello") + ] + bob #> ("#" <> gName <> " hi there") + concurrentlyN_ + [ alice <# ("#" <> gName <> " bob> hi there"), + cath <# ("#" <> gName <> " " <> bobLDN <> "> hi there") + ] + cath #> ("#" <> gName <> " hey") + concurrentlyN_ + [ alice <# ("#" <> gName <> " cath> hey"), + bob <# ("#" <> gName <> " " <> cathLDN <> "> hey") + ]