Skip to content

Commit

Permalink
Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed May 31, 2021
1 parent 5204d24 commit 8aea18e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
17 changes: 12 additions & 5 deletions services/galley/test/integration/API/Teams/LegalHold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,18 @@ testOldClientsBlockDeviceHandshake = do
legalholderLHDevice <- doEnableLH legalholder legalholder
_legalholder2LHDevice <- doEnableLH legalholder legalholder2

legalholderClient <- randomClient legalholder (someLastPrekeys !! 1)
upgradeClientToLH legalholder legalholderClient
legalholder2Client <- randomClient legalholder2 (someLastPrekeys !! 3)
upgradeClientToLH legalholder2 legalholder2Client

let caps = Set.singleton Client.ClientSupportsLegalholdImplicitConsent
legalholderClient <- do
clnt <- randomClientWithCaps legalholder (someLastPrekeys !! 1) (Just caps)
ensureClientCaps legalholder clnt (Client.ClientCapabilityList caps)
pure clnt
legalholder2Client <- do
clnt <- randomClient legalholder2 (someLastPrekeys !! 3)
-- this another way to do it (instead of providing caps during client creation).
ensureClientCaps legalholder2 clnt (Client.ClientCapabilityList mempty)
upgradeClientToLH legalholder2 clnt
ensureClientCaps legalholder2 clnt (Client.ClientCapabilityList caps)
pure clnt
grantConsent tid2 peer
connectUsers peer (List1.list1 legalholder [legalholder2])

Expand Down
19 changes: 15 additions & 4 deletions services/galley/test/integration/API/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import qualified API.SQS as SQS
import Bilge hiding (timeout)
import Bilge.Assert
import Brig.Types
import Brig.Types.Intra (ConnectionStatus (ConnectionStatus), UserAccount (..), UserSet)
import Brig.Types.Intra (ConnectionStatus (ConnectionStatus), UserAccount (..), UserSet (..))
import Brig.Types.Team.Invitation
import Brig.Types.User.Auth (CookieLabel (..))
import Control.Exception (finally)
Expand Down Expand Up @@ -95,7 +95,8 @@ import qualified Wire.API.Event.Team as TE
import Wire.API.Federation.GRPC.Types (OutwardResponse (..))
import qualified Wire.API.Federation.Mock as Mock
import qualified Wire.API.Message.Proto as Proto
import Wire.API.User.Client (ClientCapability (..), UserClientsFull)
import Wire.API.User.Client (ClientCapability (..), UserClientsFull (UserClientsFull))
import qualified Wire.API.User.Client as Client

-------------------------------------------------------------------------------
-- API Operations
Expand Down Expand Up @@ -1284,7 +1285,10 @@ ephemeralUser = do
return $ Brig.Types.userId user

randomClient :: HasCallStack => UserId -> LastPrekey -> TestM ClientId
randomClient uid lk = do
randomClient uid lk = randomClientWithCaps uid lk Nothing

randomClientWithCaps :: HasCallStack => UserId -> LastPrekey -> Maybe (Set Client.ClientCapability) -> TestM ClientId
randomClientWithCaps uid lk caps = do
b <- view tsBrig
resp <-
post (b . paths ["i", "clients", toByteString' uid] . json newClientBody)
Expand All @@ -1296,7 +1300,8 @@ randomClient uid lk = do
rStatus = 201
newClientBody =
(newClient cType lk)
{ newClientPassword = Just defPassword
{ newClientPassword = Just defPassword,
newClientCapabilities = caps
}

ensureDeletedState :: HasCallStack => Bool -> UserId -> UserId -> TestM ()
Expand Down Expand Up @@ -1335,6 +1340,12 @@ getInternalClientsFull userSet = do
. json userSet
responseJsonError res

ensureClientCaps :: HasCallStack => UserId -> ClientId -> Client.ClientCapabilityList -> TestM ()
ensureClientCaps uid cid caps = do
UserClientsFull (Map.lookup uid -> (Just clnts)) <- getInternalClientsFull (UserSet $ Set.singleton uid)
let [clnt] = filter ((== cid) . clientId) $ Set.toList clnts
liftIO $ assertEqual ("ensureClientCaps: " <> show (uid, cid, caps)) (clientCapabilities clnt) caps

-- TODO: Refactor, as used also in brig
deleteClient :: UserId -> ClientId -> Maybe PlainTextPassword -> TestM ResponseLBS
deleteClient u c pw = do
Expand Down

0 comments on commit 8aea18e

Please sign in to comment.