Skip to content

Commit 5c1323c

Browse files
pcapriottistefanwire
authored andcommitted
Port MLS test framework to new integration suite (#3288)
* Initial import of MLS test framework * Add subconversation utilities to integration suite * Add more utilities * Add self conversation utilities --------- Co-authored-by: Stefan Berthold <[email protected]>
1 parent a20d8d4 commit 5c1323c

File tree

14 files changed

+898
-35
lines changed

14 files changed

+898
-35
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Port MLS test framework to new integration suite

integration/default.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
, array
99
, async
1010
, base
11+
, base64-bytestring
1112
, bytestring
1213
, bytestring-conversion
1314
, Cabal
@@ -18,8 +19,10 @@
1819
, exceptions
1920
, filepath
2021
, gitignoreSource
22+
, hex
2123
, http-client
2224
, http-types
25+
, kan-extensions
2326
, lib
2427
, mtl
2528
, network
@@ -34,10 +37,13 @@
3437
, stm
3538
, string-conversions
3639
, tagged
40+
, temporary
3741
, text
3842
, time
3943
, transformers
44+
, unix
4045
, unliftio
46+
, uuid
4147
, websockets
4248
, yaml
4349
}:
@@ -54,6 +60,7 @@ mkDerivation {
5460
array
5561
async
5662
base
63+
base64-bytestring
5764
bytestring
5865
bytestring-conversion
5966
case-insensitive
@@ -62,8 +69,10 @@ mkDerivation {
6269
directory
6370
exceptions
6471
filepath
72+
hex
6573
http-client
6674
http-types
75+
kan-extensions
6776
mtl
6877
network
6978
network-uri
@@ -77,10 +86,13 @@ mkDerivation {
7786
stm
7887
string-conversions
7988
tagged
89+
temporary
8090
text
8191
time
8292
transformers
93+
unix
8394
unliftio
95+
uuid
8496
websockets
8597
yaml
8698
];

integration/integration.cabal

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ library
8484
API.Common
8585
API.Galley
8686
API.GalleyInternal
87+
MLS.Util
8788
RunAllTests
8889
SetupHelpers
8990
Test.B2B
@@ -109,6 +110,7 @@ library
109110
, array
110111
, async
111112
, base
113+
, base64-bytestring
112114
, bytestring
113115
, bytestring-conversion
114116
, case-insensitive
@@ -117,8 +119,10 @@ library
117119
, directory
118120
, exceptions
119121
, filepath
122+
, hex
120123
, http-client
121124
, http-types
125+
, kan-extensions
122126
, mtl
123127
, network
124128
, network-uri
@@ -132,9 +136,12 @@ library
132136
, stm
133137
, string-conversions
134138
, tagged
139+
, temporary
135140
, text
136141
, time
137142
, transformers
143+
, unix
138144
, unliftio
145+
, uuid
139146
, websockets
140147
, yaml

integration/test/API/Brig.hs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
module API.Brig where
22

33
import API.Common
4+
import qualified Data.ByteString.Base64 as Base64
5+
import Data.Foldable
46
import Data.Function
57
import Data.Maybe
8+
import qualified Data.Text.Encoding as T
69
import GHC.Stack
710
import Testlib.Prelude
811

@@ -49,6 +52,43 @@ addClient user args = do
4952
"password" .= args.password
5053
]
5154

55+
data UpdateClient = UpdateClient
56+
{ prekeys :: [Value],
57+
lastPrekey :: Maybe Value,
58+
label :: Maybe String,
59+
capabilities :: Maybe [Value],
60+
mlsPublicKeys :: Maybe Value
61+
}
62+
63+
instance Default UpdateClient where
64+
def =
65+
UpdateClient
66+
{ prekeys = [],
67+
lastPrekey = Nothing,
68+
label = Nothing,
69+
capabilities = Nothing,
70+
mlsPublicKeys = Nothing
71+
}
72+
73+
updateClient ::
74+
HasCallStack =>
75+
ClientIdentity ->
76+
UpdateClient ->
77+
App Response
78+
updateClient cid args = do
79+
uid <- objId cid
80+
req <- baseRequest cid Brig Versioned $ "/clients/" <> cid.client
81+
submit "PUT" $
82+
req
83+
& zUser uid
84+
& addJSONObject
85+
( ["prekeys" .= args.prekeys]
86+
<> ["lastkey" .= k | k <- toList args.lastPrekey]
87+
<> ["label" .= l | l <- toList args.label]
88+
<> ["capabilities" .= c | c <- toList args.capabilities]
89+
<> ["mls_public_keys" .= k | k <- toList args.mlsPublicKeys]
90+
)
91+
5292
deleteClient ::
5393
(HasCallStack, MakesValue user, MakesValue client) =>
5494
user ->
@@ -137,3 +177,25 @@ putConnection userFrom userTo status = do
137177
& contentTypeJSON
138178
& addJSONObject ["status" .= statusS]
139179
)
180+
181+
uploadKeyPackage :: ClientIdentity -> ByteString -> App Response
182+
uploadKeyPackage cid kp = do
183+
req <-
184+
baseRequest cid Brig Versioned $
185+
"/mls/key-packages/self/" <> cid.client
186+
uid <- objId cid
187+
submit
188+
"POST"
189+
( req
190+
& zUser uid
191+
& addJSONObject ["key_packages" .= [T.decodeUtf8 (Base64.encode kp)]]
192+
)
193+
194+
claimKeyPackages :: (MakesValue u, MakesValue v) => u -> v -> App Response
195+
claimKeyPackages u v = do
196+
(targetDom, targetUid) <- objQid v
197+
req <-
198+
baseRequest u Brig Versioned $
199+
"/mls/key-packages/claim/" <> targetDom <> "/" <> targetUid
200+
uid <- objId u
201+
submit "POST" (req & zUser uid)

integration/test/API/Galley.hs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,87 @@ getConversation user qcnv = do
116116
( req
117117
& zUser uid
118118
)
119+
120+
getSubConversation ::
121+
( HasCallStack,
122+
MakesValue user,
123+
MakesValue conv
124+
) =>
125+
user ->
126+
conv ->
127+
String ->
128+
App Response
129+
getSubConversation user conv sub = do
130+
uid <- objId user
131+
(cnvDomain, cnvId) <- objQid conv
132+
req <-
133+
baseRequest user Galley Versioned $
134+
joinHttpPath
135+
[ "conversations",
136+
cnvDomain,
137+
cnvId,
138+
"subconversations",
139+
sub
140+
]
141+
submit "GET" $ req & zUser uid
142+
143+
getSelfConversation :: (HasCallStack, MakesValue user) => user -> App Response
144+
getSelfConversation user = do
145+
uid <- objId user
146+
req <- baseRequest user Galley Versioned "/conversations/mls-self"
147+
submit "GET" $ req & zUser uid & zConnection "conn"
148+
149+
data ListConversationIds = ListConversationIds {pagingState :: Maybe String, size :: Maybe Int}
150+
151+
instance Default ListConversationIds where
152+
def = ListConversationIds Nothing Nothing
153+
154+
listConversationIds :: MakesValue user => user -> ListConversationIds -> App Response
155+
listConversationIds user args = do
156+
req <- baseRequest user Galley Versioned "/conversations/list-ids"
157+
uid <- objId user
158+
submit "POST" $
159+
req
160+
& zUser uid
161+
& addJSONObject
162+
( ["paging_state" .= s | s <- toList args.pagingState]
163+
<> ["size" .= s | s <- toList args.size]
164+
)
165+
166+
listConversations :: MakesValue user => user -> [Value] -> App Response
167+
listConversations user cnvs = do
168+
req <- baseRequest user Galley Versioned "/conversations/list"
169+
uid <- objId user
170+
submit "POST" $
171+
req
172+
& zUser uid
173+
& addJSONObject ["qualified_ids" .= cnvs]
174+
175+
postMLSMessage :: HasCallStack => ClientIdentity -> ByteString -> App Response
176+
postMLSMessage cid msg = do
177+
req <- baseRequest cid Galley Versioned "/mls/messages"
178+
uid <- objId cid
179+
c <- cid %. "client" & asString
180+
submit "POST" (addMLS msg req & zUser uid & zClient c & zConnection "conn")
181+
182+
postMLSCommitBundle :: HasCallStack => ClientIdentity -> ByteString -> App Response
183+
postMLSCommitBundle cid msg = do
184+
req <- baseRequest cid Galley Versioned "/mls/commit-bundles"
185+
uid <- objId cid
186+
c <- cid %. "client_id" & asString
187+
submit "POST" (addMLS msg req & zUser uid & zClient c & zConnection "conn")
188+
189+
getGroupInfo ::
190+
(HasCallStack, MakesValue user, MakesValue conv) =>
191+
user ->
192+
conv ->
193+
App Response
194+
getGroupInfo user conv = do
195+
(qcnv, mSub) <- objSubConv conv
196+
(convDomain, convId) <- objQid qcnv
197+
let path = joinHttpPath $ case mSub of
198+
Nothing -> ["conversations", convDomain, convId, "groupinfo"]
199+
Just sub -> ["conversations", convDomain, convId, "subconversations", sub, "groupinfo"]
200+
req <- baseRequest user Galley Versioned path
201+
uid <- objId user
202+
submit "GET" (req & zUser uid & zConnection "conn")

0 commit comments

Comments
 (0)