Skip to content

Commit

Permalink
Merge branch 'wireapp:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
offsoc authored Dec 28, 2024
2 parents 49a3383 + eabc5d2 commit 5648ecb
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 383 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Revive and translate old integration test.
Revive and translate old integration test (#4387, ##)
26 changes: 0 additions & 26 deletions integration/test/SetupHelpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import API.BrigInternal
import API.Cargohold
import API.Common
import API.Galley
import API.GalleyInternal (legalholdWhitelistTeam)
import API.Spar
import Control.Monad.Reader
import Crypto.Random (getRandomBytes)
Expand All @@ -34,7 +33,6 @@ import qualified SAML2.WebSSO.API.Example as SAML
import qualified SAML2.WebSSO.Test.MockResponse as SAML
import SAML2.WebSSO.Test.Util (SampleIdP (..), makeSampleIdPMetadata)
import Testlib.JSON
import Testlib.MockIntegrationService (mkLegalHoldSettings)
import Testlib.Prelude
import Testlib.Printing (indent)
import qualified Text.XML as XML
Expand Down Expand Up @@ -324,30 +322,6 @@ setupProvider u np@(NewProvider {..}) = do
activateProvider dom key code
loginProvider dom newProviderEmail pass $> provider

-- | setup a legalhold device for @uid@, authorised by @owner@
-- at the specified port
setUpLHDevice ::
(HasCallStack, MakesValue tid, MakesValue owner, MakesValue uid) =>
tid ->
owner ->
uid ->
-- | the host and port the LH service is running on
(String, Int) ->
App ()
setUpLHDevice tid alice bob lhPort = do
legalholdWhitelistTeam tid alice
>>= assertStatus 200

-- the status messages for these have already been tested
postLegalHoldSettings tid alice (mkLegalHoldSettings lhPort)
>>= assertStatus 201

requestLegalHoldDevice tid alice bob
>>= assertStatus 201

approveLegalHoldDevice tid bob defPassword
>>= assertStatus 200

lhDeviceIdOf :: (MakesValue user) => user -> App String
lhDeviceIdOf bob = do
bobId <- objId bob
Expand Down
39 changes: 27 additions & 12 deletions integration/test/Test/Events.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Servant.API (AsApi, ToServant, toServant)
import Servant.API.Generic (fromServant)
import qualified Servant.Client as Servant
import SetupHelpers
import Testlib.Prelude hiding (assertNoEvent)
import Testlib.Prelude
import UnliftIO hiding (handle)

testConsumeEventsOneWebSocket :: (HasCallStack) => App ()
Expand Down Expand Up @@ -480,21 +480,23 @@ testChannelKilled = startDynamicBackendsReturnResources [def] $ \[backend] -> do
>>= asString

runCodensity (createEventsWebSocket alice (Just c1)) $ \ws -> do
assertEvent ws $ \e -> do
-- If creating the user takes longer (async) than adding the clients, we get a
-- `"user.activate"` here, so we use `assertFindsEvent`.

assertFindsEvent ws $ \e -> do
e %. "data.event.payload.0.type" `shouldMatch` "user.client-add"
e %. "data.event.payload.0.client.id" `shouldMatch` c1
ackEvent ws e

assertEvent ws $ \e -> do
assertFindsEvent ws $ \e -> do
e %. "data.event.payload.0.type" `shouldMatch` "user.client-add"
e %. "data.event.payload.0.client.id" `shouldMatch` c2

recoverAll
(constantDelay 500_000 <> limitRetries 10)
(const (killConnection backend))
recoverAll
(constantDelay 500_000 <> limitRetries 10)
(const (killConnection backend))

noEvent <- assertNoEvent ws
noEvent `shouldMatch` WebSocketDied
assertWebSocketDied ws

----------------------------------------------------------------------
-- helpers
Expand Down Expand Up @@ -622,17 +624,30 @@ instance ToJSON NoEvent where
toJSON NoEvent = toJSON "no-event"
toJSON WebSocketDied = toJSON "web-socket-died"

assertNoEvent :: (HasCallStack) => EventWebSocket -> App NoEvent
assertNoEvent ws = do
timeout 1_000_000 (readChan ws.events) >>= \case
assertNoEventHelper :: (HasCallStack) => EventWebSocket -> App NoEvent
assertNoEventHelper ws = do
timeOutSeconds <- asks (.timeOutSeconds)
timeout (timeOutSeconds * 1_000_000) (readChan ws.events) >>= \case
Nothing -> pure NoEvent
Just (Left _) -> pure WebSocketDied
Just (Right e) -> do
eventJSON <- prettyJSON e
assertFailure $ "Did not expect event: \n" <> eventJSON

-- | Similar to `assertNoEvent` from Testlib, but with rabbitMQ typing (`/event` end-point, not
-- `/await`).
assertNoEvent_ :: (HasCallStack) => EventWebSocket -> App ()
assertNoEvent_ = void . assertNoEvent
assertNoEvent_ = void . assertNoEventHelper

assertWebSocketDied :: (HasCallStack) => EventWebSocket -> App ()
assertWebSocketDied ws = do
recpol <- do
timeOutSeconds <- asks (.timeOutSeconds)
pure $ limitRetriesByCumulativeDelay (timeOutSeconds * 1_000_000) (constantDelay 800_000)
recoverAll recpol $ \_ ->
assertNoEventHelper ws >>= \case
NoEvent -> assertFailure $ "WebSocket is still open"
WebSocketDied -> pure ()

consumeAllEvents :: EventWebSocket -> App ()
consumeAllEvents ws = do
Expand Down
Loading

0 comments on commit 5648ecb

Please sign in to comment.