matrix_sdk_test/test_json/
api_responses.rs

1//! Responses to client API calls.
2
3use once_cell::sync::Lazy;
4use serde_json::{Value as JsonValue, json};
5
6/// `GET /_matrix/client/v3/devices`
7pub static DEVICES: Lazy<JsonValue> = Lazy::new(|| {
8    json!({
9        "devices": [
10            {
11                "device_id": "BNYQQWUMXO",
12                "display_name": "Client 1",
13                "last_seen_ip": "-",
14                "last_seen_ts": 1596117733037u64,
15                "user_id": "@example:localhost"
16            },
17            {
18                "device_id": "LEBKSEUSNR",
19                "display_name": "Client 2",
20                "last_seen_ip": "-",
21                "last_seen_ts": 1599057006985u64,
22                "user_id": "@example:localhost"
23            }
24        ]
25    })
26});
27
28/// `GET /_matrix/client/v3/device/{deviceId}`
29pub static DEVICE: Lazy<JsonValue> = Lazy::new(|| {
30    json!({
31        "device_id": "QBUAZIFURK",
32        "display_name": "android",
33        "last_seen_ip": "1.2.3.4",
34        "last_seen_ts": 1474491775024u64
35    })
36});
37
38/// `GET /_matrix/client/v3/directory/room/{roomAlias}`
39pub static GET_ALIAS: Lazy<JsonValue> = Lazy::new(|| {
40    json!({
41        "room_id": "!lUbmUPdxdXxEQurqOs:example.net",
42        "servers": [
43          "example.org",
44          "example.net",
45          "matrix.org",
46        ]
47    })
48});
49
50/// `POST /_matrix/client/v3/keys/query`
51pub static KEYS_QUERY: Lazy<JsonValue> = Lazy::new(|| {
52    json!({
53      "device_keys": {
54        "@alice:example.org": {
55          "JLAFKJWSCS": {
56              "algorithms": [
57                  "m.olm.v1.curve25519-aes-sha2",
58                  "m.megolm.v1.aes-sha2"
59              ],
60              "device_id": "JLAFKJWSCS",
61              "user_id": "@alice:example.org",
62              "keys": {
63                  "curve25519:JLAFKJWSCS": "wjLpTLRqbqBzLs63aYaEv2Boi6cFEbbM/sSRQ2oAKk4",
64                  "ed25519:JLAFKJWSCS": "nE6W2fCblxDcOFmeEtCHNl8/l8bXcu7GKyAswA4r3mM"
65              },
66              "signatures": {
67                  "@alice:example.org": {
68                      "ed25519:JLAFKJWSCS": "m53Wkbh2HXkc3vFApZvCrfXcX3AI51GsDHustMhKwlv3TuOJMj4wistcOTM8q2+e/Ro7rWFUb9ZfnNbwptSUBA"
69                  }
70              },
71              "unsigned": {
72                  "device_display_name": "Alice's mobile phone"
73              }
74          }
75        }
76      },
77      "failures": {}
78    })
79});
80
81/// `POST /_matrix/client/v3/keys/query`
82/// For a set of 2 devices own by a user named web2.
83/// First device is unsigned, second one is signed
84pub static KEYS_QUERY_TWO_DEVICES_ONE_SIGNED: Lazy<JsonValue> = Lazy::new(|| {
85    json!({
86    "device_keys":{
87       "@web2:localhost:8482":{
88          "AVXFQWJUQA":{
89             "algorithms":[
90                "m.olm.v1.curve25519-aes-sha2",
91                "m.megolm.v1.aes-sha2"
92             ],
93             "device_id":"AVXFQWJUQA",
94             "keys":{
95                "curve25519:AVXFQWJUQA":"LTpv2DGMhggPAXO02+7f68CNEp6A40F0Yl8B094Y8gc",
96                "ed25519:AVXFQWJUQA":"loz5i40dP+azDtWvsD0L/xpnCjNkmrcvtXVXzCHX8Vw"
97             },
98             "signatures":{
99                "@web2:localhost:8482":{
100                   "ed25519:AVXFQWJUQA":"BmdzjXMwZaZ0ZK8T6h3pkTA+gZbD34Bzf8FNazBdAIE16fxVzrlSJkLfXnjdBqRO0Dlda5vKgGpqJazZP6obDw"
101                }
102             },
103             "user_id":"@web2:localhost:8482"
104          },
105          "JERTCKWUWG":{
106             "algorithms":[
107                "m.olm.v1.curve25519-aes-sha2",
108                "m.megolm.v1.aes-sha2"
109             ],
110             "device_id":"JERTCKWUWG",
111             "keys":{
112                "curve25519:JERTCKWUWG":"XJixbpnfIk+RqcK5T6moqVY9d9Q1veR8WjjSlNiQNT0",
113                "ed25519:JERTCKWUWG":"48f3WQAMGwYLBg5M5qUhqnEVA8yeibjZpPsShoWMFT8"
114             },
115             "signatures":{
116                "@web2:localhost:8482":{
117                   "ed25519:JERTCKWUWG":"Wc67XYem4IKCpshcslQ6ketCE5otubpX+Bh01OB8ghLxl1d6exlZsgaRA57N8RJ0EMvbeTWCweHXXC/UeeQ4DQ",
118                   "ed25519:uXOM0Xlfts9SGysk/yNr0Vn9rgv1Ifh3R8oPhtic4BM":"dto9VPhhJbNw62j8NQyjnwukMd1NtYnDYSoUOzD5dABq1u2Kt/ZdthcTO42HyxG/3/hZdno8XPfJ47l1ZxuXBA"
119                }
120             },
121             "user_id":"@web2:localhost:8482"
122          }
123       }
124    },
125    "failures":{
126
127    },
128    "master_keys":{
129       "@web2:localhost:8482":{
130          "user_id":"@web2:localhost:8482",
131          "usage":[
132             "master"
133          ],
134          "keys":{
135             "ed25519:Ct4QR+aXrzW4iYIgH1B/56NkPEtSPoN+h2TGoQ0xxYI":"Ct4QR+aXrzW4iYIgH1B/56NkPEtSPoN+h2TGoQ0xxYI"
136          },
137          "signatures":{
138             "@web2:localhost:8482":{
139                "ed25519:JERTCKWUWG":"H9hEsUJ+alB5XAboDzU4loVb+SZajC4tsQzGaeU/FHMFAnWeVarTMCR+NmPSGsZfvPrNz2WVS2G7FIH5yhJfBg"
140             }
141          }
142       }
143    },
144    "self_signing_keys":{
145       "@web2:localhost:8482":{
146          "user_id":"@web2:localhost:8482",
147          "usage":[
148             "self_signing"
149          ],
150          "keys":{
151             "ed25519:uXOM0Xlfts9SGysk/yNr0Vn9rgv1Ifh3R8oPhtic4BM":"uXOM0Xlfts9SGysk/yNr0Vn9rgv1Ifh3R8oPhtic4BM"
152          },
153          "signatures":{
154             "@web2:localhost:8482":{
155                "ed25519:Ct4QR+aXrzW4iYIgH1B/56NkPEtSPoN+h2TGoQ0xxYI":"YbD6gTEwY078nllTxmlyea2VNvAElQ/ig7aPsyhA3h1gGwFvPdtyDbomjdIphUF/lXQ+Eyz4SzlUWeghr1b3BA"
156             }
157          }
158       }
159    },
160    "user_signing_keys":{
161
162    }
163     })
164});
165
166/// ``
167pub static KEYS_UPLOAD: Lazy<JsonValue> = Lazy::new(|| {
168    json!({
169      "one_time_key_counts": {
170        "curve25519": 10,
171        "signed_curve25519": 20
172      }
173    })
174});
175
176/// Successful call to `POST /_matrix/client/v3/login` without auto-discovery.
177pub static LOGIN: Lazy<JsonValue> = Lazy::new(|| {
178    json!({
179        "access_token": "abc123",
180        "device_id": "GHTYAJCE",
181        "home_server": "matrix.org",
182        "user_id": "@cheeky_monkey:matrix.org"
183    })
184});
185
186/// Successful call to `POST /_matrix/client/v3/login` with auto-discovery.
187pub static LOGIN_WITH_DISCOVERY: Lazy<JsonValue> = Lazy::new(|| {
188    json!({
189        "access_token": "abc123",
190        "device_id": "GHTYAJCE",
191        "home_server": "matrix.org",
192        "user_id": "@cheeky_monkey:matrix.org",
193        "well_known": {
194            "m.homeserver": {
195                "base_url": "https://example.org"
196            },
197            "m.identity_server": {
198                "base_url": "https://id.example.org"
199            }
200        }
201    })
202});
203
204/// Successful call to `POST /_matrix/client/v3/login` with a refresh token.
205pub static LOGIN_WITH_REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
206    json!({
207        "access_token": "abc123",
208        "device_id": "GHTYAJCE",
209        "home_server": "matrix.org",
210        "user_id": "@cheeky_monkey:matrix.org",
211        "expires_in_ms": 432000000,
212        "refresh_token": "zyx987",
213    })
214});
215
216/// Failed call to `POST /_matrix/client/v3/login`
217pub static LOGIN_RESPONSE_ERR: Lazy<JsonValue> = Lazy::new(|| {
218    json!({
219      "errcode": "M_FORBIDDEN",
220      "error": "Invalid password"
221    })
222});
223
224/// `GET /_matrix/client/v3/login`
225pub static LOGIN_TYPES: Lazy<JsonValue> = Lazy::new(|| {
226    json!({
227        "flows": [
228            {
229                "type": "m.login.password"
230            },
231            {
232                "type": "m.login.sso"
233            },
234            {
235                "type": "m.login.token"
236            }
237        ]
238    })
239});
240
241/// Failed call to an endpoint when the resource that was asked could not be
242/// found.
243pub static NOT_FOUND: Lazy<JsonValue> = Lazy::new(|| {
244    json!({
245      "errcode": "M_NOT_FOUND",
246      "error": "No resource was found for this request.",
247      "soft_logout": true,
248    })
249});
250
251/// `GET /_matrix/client/v3/publicRooms`
252/// `POST /_matrix/client/v3/publicRooms`
253pub static PUBLIC_ROOMS: Lazy<JsonValue> = Lazy::new(|| {
254    json!({
255        "chunk": [
256            {
257                "aliases": [
258                    "#murrays:cheese.bar"
259                ],
260                "avatar_url": "mxc://bleeker.street/CHEDDARandBRIE",
261                "guest_can_join": false,
262                "name": "CHEESE",
263                "num_joined_members": 37,
264                "room_id": "!ol19s:bleecker.street",
265                "topic": "Tasty tasty cheese",
266                "world_readable": true
267            }
268        ],
269        "next_batch": "p190q",
270        "prev_batch": "p1902",
271        "total_room_count_estimate": 115
272    })
273});
274
275/// `GET /_matrix/client/v3/publicRooms`
276/// `POST /_matrix/client/v3/publicRooms``
277pub static PUBLIC_ROOMS_FINAL_PAGE: Lazy<JsonValue> = Lazy::new(|| {
278    json!({
279        "chunk": [
280            {
281                "canonical_alias": "#murrays:pear.bar",
282                "avatar_url": "mxc://bleeker.street/pear",
283                "guest_can_join": false,
284                "name": "PEAR",
285                "num_joined_members": 20,
286                "room_id": "!ca18r:bleecker.street",
287                "topic": "Tasty tasty pear",
288                "world_readable": false,
289                "join_rule": "knock"
290            }
291        ],
292        "prev_batch": "p190q",
293        "total_room_count_estimate": 115
294    })
295});
296
297/// `POST /_matrix/client/v3/refresh` without new refresh token.
298pub static REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
299    json!({
300      "access_token": "5678",
301      "expire_in_ms": 432000000,
302    })
303});
304
305/// `POST /_matrix/client/v3/refresh` with a new refresh token.
306pub static REFRESH_TOKEN_WITH_REFRESH_TOKEN: Lazy<JsonValue> = Lazy::new(|| {
307    json!({
308      "access_token": "9012",
309      "expire_in_ms": 432000000,
310      "refresh_token": "wxyz",
311    })
312});
313
314/// Failed call to `POST /_matrix/client/v3/register`
315pub static REGISTRATION_RESPONSE_ERR: Lazy<JsonValue> = Lazy::new(|| {
316    json!({
317        "errcode": "M_FORBIDDEN",
318        "error": "Invalid password",
319        "completed": ["example.type.foo"],
320        "flows": [
321            {
322                "stages": ["example.type.foo", "example.type.bar"]
323            },
324            {
325                "stages": ["example.type.foo", "example.type.baz"]
326            }
327        ],
328        "params": {
329            "example.type.baz": {
330                "example_key": "foobar"
331            }
332        },
333        "session": "xxxxxx"
334    })
335});
336
337/// Failed called to any endpoint with an expired access token.
338pub static UNKNOWN_TOKEN_SOFT_LOGOUT: Lazy<JsonValue> = Lazy::new(|| {
339    json!({
340      "errcode": "M_UNKNOWN_TOKEN",
341      "error": "Invalid access token passed.",
342      "soft_logout": true,
343    })
344});
345
346/// `GET /_matrix/client/versions`
347pub static VERSIONS: Lazy<JsonValue> = Lazy::new(|| {
348    json!({
349        "versions": [
350            "r0.0.1",
351            "r0.1.0",
352            "r0.2.0",
353            "r0.3.0",
354            "r0.4.0",
355            "r0.5.0",
356            "r0.6.0"
357        ],
358        "unstable_features": {
359            "org.matrix.label_based_filtering": true,
360            "org.matrix.e2e_cross_signing": true,
361            "org.matrix.msc4028": true,
362            "org.matrix.simplified_msc3575": true,
363        }
364    })
365});
366
367/// `GET /.well-known/matrix/client`
368pub static WELL_KNOWN: Lazy<JsonValue> = Lazy::new(|| {
369    json!({
370        "m.homeserver": {
371            "base_url": "HOMESERVER_URL"
372        },
373        "m.rtc_foci": [
374            {
375                "type": "livekit",
376                "livekit_service_url": "https://livekit.example.com",
377            }
378        ]
379    })
380});
381
382/// `GET /_matrix/client/v3/account/whoami`
383pub static WHOAMI: Lazy<JsonValue> = Lazy::new(|| {
384    json!({
385        "user_id": "@joe:example.org"
386    })
387});