@@ -48,77 +48,72 @@ func TestFederationKeyUploadQuery(t *testing.T) {
48
48
},
49
49
})
50
50
51
- t .Run ("Parallel" , func (t * testing.T ) {
52
- // sytest: Can claim remote one time key using POST
53
- t .Run ("Can claim remote one time key using POST" , func (t * testing.T ) {
54
- t .Parallel ()
55
- // check keys on remote server
56
- reqBody = client .WithJSONBody (t , map [string ]interface {}{
57
- "one_time_keys" : map [string ]interface {}{
58
- alice .UserID : map [string ]string {
59
- alice .DeviceID : "signed_curve25519" ,
60
- },
51
+ // sytest: Can claim remote one time key using POST
52
+ t .Run ("Can claim remote one time key using POST" , func (t * testing.T ) {
53
+ // check keys on remote server
54
+ reqBody = client .WithJSONBody (t , map [string ]interface {}{
55
+ "one_time_keys" : map [string ]interface {}{
56
+ alice .UserID : map [string ]string {
57
+ alice .DeviceID : "signed_curve25519" ,
61
58
},
62
- })
63
- resp = bob . MustDoFunc ( t , "POST" , [] string { "_matrix" , "client" , "v3" , "keys" , "claim" }, reqBody )
64
- otksField := "one_time_keys." + client . GjsonEscape ( alice . UserID ) + "." + client . GjsonEscape ( alice . DeviceID )
65
- must . MatchResponse ( t , resp , match. HTTPResponse {
66
- StatusCode : http . StatusOK ,
67
- JSON : []match. JSON {
68
- match .JSONKeyTypeEqual ( otksField , gjson . JSON ),
69
- match .JSONKeyEqual (otksField , oneTimeKeys ),
70
- } ,
71
- })
72
-
73
- // there should be no OTK left now
74
- resp = bob . MustDoFunc ( t , "POST" , [] string { "_matrix" , "client" , "v3" , "keys" , "claim" }, reqBody )
75
- must . MatchResponse (t , resp , match. HTTPResponse {
76
- StatusCode : http . StatusOK ,
77
- JSON : []match. JSON {
78
- match .JSONKeyMissing ( "one_time_keys." + client . GjsonEscape ( alice . UserID )),
79
- } ,
80
- })
59
+ },
60
+ } )
61
+ resp = bob . MustDoFunc ( t , "POST" , [] string { "_matrix" , " client" , "v3" , "keys" , "claim" }, reqBody )
62
+ otksField := "one_time_keys." + client . GjsonEscape ( alice . UserID ) + "." + client . GjsonEscape ( alice . DeviceID )
63
+ must . MatchResponse ( t , resp , match. HTTPResponse {
64
+ StatusCode : http . StatusOK ,
65
+ JSON : [] match.JSON {
66
+ match .JSONKeyTypeEqual (otksField , gjson . JSON ),
67
+ match . JSONKeyEqual ( otksField , oneTimeKeys ) ,
68
+ },
69
+ })
70
+
71
+ // there should be no OTK left now
72
+ resp = bob . MustDoFunc (t , "POST" , [] string { "_matrix" , "client" , "v3" , "keys" , "claim" }, reqBody )
73
+ must . MatchResponse ( t , resp , match. HTTPResponse {
74
+ StatusCode : http . StatusOK ,
75
+ JSON : [] match.JSON {
76
+ match . JSONKeyMissing ( "one_time_keys." + client . GjsonEscape ( alice . UserID )) ,
77
+ },
81
78
})
79
+ })
82
80
83
- // sytest: Can query remote device keys using POST
84
- t .Run ("Can query remote device keys using POST" , func (t * testing.T ) {
85
- t .Parallel ()
86
-
87
- displayName := "My new displayname"
88
- body := client .WithJSONBody (t , map [string ]interface {}{
89
- "display_name" : displayName ,
90
- })
91
- alice .MustDoFunc (t , http .MethodPut , []string {"_matrix" , "client" , "v3" , "devices" , alice .DeviceID }, body )
92
- // wait for bob to receive the displayname change
93
- bob .MustSyncUntil (t , client.SyncReq {}, func (clientUserID string , topLevelSyncJSON gjson.Result ) error {
94
- devicesChanged := topLevelSyncJSON .Get ("device_lists.changed" )
95
- if devicesChanged .Exists () {
96
- for _ , userID := range devicesChanged .Array () {
97
- if userID .Str == alice .UserID {
98
- return nil
99
- }
81
+ // sytest: Can query remote device keys using POST
82
+ t .Run ("Can query remote device keys using POST" , func (t * testing.T ) {
83
+ displayName := "My new displayname"
84
+ body := client .WithJSONBody (t , map [string ]interface {}{
85
+ "display_name" : displayName ,
86
+ })
87
+ alice .MustDoFunc (t , http .MethodPut , []string {"_matrix" , "client" , "v3" , "devices" , alice .DeviceID }, body )
88
+ // wait for bob to receive the displayname change
89
+ bob .MustSyncUntil (t , client.SyncReq {}, func (clientUserID string , topLevelSyncJSON gjson.Result ) error {
90
+ devicesChanged := topLevelSyncJSON .Get ("device_lists.changed" )
91
+ if devicesChanged .Exists () {
92
+ for _ , userID := range devicesChanged .Array () {
93
+ if userID .Str == alice .UserID {
94
+ return nil
100
95
}
101
96
}
102
- return fmt . Errorf ( "no device_lists found" )
103
- } )
104
- reqBody = client . WithJSONBody ( t , map [ string ] interface {}{
105
- "device_keys" : map [string ]interface {}{
106
- alice . UserID : [] string {},
107
- },
108
- })
109
- resp = bob . MustDoFunc ( t , "POST" , [] string { "_matrix" , "client" , "v3" , "keys" , "query" }, reqBody )
110
- deviceKeysField := "device_keys." + client . GjsonEscape ( alice . UserID ) + "." + client . GjsonEscape ( alice . DeviceID )
111
-
112
- must . MatchResponse ( t , resp , match. HTTPResponse {
113
- StatusCode : http . StatusOK ,
114
- JSON : []match. JSON {
115
- match .JSONKeyTypeEqual ( deviceKeysField , gjson . JSON ),
116
- match .JSONKeyEqual (deviceKeysField + ".algorithms" , deviceKeys [ "algorithms" ] ),
117
- match .JSONKeyEqual (deviceKeysField + ".keys " , deviceKeys ["keys " ]),
118
- match .JSONKeyEqual (deviceKeysField + ".signatures " , deviceKeys ["signatures " ]),
119
- match .JSONKeyEqual (deviceKeysField + ".unsigned.device_display_name " , displayName ),
120
- } ,
121
- })
97
+ }
98
+ return fmt . Errorf ( "no device_lists found" )
99
+ })
100
+ reqBody = client . WithJSONBody ( t , map [string ]interface {}{
101
+ "device_keys" : map [ string ] interface {}{
102
+ alice . UserID : [] string { },
103
+ },
104
+ } )
105
+ resp = bob . MustDoFunc ( t , "POST" , [] string { "_matrix" , " client" , "v3" , "keys" , "query" }, reqBody )
106
+ deviceKeysField := "device_keys." + client . GjsonEscape ( alice . UserID ) + "." + client . GjsonEscape ( alice . DeviceID )
107
+
108
+ must . MatchResponse ( t , resp , match. HTTPResponse {
109
+ StatusCode : http . StatusOK ,
110
+ JSON : [] match.JSON {
111
+ match .JSONKeyTypeEqual (deviceKeysField , gjson . JSON ),
112
+ match .JSONKeyEqual (deviceKeysField + ".algorithms " , deviceKeys ["algorithms " ]),
113
+ match .JSONKeyEqual (deviceKeysField + ".keys " , deviceKeys ["keys " ]),
114
+ match .JSONKeyEqual (deviceKeysField + ".signatures " , deviceKeys [ "signatures" ] ),
115
+ match . JSONKeyEqual ( deviceKeysField + ".unsigned.device_display_name" , displayName ) ,
116
+ },
122
117
})
123
118
})
124
119
}
0 commit comments