matrix_sdk_test/test_json/
api_responses.rs

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