Skip to content

Commit 33bfe48

Browse files
committed
Migrate mls/clients test to integration
1 parent b6cd866 commit 33bfe48

File tree

5 files changed

+93
-35
lines changed

5 files changed

+93
-35
lines changed

integration/integration.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ library
161161
Test.Login
162162
Test.MessageTimer
163163
Test.MLS
164+
Test.MLS.Clients
164165
Test.MLS.KeyPackage
165166
Test.MLS.Keys
166167
Test.MLS.Message

integration/test/API/BrigInternal.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,9 @@ getDomainRegistration :: (HasCallStack, MakesValue domain) => domain -> String -
381381
getDomainRegistration domain emailDomain = do
382382
req <- baseRequest domain Brig Unversioned $ joinHttpPath ["i", "domain-registration", emailDomain]
383383
submit "GET" req
384+
385+
getMLSClients :: (HasCallStack, MakesValue user) => user -> Ciphersuite -> App Response
386+
getMLSClients user ciphersuite = do
387+
userId <- objId user
388+
req <- baseRequest user Brig Unversioned $ joinHttpPath ["i", "mls", "clients", userId]
389+
submit "GET" $ req & addQueryParams [("ciphersuite", ciphersuite.code)]

integration/test/MLS/Util.hs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,28 +155,33 @@ data InitMLSClient = InitMLSClient
155155
instance Default InitMLSClient where
156156
def = InitMLSClient {credType = BasicCredentialType, clientArgs = def, ciphersuites = [def]}
157157

158-
-- | Create new mls client and register with backend.
159-
createMLSClient :: (MakesValue u, HasCallStack) => InitMLSClient -> u -> App ClientIdentity
160-
createMLSClient opts u = do
161-
cid <- createWireClient u opts.clientArgs
158+
initMLSClient :: InitMLSClient -> ClientIdentity -> App Value
159+
initMLSClient opts cid = do
162160
setClientGroupState cid def {credType = opts.credType}
163161

164162
-- set public key
165163
suitePKeys <- for opts.ciphersuites $ \ciphersuite -> (ciphersuite,) <$> mlscli Nothing ciphersuite cid ["public-key"] Nothing
164+
let keys =
165+
object
166+
[ csSignatureScheme ciphersuite .= T.decodeUtf8 (Base64.encode pkey)
167+
| (ciphersuite, pkey) <- suitePKeys
168+
]
166169
bindResponse
167170
( updateClient
168171
cid
169172
def
170-
{ mlsPublicKeys =
171-
Just
172-
( object
173-
[ csSignatureScheme ciphersuite .= T.decodeUtf8 (Base64.encode pkey)
174-
| (ciphersuite, pkey) <- suitePKeys
175-
]
176-
)
173+
{ mlsPublicKeys = Just keys
177174
}
178175
)
179176
$ \resp -> resp.status `shouldMatchInt` 200
177+
178+
pure keys
179+
180+
-- | Create new mls client and register with backend.
181+
createMLSClient :: (MakesValue u, HasCallStack) => InitMLSClient -> u -> App ClientIdentity
182+
createMLSClient opts u = do
183+
cid <- createWireClient u opts.clientArgs
184+
void $ initMLSClient opts cid
180185
pure cid
181186

182187
-- | create and upload to backend

integration/test/Test/MLS/Clients.hs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
module Test.MLS.Clients where
2+
3+
import qualified API.BrigInternal as I
4+
import MLS.Util
5+
import SetupHelpers
6+
import Testlib.Prelude
7+
8+
testGetMLSClients :: (HasCallStack) => App ()
9+
testGetMLSClients = do
10+
alice <- randomUser OwnDomain def
11+
alice1 <- createWireClient alice def
12+
13+
bindResponse (I.getMLSClients alice def) $ \resp -> do
14+
resp.status `shouldMatchInt` 200
15+
cs <- resp.json & asList
16+
c <- assertOne cs
17+
c
18+
`shouldMatch` object
19+
[ "has_key_packages" .= False,
20+
"id" .= alice1.client,
21+
"mls_signature_key" .= object []
22+
]
23+
24+
keys <- initMLSClient def alice1
25+
26+
bindResponse (I.getMLSClients alice def) $ \resp -> do
27+
resp.status `shouldMatchInt` 200
28+
cs <- resp.json & asList
29+
c <- assertOne cs
30+
c
31+
`shouldMatch` object
32+
[ "has_key_packages" .= False,
33+
"id" .= alice1.client,
34+
"mls_signature_key" .= keys
35+
]
36+
37+
void $ uploadNewKeyPackage def alice1
38+
39+
bindResponse (I.getMLSClients alice def) $ \resp -> do
40+
resp.status `shouldMatchInt` 200
41+
cs <- resp.json & asList
42+
c <- assertOne cs
43+
c
44+
`shouldMatch` object
45+
[ "has_key_packages" .= True,
46+
"id" .= alice1.client,
47+
"mls_signature_key" .= keys
48+
]
49+
50+
-- qusr <- userQualifiedId <$> randomUser brig
51+
-- c <- createClient brig qusr 0
52+
--
53+
-- let getClients :: Http (Set ClientInfo)
54+
-- getClients =
55+
-- responseJsonError
56+
-- =<< get
57+
-- ( brig
58+
-- . paths ["i", "mls", "clients", toByteString' (qUnqualified qusr)]
59+
-- . queryItem "ciphersuite" "0x0001"
60+
-- )
61+
-- <!! const 200 === statusCode
62+
--
63+
-- cs <- getClients
64+
-- liftIO $ toList cs @?= [ClientInfo c mempty False]
65+
--
66+
-- withSystemTempDirectory "mls" $ \tmp ->
67+
-- uploadKeyPackages brig tmp def qusr c 2
68+
--
69+
-- cs1 <- getClients
70+
-- liftIO $ [ClientInfo toList cs1 @?= [ClientInfo c mempty True]

services/brig/test/integration/API/Internal.hs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,6 @@ setAccountStatus brig u s =
8686
. json (AccountStatusUpdate s)
8787
)
8888

89-
testGetMlsClients :: Brig -> Http ()
90-
testGetMlsClients brig = do
91-
qusr <- userQualifiedId <$> randomUser brig
92-
c <- createClient brig qusr 0
93-
94-
let getClients :: Http (Set ClientInfo)
95-
getClients =
96-
responseJsonError
97-
=<< get
98-
( brig
99-
. paths ["i", "mls", "clients", toByteString' (qUnqualified qusr)]
100-
. queryItem "ciphersuite" "0x0001"
101-
)
102-
<!! const 200 === statusCode
103-
104-
cs0 <- getClients
105-
liftIO $ toList cs0 @?= [ClientInfo c mempty False]
106-
107-
withSystemTempDirectory "mls" $ \tmp ->
108-
uploadKeyPackages brig tmp def qusr c 2
109-
110-
cs1 <- getClients
111-
liftIO $ toList cs1 @?= [ClientInfo c mempty True]
112-
11389
createClient :: Brig -> Qualified UserId -> Int -> Http ClientId
11490
createClient brig u i =
11591
fmap ((.clientId) :: Client -> ClientId) $

0 commit comments

Comments
 (0)