Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti authored and mdimjasevic committed Sep 6, 2022
1 parent b697f93 commit b33b18f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
17 changes: 10 additions & 7 deletions services/galley/src/Galley/API/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ performConversationAccessData lconv action = do
notifyConversationAction
(sing @'ConversationLeaveTag)
userToRemove
True
Nothing
lconv
(bmToNotify <> extraTargets)
Expand Down Expand Up @@ -638,6 +639,7 @@ updateLocalConversationUnchecked lconv qusr con action = do
notifyConversationAction
(sing @tag)
qusr
False
con
lconv
(convBotsAndMembers conv <> extraTargets)
Expand Down Expand Up @@ -692,12 +694,13 @@ notifyConversationAction ::
Members '[FederatorAccess, ExternalAccess, GundeckAccess, Input UTCTime] r =>
Sing tag ->
Qualified UserId ->
Bool ->
Maybe ConnId ->
Local Conversation ->
BotsAndMembers ->
ConversationAction (tag :: ConversationActionTag) ->
Sem r LocalConversationUpdate
notifyConversationAction tag quid con lconv targets action = do
notifyConversationAction tag quid notifyOrigDomain con lconv targets action = do
now <- input
let lcnv = fmap convId lconv
conv = tUnqualified lconv
Expand Down Expand Up @@ -729,12 +732,12 @@ notifyConversationAction tag quid con lconv targets action = do
. E.runFederatedConcurrently (toList (bmRemotes targets))
$ \ruids -> do
let update = mkUpdate (tUnqualified ruids)
-- filter out user from quid's domain, because quid's backend will update
-- local state and notify its users itself using the ConversationUpdate
-- returned by this function
if tDomain ruids == qDomain quid
then pure (Just update)
else fedClient @'Galley @"on-conversation-updated" update $> Nothing
-- if notifyOrigDomain is false, filter out user from quid's domain,
-- because quid's backend will update local state and notify its users
-- itself using the ConversationUpdate returned by this function
if notifyOrigDomain || tDomain ruids /= qDomain quid
then fedClient @'Galley @"on-conversation-updated" update $> Nothing
else pure (Just update)

-- notify local participants and bots
pushConversationEvent con e (qualifyAs lcnv (bmLocals targets)) (bmBots targets)
Expand Down
2 changes: 2 additions & 0 deletions services/galley/src/Galley/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ leaveConversation requestingDomain lc = do
notifyConversationAction
SConversationLeaveTag
(qUntagged leaver)
False
Nothing
(qualifyAs lcnv conv)
botsAndMembers
Expand Down Expand Up @@ -466,6 +467,7 @@ onUserDeleted origDomain udcn = do
notifyConversationAction
(sing @'ConversationLeaveTag)
untaggedDeletedUser
False
Nothing
(qualifyAs lc conv)
botsAndMembers
Expand Down
1 change: 1 addition & 0 deletions services/galley/src/Galley/API/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ joinConversation lusr zcon conv access = do
<$> notifyConversationAction
(sing @'ConversationJoinTag)
(qUntagged lusr)
False
(Just zcon)
(qualifyAs lusr conv)
(convBotsAndMembers conv <> extraTargets)
Expand Down
1 change: 1 addition & 0 deletions services/galley/src/Galley/API/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ data BotsAndMembers = BotsAndMembers
bmRemotes :: Set (Remote UserId),
bmBots :: Set BotMember
}
deriving (Show)

bmQualifiedMembers :: Local x -> BotsAndMembers -> [Qualified UserId]
bmQualifiedMembers loc bm =
Expand Down
50 changes: 37 additions & 13 deletions services/galley/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ postConvertTeamConv = do
dave <- view Teams.userId <$> addUserToTeam alice tid
assertQueue "team member (dave) join" $ tUpdate 3 [alice]
refreshIndex
eve <- randomUser
(eve, qeve) <- randomUserTuple
connectUsers alice (singleton eve)
let acc = Just $ Set.fromList [InviteAccess, CodeAccess]
-- creating a team-only conversation containing eve should fail
Expand Down Expand Up @@ -1478,9 +1478,11 @@ postConvertTeamConv = do
WS.assertMatchN (5 # Second) [wsA, wsB, wsE, wsM] $
wsAssertConvAccessUpdate qconv qalice teamAccess
-- non-team members get kicked out
void . liftIO $
WS.assertMatchN (5 # Second) [wsA, wsB, wsE, wsM] $
wsAssertMemberLeave qconv qalice $ (`Qualified` localDomain) <$> [eve, mallory]
liftIO $ do
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsE, wsM] $
wsAssertMemberLeave qconv qeve (pure qeve)
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsE, wsM] $
wsAssertMemberLeave qconv qmallory (pure qmallory)
-- joining (for mallory) is no longer possible
postJoinCodeConv mallory j !!! const 403 === statusCode
-- team members (dave) can still join
Expand Down Expand Up @@ -1532,19 +1534,41 @@ testAccessUpdateGuestRemoved = do
-- note that removing users happens asynchronously, so this check should
-- happen while the mock federator is still available
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsC] $
wsAssertMembersLeave (cnvQualifiedId conv) alice [charlie, dee]
wsAssertMembersLeave (cnvQualifiedId conv) charlie [charlie]
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsC] $
wsAssertMembersLeave (cnvQualifiedId conv) dee [dee]

-- dee's remote receives a notification
liftIO $
map
( \fr -> do
cu <- eitherDecode (frBody fr)
pure (F.cuOrigUserId cu, F.cuAction cu)
sortOn
(fmap fst)
( map
( \fr -> do
cu <- eitherDecode (frBody fr)
pure (F.cuOrigUserId cu, F.cuAction cu)
)
( filter
( \fr ->
frComponent fr == Galley
&& frRPC fr == "on-conversation-updated"
)
reqs
)
)
(filter (\fr -> frComponent fr == Galley && frRPC fr == "on-conversation-updated") reqs)
@?= [ Right (charlie, SomeConversationAction (sing @'ConversationLeaveTag) ()),
Right (dee, SomeConversationAction (sing @'ConversationLeaveTag) ())
]
@?= sortOn
(fmap fst)
[ Right (charlie, SomeConversationAction (sing @'ConversationLeaveTag) ()),
Right (dee, SomeConversationAction (sing @'ConversationLeaveTag) ()),
Right
( alice,
SomeConversationAction
(sing @'ConversationAccessDataTag)
ConversationAccessData
{ cupAccess = mempty,
cupAccessRoles = Set.fromList [TeamMemberAccessRole]
}
)
]

-- only alice and bob remain
conv2 <-
Expand Down
2 changes: 1 addition & 1 deletion services/galley/test/integration/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ onUserDeleted = do
FedGalley.cuOrigUserId cDomainRPCReq @?= qUntagged bob
FedGalley.cuConvId cDomainRPCReq @?= qUnqualified groupConvId
FedGalley.cuAlreadyPresentUsers cDomainRPCReq @?= [qUnqualified carl]
FedGalley.cuAction cDomainRPCReq @?= SomeConversationAction (sing @'ConversationRemoveMembersTag) (pure $ qUntagged bob)
FedGalley.cuAction cDomainRPCReq @?= SomeConversationAction (sing @'ConversationLeaveTag) ()

-- | We test only ReceiptMode update here
--
Expand Down

0 comments on commit b33b18f

Please sign in to comment.