Skip to content
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
1 change: 1 addition & 0 deletions changelog.d/5-internal/sqservices-1118
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tag integration tests for certification.
66 changes: 64 additions & 2 deletions services/galley/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ tests s =
test s "cannot join private conversation" postJoinConvFail,
test s "remove user with only local convs" removeUserNoFederation,
test s "remove user with local and remote convs" removeUser,
test s "iUpsertOne2OneConversation" testAllOne2OneConversationRequests
test s "iUpsertOne2OneConversation" testAllOne2OneConversationRequests,
test s "post message - reject if missing client" postMessageRejectIfMissingClients,
test s "post message - client that is not in group doesn't receive message" postMessageClientNotInGroupDoesNotReceiveMsg
]

emptyFederatedBrig :: F.BrigApi (AsServerT Handler)
Expand Down Expand Up @@ -366,6 +368,7 @@ postConvWithRemoteUsersOk = do

-- | This test verifies whether a message actually gets sent all the way to
-- cannon.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postCryptoMessage1 :: TestM ()
postCryptoMessage1 = do
localDomain <- viewFederationDomain
Expand Down Expand Up @@ -450,6 +453,7 @@ postCryptoMessage1 = do
assertNoMsg wsB2 (wsAssertOtr qconv qalice ac bc cipher)

-- | This test verifies basic mismatch behaviour of the the JSON endpoint.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postCryptoMessage2 :: TestM ()
postCryptoMessage2 = do
b <- view tsBrig
Expand All @@ -475,6 +479,7 @@ postCryptoMessage2 = do
Map.keys <$> Map.lookup eve (userClientMap (getUserClientPrekeyMap p)) @=? Just [ec]

-- | This test verifies basic mismatch behaviour of the protobuf endpoint.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postCryptoMessage3 :: TestM ()
postCryptoMessage3 = do
b <- view tsBrig
Expand All @@ -501,7 +506,7 @@ postCryptoMessage3 = do
Map.keys (userClientMap (getUserClientPrekeyMap p)) @=? [eve]
Map.keys <$> Map.lookup eve (userClientMap (getUserClientPrekeyMap p)) @=? Just [ec]

-- | This test verfies behaviour when an unknown client posts the message. Only
-- | This test verifies behaviour when an unknown client posts the message. Only
-- tests the Protobuf endpoint.
postCryptoMessage4 :: TestM ()
postCryptoMessage4 = do
Expand All @@ -516,8 +521,63 @@ postCryptoMessage4 = do
postProtoOtrMessage alice (ClientId "172618352518396") conv m
!!! const 403 === statusCode

-- | This test verifies the following scenario.
-- A client sends a message to all clients of a group and one more who is not part of the group.
-- The server must not send this message to client ids not part of the group.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postMessageClientNotInGroupDoesNotReceiveMsg :: TestM ()
postMessageClientNotInGroupDoesNotReceiveMsg = do
localDomain <- viewFederationDomain
cannon <- view tsCannon
(alice, ac) <- randomUserWithClient (someLastPrekeys !! 0)
(bob, bc) <- randomUserWithClient (someLastPrekeys !! 1)
(eve, ec) <- randomUserWithClient (someLastPrekeys !! 2)
(chad, cc) <- randomUserWithClient (someLastPrekeys !! 3)
connectUsers alice (list1 bob [eve, chad])
conversationWithAllButChad <- decodeConvId <$> postConv alice [bob, eve] (Just "gossip") [] Nothing Nothing
let qalice = Qualified alice localDomain
qconv = Qualified conversationWithAllButChad localDomain
WS.bracketR3 cannon bob eve chad $ \(wsBob, wsEve, wsChad) -> do
let msgToAllIncludingChad = [(bob, bc, toBase64Text "ciphertext2"), (eve, ec, toBase64Text "ciphertext2"), (chad, cc, toBase64Text "ciphertext2")]
postOtrMessage id alice ac conversationWithAllButChad msgToAllIncludingChad !!! const 201 === statusCode
let checkBobGetsMsg = void . liftIO $ WS.assertMatch (5 # Second) wsBob (wsAssertOtr qconv qalice ac bc (toBase64Text "ciphertext2"))
let checkEveGetsMsg = void . liftIO $ WS.assertMatch (5 # Second) wsEve (wsAssertOtr qconv qalice ac ec (toBase64Text "ciphertext2"))
let checkChadDoesNotGetMsg = assertNoMsg wsChad (wsAssertOtr qconv qalice ac ac (toBase64Text "ciphertext2"))
checkBobGetsMsg
checkEveGetsMsg
checkChadDoesNotGetMsg

-- | This test verifies that when a client sends a message not to all clients of a group then the server should reject the message and sent a notification to the sender (412 Missing clients).
-- The test is somewhat redundant because this is already tested as part of other tests already. This is a stand alone test that solely tests the behavior described above.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postMessageRejectIfMissingClients :: TestM ()
postMessageRejectIfMissingClients = do
(sender, senderClient) : allReceivers <- randomUserWithClient `traverse` someLastPrekeys
let (receiver1, receiverClient1) : otherReceivers = allReceivers
connectUsers sender (list1 receiver1 (fst <$> otherReceivers))
conv <- decodeConvId <$> postConv sender (receiver1 : (fst <$> otherReceivers)) (Just "gossip") [] Nothing Nothing
let msgToAllClients = mkMsg "hello!" <$> allReceivers
let msgMissingClients = mkMsg "hello!" <$> drop 1 allReceivers

let checkSendToAllClientShouldBeSuccessful =
postOtrMessage id sender senderClient conv msgToAllClients !!! do
const 201 === statusCode
assertMismatch [] [] []

let checkSendWitMissingClientsShouldFail =
postOtrMessage id sender senderClient conv msgMissingClients !!! do
const 412 === statusCode
assertMismatch [(receiver1, Set.singleton receiverClient1)] [] []

checkSendToAllClientShouldBeSuccessful
checkSendWitMissingClientsShouldFail
where
mkMsg :: ByteString -> (UserId, ClientId) -> (UserId, ClientId, Text)
mkMsg text (userId, clientId) = (userId, clientId, toBase64Text text)

-- | This test verifies behaviour under various values of ignore_missing and
-- report_missing. Only tests the JSON endpoint.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postCryptoMessage5 :: TestM ()
postCryptoMessage5 = do
(alice, ac) <- randomUserWithClient (someLastPrekeys !! 0)
Expand Down Expand Up @@ -709,6 +769,7 @@ postMessageQualifiedLocalOwningBackendSuccess = do
-- | Sets up a conversation on Backend A known as "owning backend". One of the
-- users from Backend A will send the message but have a missing client. It is
-- expected that the message will not be sent.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postMessageQualifiedLocalOwningBackendMissingClients :: TestM ()
postMessageQualifiedLocalOwningBackendMissingClients = do
-- Cannon for local users
Expand Down Expand Up @@ -868,6 +929,7 @@ postMessageQualifiedLocalOwningBackendRedundantAndDeletedClients = do
-- users from Backend A will send the message but have a missing client. It is
-- expected that the message will be sent except when it is specifically
-- requested to report on missing clients of a user.
-- @SF.Separation @TSFI.RESTfulAPI @S2
postMessageQualifiedLocalOwningBackendIgnoreMissingClients :: TestM ()
postMessageQualifiedLocalOwningBackendIgnoreMissingClients = do
-- WS receive timeout
Expand Down