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 commit bundle support #2688

Merged
merged 18 commits into from
Sep 19, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Test remote commit bundles
pcapriotti committed Sep 19, 2022

Verified

This commit was signed with the committer’s verified signature.
sandhose Quentin Gliech
commit aa8151ff4c56a4d4f2ff2f4d7c946fb6123396ae
62 changes: 59 additions & 3 deletions services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
@@ -100,6 +100,7 @@ tests s =
test s "add user with some non-MLS clients" testAddUserWithProteusClients,
test s "send a stale commit" testStaleCommit,
test s "add remote user to a conversation" testAddRemoteUser,
test s "add remote user with a commit bundle" testAddRemoteUserWithBundle,
test s "return error when commit is locked" testCommitLock,
test s "add user to a conversation with proposal + commit" testAddUserBareProposalCommit,
test s "post commit that references a unknown proposal" testUnknownProposalRefCommit,
@@ -298,10 +299,19 @@ testAddUserWithBundle = do
[alice, bob] <- createAndConnectUsers [Nothing, Nothing]

qcnv <- runMLSTest $ do
[alice1, bob1, bob2] <- traverse createMLSClient [alice, bob, bob]
traverse_ uploadNewKeyPackage [bob1, bob2]
(alice1 : bobClients) <- traverse createMLSClient [alice, bob, bob]
traverse_ uploadNewKeyPackage bobClients
(_, qcnv) <- setupMLSGroup alice1
events <- createAddCommit alice1 [bob] >>= sendAndConsumeCommitBundle
commit <- createAddCommit alice1 [bob]
welcome <- assertJust (mpWelcome commit)

events <- mlsBracket bobClients $ \wss -> do
events <- sendAndConsumeCommitBundle commit
for_ (zip bobClients wss) $ \(c, ws) ->
WS.assertMatch (5 # Second) ws $
wsAssertMLSWelcome (cidQualifiedUser c) welcome
pure events

event <- assertOne events
liftIO $ assertJoinEvent qcnv alice [bob] roleNameWireMember event
pure qcnv
@@ -587,6 +597,52 @@ testAddRemoteUser = do
event <- assertOne events
assertJoinEvent qcnv alice [bob] roleNameWireMember event

testAddRemoteUserWithBundle :: TestM ()
testAddRemoteUserWithBundle = do
users@[alice, bob] <- createAndConnectUsers [Nothing, Just "bob.example.com"]
(events, reqs, qcnv) <- runMLSTest $ do
[alice1, bob1] <- traverse createMLSClient users
(_, qcnv) <- setupMLSGroup alice1

let mock req = case frRPC req of
"on-conversation-updated" -> pure (Aeson.encode ())
"on-new-remote-conversation" -> pure (Aeson.encode EmptyResponse)
"get-mls-clients" ->
pure
. Aeson.encode
. Set.fromList
. map (flip ClientInfo True . ciClient)
$ [bob1]
"mls-welcome" -> pure (Aeson.encode EmptyResponse)
ms -> assertFailure ("unmocked endpoint called: " <> cs ms)

commit <- createAddCommit alice1 [bob]
(events, reqs) <-
withTempMockFederator' mock $
sendAndConsumeCommitBundle commit
pure (events, reqs, qcnv)

liftIO $ do
req <- assertOne $ filter ((== "on-conversation-updated") . frRPC) reqs
frTargetDomain req @?= qDomain bob
bdy <- case Aeson.eitherDecode (frBody req) of
Right b -> pure b
Left e -> assertFailure $ "Could not parse on-conversation-updated request body: " <> e
cuOrigUserId bdy @?= alice
cuConvId bdy @?= qUnqualified qcnv
cuAlreadyPresentUsers bdy @?= [qUnqualified bob]
cuAction bdy
@?= SomeConversationAction
SConversationJoinTag
ConversationJoin
{ cjUsers = pure bob,
cjRole = roleNameWireMember
}

liftIO $ do
event <- assertOne events
assertJoinEvent qcnv alice [bob] roleNameWireMember event

testCommitLock :: TestM ()
testCommitLock = do
users <- createAndConnectUsers (replicate 4 Nothing)
2 changes: 2 additions & 0 deletions services/galley/test/integration/API/MLS/Util.hs
Original file line number Diff line number Diff line change
@@ -794,6 +794,8 @@ sendAndConsumeCommitBundle mp = do
. bytes (encodeMLS' bundle)
)
<!! const 201 === statusCode
consumeMessage mp
traverse_ consumeWelcome (mpWelcome mp)

-- increment epoch and add new clients
State.modify $ \mls ->