Skip to content

Commit

Permalink
no messages sent to clients who left subconv
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwire committed Feb 20, 2023
1 parent 3c596f0 commit a3858a7
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ tests s =
test s "fail to reset a subconversation with wrong epoch" testDeleteSubConvStale,
test s "leave a subconversation as a creator" (testLeaveSubConv True),
test s "leave a subconversation as a non-creator" (testLeaveSubConv False),
test s "leave a subconversation and skip receiving messages" testLeaveSubConvSkipReceive,
test s "last to leave a subconversation" testLastLeaverSubConv,
test s "leave a subconversation as a non-member" testLeaveSubConvNonMember,
test s "remove user from parent conversation" testRemoveUserParent,
Expand Down Expand Up @@ -3054,6 +3055,83 @@ testLeaveSubConv isSubConvCreator = do
find (\(l, _) -> l == leaver) (allLocalsButLeaver xs)
in others

testLeaveSubConvSkipReceive :: TestM ()
testLeaveSubConvSkipReceive = do
[alice, bob] <- createAndConnectUsers [Nothing, Nothing]

runMLSTest $ do
allLocals@[alice1, bob1, bob2] <- traverse createMLSClient [alice, bob, bob]
traverse_ uploadNewKeyPackage [bob1, bob2]
(_, qcnv) <- setupMLSGroup alice1

let subId = SubConvId "conference"
(qsub, _) <- withTempMockFederator' (mockReply ()) $ do
void $ createAddCommit alice1 [bob] >>= sendAndConsumeCommit

qsub <- createSubConv qcnv bob1 subId
void $ createExternalCommit alice1 Nothing qsub >>= sendAndConsumeCommitBundle
void $ createExternalCommit bob2 Nothing qsub >>= sendAndConsumeCommitBundle
pure qsub

let firstLeaver = bob1
-- a member leaves the subconversation
[firstLeaverKP] <-
map snd . filter (\(cid, _) -> cid == firstLeaver)
<$> getClientsFromGroupState
alice1
(cidQualifiedUser firstLeaver)
let others = leaverAndOthers firstLeaver allLocals
mlsBracket (firstLeaver : others) $ \(wsLeaver : wss) -> do
void $
withTempMockFederator' messageSentMock $
leaveCurrentConv firstLeaver qsub

msgs <-
WS.assertMatchN (5 # WS.Second) wss $
wsAssertBackendRemoveProposal
(cidQualifiedUser firstLeaver)
(Conv <$> qcnv)
firstLeaverKP
traverse_ (uncurry consumeMessage1) (zip others msgs)
-- assert the leaver gets no proposal or event
void . liftIO $ WS.assertNoEvent (5 # WS.Second) [wsLeaver]

-- a member commits the pending proposal
void $ createPendingProposalCommit (head others) >>= sendAndConsumeCommitBundle

-- check that only 3 clients are left in the subconv
do
psc <-
liftTest $
responseJsonError
=<< getSubConv (ciUser (head others)) qcnv subId
<!! do
const 200 === statusCode
liftIO $ length (pscMembers psc) @?= 2

-- send an application message
message <- createApplicationMessage (head others) "some text"
mlsBracket (firstLeaver : others) $ \(wsLeaver : wss) -> do
events <- sendAndConsumeMessage message
liftIO $ events @?= []
liftIO $
WS.assertMatchN_ (5 # WS.Second) wss $ \n -> do
wsAssertMLSMessage qsub (cidQualifiedUser . head $ others) (mpMessage message) n
void $ liftIO $ WS.assertNoEvent (5 # WS.Second) [wsLeaver]
where
allLocalsButLeaver :: [a] -> [(a, [a])]
allLocalsButLeaver xs =
( \(l, i) ->
let s = splitAt i xs
in (l, fst s ++ drop 1 (snd s))
)
<$> zip xs [0 ..]
leaverAndOthers :: Eq a => a -> [a] -> [a]
leaverAndOthers leaver xs =
let (Just (_, others)) =
find (\(l, _) -> l == leaver) (allLocalsButLeaver xs)
in others

testLeaveSubConvNonMember :: TestM ()
testLeaveSubConvNonMember = do
[alice, bob] <- createAndConnectUsers [Nothing, Nothing]
Expand Down

0 comments on commit a3858a7

Please sign in to comment.