@@ -26,13 +26,10 @@ import Control.Lens hiding ((#))
26
26
import qualified Data.Aeson as A
27
27
import Data.ByteString.Conversion (toByteString' )
28
28
import Data.Domain
29
- import Data.Id (ConvId , Id (.. ), UserId , randomId )
30
- import Data.Json.Util hiding ((#) )
29
+ import Data.Id
31
30
import Data.List.NonEmpty (NonEmpty (.. ))
32
31
import Data.List1 hiding (head )
33
32
import qualified Data.List1 as List1
34
- import qualified Data.Map as Map
35
- import qualified Data.ProtoLens as Protolens
36
33
import Data.Qualified
37
34
import Data.Range
38
35
import qualified Data.Set as Set
@@ -43,7 +40,6 @@ import Data.UUID.V4 (nextRandom)
43
40
import Federator.MockServer
44
41
import Imports
45
42
import qualified Network.HTTP.Types as Http
46
- import Test.QuickCheck (arbitrary , generate )
47
43
import Test.Tasty
48
44
import qualified Test.Tasty.Cannon as WS
49
45
import Test.Tasty.HUnit
@@ -58,9 +54,7 @@ import Wire.API.Federation.API.Galley
58
54
import qualified Wire.API.Federation.API.Galley as FedGalley
59
55
import Wire.API.Federation.Component
60
56
import Wire.API.Internal.Notification
61
- import Wire.API.Message
62
57
import Wire.API.Routes.Internal.Galley.ConversationsIntra
63
- import Wire.API.User.Client (PubClient (.. ))
64
58
import Wire.API.User.Profile
65
59
66
60
tests :: IO TestSetup -> TestTree
@@ -84,7 +78,6 @@ tests s =
84
78
test s " POST /federation/leave-conversation : Success" leaveConversationSuccess,
85
79
test s " POST /federation/leave-conversation : Non-existent" leaveConversationNonExistent,
86
80
test s " POST /federation/leave-conversation : Invalid type" leaveConversationInvalidType,
87
- test s " POST /federation/send-message : Post a message sent from another backend" sendMessage,
88
81
test s " POST /federation/on-user-deleted-conversations : Remove deleted remote user from local conversations" onUserDeleted,
89
82
test s " POST /federation/update-conversation : Update local conversation by a remote admin " updateConversationByRemoteAdmin,
90
83
test s " POST /federation/on-conversation-updated : Notify local user about conversation rename with an unavailable federator" notifyConvRenameUnavailable,
@@ -816,111 +809,6 @@ leaveConversationInvalidType = do
816
809
<!! const 200 === statusCode
817
810
liftIO $ resp @?= Left FedGalley. RemoveFromConversationErrorRemovalNotAllowed
818
811
819
- -- alice local, bob and chad remote in a local conversation
820
- -- bob sends a message (using the RPC), we test that alice receives it and that
821
- -- a call is made to the onMessageSent RPC to inform chad
822
- sendMessage :: TestM ()
823
- sendMessage = do
824
- cannon <- view tsCannon
825
- let remoteDomain = Domain " far-away.example.com"
826
- localDomain <- viewFederationDomain
827
-
828
- -- users and clients
829
- (alice, aliceClient) <- randomUserWithClientQualified (head someLastPrekeys)
830
- let aliceId = qUnqualified alice
831
- bobId <- randomId
832
- bobClient <- liftIO $ generate arbitrary
833
- let bob = Qualified bobId remoteDomain
834
- bobProfile = mkProfile bob (Name " Bob" )
835
- chadId <- randomId
836
- chadClient <- liftIO $ generate arbitrary
837
- let chad = Qualified chadId remoteDomain
838
- chadProfile = mkProfile chad (Name " Chad" )
839
-
840
- connectWithRemoteUser aliceId bob
841
- connectWithRemoteUser aliceId chad
842
- -- conversation
843
- let responses1 = guardComponent Brig *> mockReply [bobProfile, chadProfile]
844
- (convId, requests1) <-
845
- withTempMockFederator' (responses1 <|> mockReply EmptyResponse ) $
846
- fmap decodeConvId $
847
- postConvQualified
848
- aliceId
849
- Nothing
850
- defNewProteusConv
851
- { newConvQualifiedUsers = [bob, chad]
852
- }
853
- <!! const 201 === statusCode
854
-
855
- liftIO $ do
856
- [galleyReq] <- case requests1 of
857
- xs@ [_] -> pure xs
858
- _ -> assertFailure " unexpected number of requests"
859
- frComponent galleyReq @?= Galley
860
- frRPC galleyReq @?= " on-conversation-created"
861
- let conv = Qualified convId localDomain
862
-
863
- -- we use bilge instead of the federation client to make a federated request
864
- -- here, because we need to make use of the mock federator, which at the moment
865
- -- supports only bilge requests
866
- let rcpts =
867
- [ (alice, aliceClient, " hi alice" ),
868
- (chad, chadClient, " hi chad" )
869
- ]
870
- msg = mkQualifiedOtrPayload bobClient rcpts " " MismatchReportAll
871
- msr =
872
- FedGalley. ProteusMessageSendRequest
873
- { FedGalley. pmsrConvId = convId,
874
- FedGalley. pmsrSender = bobId,
875
- FedGalley. pmsrRawMessage = Base64ByteString (Protolens. encodeMessage msg)
876
- }
877
- let mock = do
878
- guardComponent Brig
879
- mockReply $
880
- Map. fromList
881
- [ (chadId, Set. singleton (PubClient chadClient Nothing )),
882
- (bobId, Set. singleton (PubClient bobClient Nothing ))
883
- ]
884
- (_, requests2) <- withTempMockFederator' (mock <|> mockReply EmptyResponse ) $ do
885
- WS. bracketR cannon aliceId $ \ ws -> do
886
- g <- viewGalley
887
- msresp <-
888
- post
889
- ( g
890
- . paths [" federation" , " send-message" ]
891
- . content " application/json"
892
- . header " Wire-Origin-Domain" (toByteString' remoteDomain)
893
- . json msr
894
- )
895
- <!! do
896
- const 200 === statusCode
897
- (FedGalley. MessageSendResponse eithStatus) <- responseJsonError msresp
898
- liftIO $ case eithStatus of
899
- Left err -> assertFailure $ " Expected Right, got Left: " <> show err
900
- Right mss -> do
901
- assertEqual " missing clients should be empty" mempty (mssMissingClients mss)
902
- assertEqual " redundant clients should be empty" mempty (mssRedundantClients mss)
903
- assertEqual " deleted clients should be empty" mempty (mssDeletedClients mss)
904
- assertEqual " failed to send should be empty" mempty (mssFailedToSend mss)
905
-
906
- -- check that alice received the message
907
- WS. assertMatch_ (5 # Second ) ws $
908
- wsAssertOtr' " " conv bob bobClient aliceClient (toBase64Text " hi alice" )
909
-
910
- -- check that a request to propagate message to chad has been made
911
- liftIO $ do
912
- [_clientReq, receiveReq] <- case requests2 of
913
- xs@ [_, _] -> pure xs
914
- _ -> assertFailure " unexpected number of requests"
915
- frComponent receiveReq @?= Galley
916
- frRPC receiveReq @?= " on-message-sent"
917
- rm <- case A. decode (frBody receiveReq) of
918
- Nothing -> assertFailure " invalid federated request body"
919
- Just x -> pure (x :: FedGalley. RemoteMessage ConvId )
920
- FedGalley. rmSender rm @?= bob
921
- Map. keysSet (userClientMap (FedGalley. rmRecipients rm))
922
- @?= Set. singleton chadId
923
-
924
812
-- | There are 3 backends in action here:
925
813
--
926
814
-- - Backend A (local) has Alice and Alex
0 commit comments