Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subconversation test #4102

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration/test/MLS/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ consumeMessageWithPredicate p cid mmp ws = do
consumeMessage :: (HasCallStack) => ClientIdentity -> Maybe MessagePackage -> WebSocket -> App Value
consumeMessage = consumeMessageWithPredicate isNewMLSMessageNotif

-- | like 'consumeMessage' but but will not consume a message where the sender is the backend
-- | like 'consumeMessage' but will not consume a message where the sender is the backend
consumeMessageNoExternal :: (HasCallStack) => ClientIdentity -> Maybe MessagePackage -> WebSocket -> App Value
consumeMessageNoExternal cid = consumeMessageWithPredicate isNewMLSMessageNotifButNoProposal cid
where
Expand All @@ -592,7 +592,7 @@ consumeMessageNoExternal cid = consumeMessageWithPredicate isNewMLSMessageNotifB
pure $ sender /= Just backendSender
else pure False

mlsCliConsume :: ClientIdentity -> ByteString -> App ByteString
mlsCliConsume :: (HasCallStack) => ClientIdentity -> ByteString -> App ByteString
mlsCliConsume cid msgData =
mlscli
cid
Expand Down
48 changes: 48 additions & 0 deletions integration/test/Test/MLS/SubConversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,51 @@ testCreatorRemovesUserFromParent = do
assertBool "alice and charlie should have access to the conversation" (resp.status == 200)
mems <- resp.jsonBody %. "members" & asList
mems `shouldMatchSet` ((renameField "id" "user_id" <=< make) `traverse` [alice1, charlie1, charlie2])

testResendingProposals :: (HasCallStack) => App ()
testResendingProposals = do
[alice, bob, charlie] <- createAndConnectUsers [OwnDomain, OwnDomain, OtherDomain]
[alice1, alice2, bob1, bob2, bob3, charlie1] <-
traverse
(createMLSClient def)
[alice, alice, bob, bob, bob, charlie]
traverse_ uploadNewKeyPackage [alice2, bob1, bob2, bob3, charlie1]

(_, conv) <- createNewGroup alice1
void $ createAddCommit alice1 [alice, bob, charlie] >>= sendAndConsumeCommitBundle

createSubConv alice1 "conference"

void $ createExternalCommit alice2 Nothing >>= sendAndConsumeCommitBundle
void $ createExternalCommit bob1 Nothing >>= sendAndConsumeCommitBundle
void $ createExternalCommit bob2 Nothing >>= sendAndConsumeCommitBundle
void $ createExternalCommit bob3 Nothing >>= sendAndConsumeCommitBundle

leaveCurrentConv bob1
leaveCurrentConv bob2
leaveCurrentConv bob3

mls <- getMLSState
withWebSockets (charlie1 : toList mls.members) \wss -> do
void $ createExternalCommit charlie1 Nothing >>= sendAndConsumeCommitBundle

-- consume proposals after backend resends them
for_ wss \ws -> do
replicateM 3 do
msg <- consumeMessage (fromJust ws.client) Nothing ws
msg %. "message.content.sender.External" `shouldMatchInt` 0

void $ createPendingProposalCommit alice1 >>= sendAndConsumeCommitBundle
pcapriotti marked this conversation as resolved.
Show resolved Hide resolved

sub <- getSubConversation alice1 conv "conference" >>= getJSON 200
let members =
map
( \cid ->
object
[ "client_id" .= cid.client,
"user_id" .= cid.user,
"domain" .= cid.domain
]
)
[alice1, alice2, charlie1]
sub %. "members" `shouldMatchSet` members
16 changes: 14 additions & 2 deletions integration/test/Testlib/Cannon.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import Data.Function
import Data.Maybe
import Data.Traversable
import Data.Word
import GHC.Records
import GHC.Stack
import qualified Network.HTTP.Client as HTTP
import qualified Network.HTTP.Client as Http
Expand All @@ -78,11 +79,22 @@ import UnliftIO (withRunInIO)
import Prelude

data WebSocket = WebSocket
{ wsChan :: TChan Value,
{ wsConnect :: WSConnect,
wsChan :: TChan Value,
wsCloseLatch :: MVar (),
wsAppThread :: Async ()
}

instance HasField "client" WebSocket (Maybe ClientIdentity) where
getField ws = do
c <- ws.wsConnect.client
pure
ClientIdentity
{ domain = ws.wsConnect.domain,
user = ws.wsConnect.user,
client = c
}

-- Specifies how a Websocket at cannon should be opened
data WSConnect = WSConnect
{ user :: String,
Expand Down Expand Up @@ -123,7 +135,7 @@ connect wsConnect = do
nchan <- liftIO newTChanIO
latch <- liftIO newEmptyMVar
wsapp <- run wsConnect (clientApp nchan latch)
pure $ WebSocket nchan latch wsapp
pure $ WebSocket wsConnect nchan latch wsapp

clientApp :: (HasCallStack) => TChan Value -> MVar () -> WS.ClientApp ()
clientApp wsChan latch conn = do
Expand Down
Loading