@@ -396,12 +396,18 @@ func (c *CSAPI) GetDefaultRoomVersion(t ct.TestLike) gomatrixserverlib.RoomVersi
396
396
return gomatrixserverlib .RoomVersion (defaultVersion .Str )
397
397
}
398
398
399
+ // MustUploadKeys uploads device and/or one time keys to the server, returning the current OTK counts.
400
+ // Both device keys and one time keys are optional. Fails the test if the upload fails.
399
401
func (c * CSAPI ) MustUploadKeys (t ct.TestLike , deviceKeys map [string ]interface {}, oneTimeKeys map [string ]interface {}) (otkCounts map [string ]int ) {
400
402
t .Helper ()
401
- res := c .MustDo (t , "POST" , []string {"_matrix" , "client" , "v3" , "keys" , "upload" }, WithJSONBody (t , map [string ]interface {}{
402
- "device_keys" : deviceKeys ,
403
- "one_time_keys" : oneTimeKeys ,
404
- }))
403
+ reqBody := make (map [string ]interface {})
404
+ if deviceKeys != nil {
405
+ reqBody ["device_keys" ] = deviceKeys
406
+ }
407
+ if oneTimeKeys != nil {
408
+ reqBody ["one_time_keys" ] = oneTimeKeys
409
+ }
410
+ res := c .MustDo (t , "POST" , []string {"_matrix" , "client" , "v3" , "keys" , "upload" }, WithJSONBody (t , reqBody ))
405
411
bodyBytes := ParseJSON (t , res )
406
412
s := struct {
407
413
OTKCounts map [string ]int `json:"one_time_key_counts"`
@@ -492,6 +498,20 @@ func (c *CSAPI) MustGenerateOneTimeKeys(t ct.TestLike, otkCount uint) (deviceKey
492
498
return deviceKeys , oneTimeKeys
493
499
}
494
500
501
+ // MustSetDisplayName sets the global display name for this account or fails the test.
502
+ func (c * CSAPI ) MustSetDisplayName (t ct.TestLike , displayname string ) {
503
+ c .MustDo (t , "PUT" , []string {"_matrix" , "client" , "v3" , "profile" , c .UserID , "displayname" }, WithJSONBody (t , map [string ]any {
504
+ "displayname" : displayname ,
505
+ }))
506
+ }
507
+
508
+ // MustGetDisplayName returns the global display name for this user or fails the test.
509
+ func (c * CSAPI ) MustGetDisplayName (t ct.TestLike , userID string ) string {
510
+ res := c .MustDo (t , "GET" , []string {"_matrix" , "client" , "v3" , "profile" , userID , "displayname" })
511
+ body := ParseJSON (t , res )
512
+ return GetJSONFieldStr (t , body , "displayname" )
513
+ }
514
+
495
515
// WithRawBody sets the HTTP request body to `body`
496
516
func WithRawBody (body []byte ) RequestOpt {
497
517
return func (req * http.Request ) {
0 commit comments