Skip to content

Commit

Permalink
Move MLS mocks to a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti committed Jan 25, 2023
1 parent 1be3896 commit 8ca5fd6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 38 deletions.
1 change: 1 addition & 0 deletions services/galley/galley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ executable galley-integration
API.Federation.Util
API.MessageTimer
API.MLS
API.MLS.Mocks
API.MLS.Util
API.Roles
API.SQS
Expand Down
39 changes: 1 addition & 38 deletions services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

module API.MLS (tests) where

import API.MLS.Mocks
import API.MLS.Util
import API.Util
import Bilge hiding (head)
Expand Down Expand Up @@ -59,18 +60,15 @@ import Wire.API.Conversation.Action
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.Role
import Wire.API.Error.Galley
import Wire.API.Federation.API.Common
import Wire.API.Federation.API.Galley
import Wire.API.MLS.Credential
import Wire.API.MLS.KeyPackage
import Wire.API.MLS.Keys
import Wire.API.MLS.Serialisation
import Wire.API.MLS.SubConversation
import Wire.API.MLS.Welcome
import Wire.API.Message
import Wire.API.Routes.MultiTablePaging
import Wire.API.Routes.Version
import Wire.API.User.Client

tests :: IO TestSetup -> TestTree
tests s =
Expand Down Expand Up @@ -2149,38 +2147,3 @@ getGroupInfoDisabled = do
withMLSDisabled $
getGroupInfo (qUnqualified alice) qcnv
!!! assertMLSNotEnabled

--------------------------------------------------------------------------------
-- Mock utilities

receiveCommitMock :: [ClientIdentity] -> Mock LByteString
receiveCommitMock clients =
asum
[ "on-conversation-updated" ~> (),
"on-new-remote-conversation" ~> EmptyResponse,
"get-mls-clients" ~>
Set.fromList
( map (flip ClientInfo True . ciClient) clients
)
]

messageSentMock :: Mock LByteString
messageSentMock = "on-mls-message-sent" ~> RemoteMLSMessageOk

welcomeMock :: Mock LByteString
welcomeMock = "mls-welcome" ~> MLSWelcomeSent

sendMessageMock :: Mock LByteString
sendMessageMock = "send-mls-message" ~> MLSMessageResponseUpdates []

claimKeyPackagesMock :: KeyPackageBundle -> Mock LByteString
claimKeyPackagesMock kpb = "claim-key-packages" ~> kpb

queryGroupStateMock :: ByteString -> Qualified UserId -> Mock LByteString
queryGroupStateMock gs qusr = do
guardRPC "query-group-info"
uid <- ggireqSender <$> getRequestBody
mockReply $
if uid == qUnqualified qusr
then GetGroupInfoResponseState (Base64ByteString gs)
else GetGroupInfoResponseError ConvNotFound
71 changes: 71 additions & 0 deletions services/galley/test/integration/API/MLS/Mocks.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module API.MLS.Mocks
( receiveCommitMock,
messageSentMock,
welcomeMock,
sendMessageMock,
claimKeyPackagesMock,
queryGroupStateMock,
)
where

import Data.Id
import Data.Json.Util
import Data.Qualified
import qualified Data.Set as Set
import Federator.MockServer
import Imports
import Wire.API.Error.Galley
import Wire.API.Federation.API.Common
import Wire.API.Federation.API.Galley
import Wire.API.MLS.Credential
import Wire.API.MLS.KeyPackage
import Wire.API.User.Client

receiveCommitMock :: [ClientIdentity] -> Mock LByteString
receiveCommitMock clients =
asum
[ "on-conversation-updated" ~> (),
"on-new-remote-conversation" ~> EmptyResponse,
"get-mls-clients" ~>
Set.fromList
( map (flip ClientInfo True . ciClient) clients
)
]

messageSentMock :: Mock LByteString
messageSentMock = "on-mls-message-sent" ~> RemoteMLSMessageOk

welcomeMock :: Mock LByteString
welcomeMock = "mls-welcome" ~> MLSWelcomeSent

sendMessageMock :: Mock LByteString
sendMessageMock = "send-mls-message" ~> MLSMessageResponseUpdates []

claimKeyPackagesMock :: KeyPackageBundle -> Mock LByteString
claimKeyPackagesMock kpb = "claim-key-packages" ~> kpb

queryGroupStateMock :: ByteString -> Qualified UserId -> Mock LByteString
queryGroupStateMock gs qusr = do
guardRPC "query-group-info"
uid <- ggireqSender <$> getRequestBody
mockReply $
if uid == qUnqualified qusr
then GetGroupInfoResponseState (Base64ByteString gs)
else GetGroupInfoResponseError ConvNotFound

0 comments on commit 8ca5fd6

Please sign in to comment.