Skip to content

Commit

Permalink
Test: subconversation creator leaving
Browse files Browse the repository at this point in the history
  • Loading branch information
mdimjasevic committed Feb 15, 2023
1 parent d9d1641 commit 6f80d1e
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ tests s =
test s "reset a subconversation as a member" (testDeleteSubConv True),
test s "reset a subconversation as a non-member" (testDeleteSubConv False),
test s "fail to reset a subconversation with wrong epoch" testDeleteSubConvStale,
test s "leave a subconversation" testLeaveSubConv,
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 as a non-member" testLeaveSubConvNonMember,
test s "delete parent conversation of a subconversation" testDeleteParentOfSubConv
],
Expand Down Expand Up @@ -2901,12 +2902,13 @@ testDeleteRemoteSubConv isAMember = do
Aeson.decode (frBody actualReq)
liftIO $ req @?= Just expectedReq

testLeaveSubConv :: TestM ()
testLeaveSubConv = do
testLeaveSubConv :: Bool -> TestM ()
testLeaveSubConv isSubConvCreator = do
[alice, bob, charlie] <- createAndConnectUsers [Nothing, Nothing, Just "charlie.example.com"]

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

Expand All @@ -2925,12 +2927,18 @@ testLeaveSubConv = do
void $ createExternalCommit charlie1 Nothing qsub >>= sendAndConsumeCommitBundle
pure qsub

let firstLeaver = if isSubConvCreator then bob1 else alice1
-- bob1 (the creator of the subconv) leaves
[bob1KP] <-
map snd . filter (\(cid, _) -> cid == bob1)
<$> getClientsFromGroupState alice1 bob
mlsBracket [bob1, alice1, bob2] $ \(wsBob1 : wss) -> do
(_, reqs) <- withTempMockFederator' messageSentMock $ leaveCurrentConv bob1 qsub
[firstLeaverKP] <-
map snd . filter (\(cid, _) -> cid == firstLeaver)
<$> getClientsFromGroupState
alice1
(cidQualifiedUser firstLeaver)
let others = leaverAndOthers firstLeaver allLocals
mlsBracket (firstLeaver : others) $ \(wsLeaver : wss) -> do
(_, reqs) <-
withTempMockFederator' messageSentMock $
leaveCurrentConv firstLeaver qsub
req <-
assertOne
( toList . Aeson.decode . frBody
Expand All @@ -2943,10 +2951,13 @@ testLeaveSubConv = do

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

-- alice commits the pending proposal
void $ createPendingProposalCommit alice1 >>= sendAndConsumeCommitBundle
Expand Down Expand Up @@ -2985,6 +2996,19 @@ testLeaveSubConv = do
<!! do
const 200 === statusCode
liftIO $ length (pscMembers psc) @?= 2
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
Expand Down

0 comments on commit 6f80d1e

Please sign in to comment.