1- // +build msc2946,msc3083
1+ // +build msc2946,!dendrite_blacklist
22
3- // Tests MSC3083, an experimental feature for joining restricted rooms based on
4- // membership in a space.
3+ // Tests MSC3083, joining restricted rooms based on membership in another room.
54
65package tests
76
@@ -35,21 +34,19 @@ func failJoinRoom(t *testing.T, c *client.CSAPI, roomIDOrAlias string, serverNam
3534 })
3635}
3736
38- // Create a space and put a room in it which is set to:
39- // * The experimental room version.
40- // * restricted join rules with allow set to the space.
37+ // Creates two rooms on room version 8 and sets the second room to have
38+ // restricted join rules with allow set to the first room.
4139func setupRestrictedRoom (t * testing.T , deployment * docker.Deployment ) (* client.CSAPI , string , string ) {
4240 t .Helper ()
4341
4442 alice := deployment .Client (t , "hs1" , "@alice:hs1" )
45- space := alice .CreateRoom (t , map [string ]interface {}{
43+ // The room which membership checks are delegated to. In practice, this will
44+ // often be an MSC1772 space, but that is not required.
45+ allowed_room := alice .CreateRoom (t , map [string ]interface {}{
4646 "preset" : "public_chat" ,
47- "name" : "Space" ,
48- "creation_content" : map [string ]interface {}{
49- "type" : "m.space" ,
50- },
47+ "name" : "Allowed Room" ,
5148 })
52- // The room is an unstable room version which supports the restricted join_rule.
49+ // The room is room version 8 which supports the restricted join_rule.
5350 room := alice .CreateRoom (t , map [string ]interface {}{
5451 "preset" : "public_chat" ,
5552 "name" : "Room" ,
@@ -63,45 +60,38 @@ func setupRestrictedRoom(t *testing.T, deployment *docker.Deployment) (*client.C
6360 "allow" : []map [string ]interface {}{
6461 {
6562 "type" : "m.room_membership" ,
66- "room_id" : & space ,
63+ "room_id" : & allowed_room ,
6764 "via" : []string {"hs1" },
6865 },
6966 },
7067 },
7168 },
7269 },
7370 })
74- alice .SendEventSynced (t , space , b.Event {
75- Type : "m.space.child" ,
76- StateKey : & room ,
77- Content : map [string ]interface {}{
78- "via" : []string {"hs1" },
79- },
80- })
8171
82- return alice , space , room
72+ return alice , allowed_room , room
8373}
8474
85- func checkRestrictedRoom (t * testing.T , alice * client.CSAPI , bob * client.CSAPI , space string , room string ) {
75+ func checkRestrictedRoom (t * testing.T , alice * client.CSAPI , bob * client.CSAPI , allowed_room string , room string ) {
8676 t .Helper ()
8777
8878 failJoinRoom (t , bob , room , "hs1" , 403 )
8979
90- // Join the space , attempt to join the room again, which now should succeed.
91- bob .JoinRoom (t , space , []string {"hs1" })
80+ // Join the allowed room , attempt to join the room again, which now should succeed.
81+ bob .JoinRoom (t , allowed_room , []string {"hs1" })
9282 bob .JoinRoom (t , room , []string {"hs1" })
9383
9484 // Joining the same room again should work fine (e.g. to change your display name).
9585 bob .JoinRoom (t , room , []string {"hs1" })
9686
9787 // Leaving the room works and the user is unable to re-join.
9888 bob .LeaveRoom (t , room )
99- bob .LeaveRoom (t , space )
89+ bob .LeaveRoom (t , allowed_room )
10090
101- // Wait until Alice sees Bob leave the space . This ensures that Alice's HS
91+ // Wait until Alice sees Bob leave the allowed room . This ensures that Alice's HS
10292 // has processed the leave before Bob tries rejoining, so that it rejects his
10393 // attempt to join the room.
104- alice .SyncUntilTimelineHas (t , space , func (ev gjson.Result ) bool {
94+ alice .SyncUntilTimelineHas (t , allowed_room , func (ev gjson.Result ) bool {
10595 if ev .Get ("type" ).Str != "m.room.member" || ev .Get ("sender" ).Str != bob .UserID {
10696 return false
10797 }
@@ -115,9 +105,9 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, s
115105 alice .InviteRoom (t , room , bob .UserID )
116106 bob .JoinRoom (t , room , []string {"hs1" })
117107
118- // Leave the room again, and join the space .
108+ // Leave the room again, and join the allowed room .
119109 bob .LeaveRoom (t , room )
120- bob .JoinRoom (t , space , []string {"hs1" })
110+ bob .JoinRoom (t , allowed_room , []string {"hs1" })
121111
122112 // Update the room to have bad values in the "allow" field, which should stop
123113 // joining from working properly.
@@ -155,34 +145,34 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, s
155145 failJoinRoom (t , bob , room , "hs1" , 403 )
156146}
157147
158- // Test joining a room with join rules restricted to membership in a space .
148+ // Test joining a room with join rules restricted to membership in another room .
159149func TestRestrictedRoomsLocalJoin (t * testing.T ) {
160150 deployment := Deploy (t , b .BlueprintOneToOneRoom )
161151 defer deployment .Destroy (t )
162152
163- // Setup the user, space , and restricted room.
164- alice , space , room := setupRestrictedRoom (t , deployment )
153+ // Setup the user, allowed room , and restricted room.
154+ alice , allowed_room , room := setupRestrictedRoom (t , deployment )
165155
166156 // Create a second user on the same homeserver.
167157 bob := deployment .Client (t , "hs1" , "@bob:hs1" )
168158
169159 // Execute the checks.
170- checkRestrictedRoom (t , alice , bob , space , room )
160+ checkRestrictedRoom (t , alice , bob , allowed_room , room )
171161}
172162
173- // Test joining a room with join rules restricted to membership in a space .
163+ // Test joining a room with join rules restricted to membership in another room .
174164func TestRestrictedRoomsRemoteJoin (t * testing.T ) {
175165 deployment := Deploy (t , b .BlueprintFederationOneToOneRoom )
176166 defer deployment .Destroy (t )
177167
178- // Setup the user, space , and restricted room.
179- alice , space , room := setupRestrictedRoom (t , deployment )
168+ // Setup the user, allowed room , and restricted room.
169+ alice , allowed_room , room := setupRestrictedRoom (t , deployment )
180170
181171 // Create a second user on a different homeserver.
182172 bob := deployment .Client (t , "hs2" , "@bob:hs2" )
183173
184174 // Execute the checks.
185- checkRestrictedRoom (t , alice , bob , space , room )
175+ checkRestrictedRoom (t , alice , bob , allowed_room , room )
186176}
187177
188178// A server will do a remote join for a local user if it is unable to to issue
@@ -191,16 +181,16 @@ func TestRestrictedRoomsRemoteJoinLocalUser(t *testing.T) {
191181 deployment := Deploy (t , b .BlueprintFederationTwoLocalOneRemote )
192182 defer deployment .Destroy (t )
193183
194- // Charlie sets up the space so it is on the other server.
184+ // Charlie sets up the allowed room so it is on the other server.
185+ //
186+ // This is the room which membership checks are delegated to. In practice,
187+ // this will often be an MSC1772 space, but that is not required.
195188 charlie := deployment .Client (t , "hs2" , "@charlie:hs2" )
196- space := charlie .CreateRoom (t , map [string ]interface {}{
189+ allowed_room := charlie .CreateRoom (t , map [string ]interface {}{
197190 "preset" : "public_chat" ,
198191 "name" : "Space" ,
199- "creation_content" : map [string ]interface {}{
200- "type" : "m.space" ,
201- },
202192 })
203- // The room is an unstable room version which supports the restricted join_rule.
193+ // The room is room version 8 which supports the restricted join_rule.
204194 room := charlie .CreateRoom (t , map [string ]interface {}{
205195 "preset" : "public_chat" ,
206196 "name" : "Room" ,
@@ -214,21 +204,14 @@ func TestRestrictedRoomsRemoteJoinLocalUser(t *testing.T) {
214204 "allow" : []map [string ]interface {}{
215205 {
216206 "type" : "m.room_membership" ,
217- "room_id" : & space ,
207+ "room_id" : & allowed_room ,
218208 "via" : []string {"hs2" },
219209 },
220210 },
221211 },
222212 },
223213 },
224214 })
225- charlie .SendEventSynced (t , space , b.Event {
226- Type : "m.space.child" ,
227- StateKey : & room ,
228- Content : map [string ]interface {}{
229- "via" : []string {"hs2" },
230- },
231- })
232215
233216 // Invite alice manually and accept it.
234217 alice := deployment .Client (t , "hs1" , "@alice:hs1" )
@@ -253,8 +236,8 @@ func TestRestrictedRoomsRemoteJoinLocalUser(t *testing.T) {
253236 // Bob cannot join the room.
254237 failJoinRoom (t , bob , room , "hs1" , 403 )
255238
256- // Join the space via hs2.
257- bob .JoinRoom (t , space , []string {"hs2" })
239+ // Join the allowed room via hs2.
240+ bob .JoinRoom (t , allowed_room , []string {"hs2" })
258241 // Joining the room should work, although we're joining via hs1, it will end up
259242 // as a remote join through hs2.
260243 bob .JoinRoom (t , room , []string {"hs1" })
@@ -314,7 +297,7 @@ func TestRestrictedRoomsRemoteJoinLocalUser(t *testing.T) {
314297// the appropriate authorisation to complete the request.
315298//
316299// Setup 3 homeservers:
317- // * hs1 creates the space /room.
300+ // * hs1 creates the allowed room /room.
318301// * hs2 joins the room
319302// * hs3 attempts to join via hs2 (should fail) and hs1 (should work)
320303func TestRestrictedRoomsRemoteJoinFailOver (t * testing.T ) {
@@ -352,8 +335,8 @@ func TestRestrictedRoomsRemoteJoinFailOver(t *testing.T) {
352335 })
353336 defer deployment .Destroy (t )
354337
355- // Setup the user, space , and restricted room.
356- alice , space , room := setupRestrictedRoom (t , deployment )
338+ // Setup the user, allowed room , and restricted room.
339+ alice , allowed_room , room := setupRestrictedRoom (t , deployment )
357340
358341 // Raise the power level so that only alice can invite.
359342 state_key := ""
@@ -371,13 +354,13 @@ func TestRestrictedRoomsRemoteJoinFailOver(t *testing.T) {
371354 // Create a second user on a different homeserver.
372355 bob := deployment .Client (t , "hs2" , "@bob:hs2" )
373356
374- // Bob joins the room and space .
375- bob .JoinRoom (t , space , []string {"hs1" })
357+ // Bob joins the room and allowed room .
358+ bob .JoinRoom (t , allowed_room , []string {"hs1" })
376359 bob .JoinRoom (t , room , []string {"hs1" })
377360
378- // Charlie should join the space (which gives access to the room).
361+ // Charlie should join the allowed room (which gives access to the room).
379362 charlie := deployment .Client (t , "hs3" , "@charlie:hs3" )
380- charlie .JoinRoom (t , space , []string {"hs1" })
363+ charlie .JoinRoom (t , allowed_room , []string {"hs1" })
381364
382365 // hs2 doesn't have anyone to invite from, so the join fails.
383366 failJoinRoom (t , charlie , room , "hs2" , 502 )
@@ -428,11 +411,12 @@ func TestRestrictedRoomsRemoteJoinFailOver(t *testing.T) {
428411 },
429412 )
430413
431- // Bob leaves the space so that hs2 doesn't know if Charlie is in the space or not.
432- bob .LeaveRoom (t , space )
414+ // Bob leaves the allowed room so that hs2 doesn't know if Charlie is in the
415+ // allowed room or not.
416+ bob .LeaveRoom (t , allowed_room )
433417
434418 // hs2 cannot complete the join since they do not know if Charlie meets the
435- // requirements (since it is no longer in the space ).
419+ // requirements (since it is no longer in the allowed room ).
436420 failJoinRoom (t , charlie , room , "hs2" , 502 )
437421
438422 // Including hs1 (and failing over to it) allows the join to succeed.
@@ -498,7 +482,7 @@ func TestRestrictedRoomsSpacesSummary(t *testing.T) {
498482 },
499483 },
500484 })
501- // The room is an unstable room version which supports the restricted join_rule.
485+ // The room is room version 8 which supports the restricted join_rule.
502486 room := alice .CreateRoom (t , map [string ]interface {}{
503487 "preset" : "public_chat" ,
504488 "name" : "Room" ,
@@ -579,8 +563,8 @@ func TestRestrictedRoomsSpacesSummaryFederation(t *testing.T) {
579563 },
580564 })
581565
582- // The room is an unstable room version which supports the restricted join_rule
583- // and is created on hs2.
566+ // The room is room version 8 which supports the restricted join_rule and is
567+ // created on hs2.
584568 charlie := deployment .Client (t , "hs2" , "@charlie:hs2" )
585569 room := charlie .CreateRoom (t , map [string ]interface {}{
586570 "preset" : "public_chat" ,
0 commit comments