@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/matrix-org/complement/internal/b"
1313 "github.com/matrix-org/complement/internal/client"
14+ "github.com/matrix-org/complement/internal/docker"
1415)
1516
1617var (
@@ -32,12 +33,10 @@ func FailJoinRoom(c *client.CSAPI, t *testing.T, roomIDOrAlias string, serverNam
3233 )
3334}
3435
35- // Test joining a room with join rules restricted to membership in a space.
36- func TestRestrictedRoomsLocalJoin (t * testing.T ) {
37- deployment := Deploy (t , "msc3083" , b .BlueprintOneToOneRoom )
38- defer deployment .Destroy (t )
39-
40- // Create the space and put a room in it.
36+ // Create a space and put a room in it which is set to:
37+ // * The experimental room version.
38+ // * restricted join rules with allow set to the space.
39+ func SetupRestrictedRoom (t * testing.T , deployment * docker.Deployment ) (* client.CSAPI , string , string ) {
4140 alice := deployment .Client (t , "hs1" , "@alice:hs1" )
4241 space := alice .CreateRoom (t , map [string ]interface {}{
4342 "preset" : "public_chat" ,
@@ -72,8 +71,10 @@ func TestRestrictedRoomsLocalJoin(t *testing.T) {
7271 },
7372 })
7473
75- // Create a second user and attempt to join the room, it should fail.
76- bob := deployment .Client (t , "hs1" , "@bob:hs1" )
74+ return alice , space , room
75+ }
76+
77+ func CheckRestrictedRoom (t * testing.T , alice * client.CSAPI , bob * client.CSAPI , space string , room string ) {
7778 FailJoinRoom (bob , t , room , "hs1" )
7879
7980 // Join the space, attempt to join the room again, which now should succeed.
@@ -86,7 +87,7 @@ func TestRestrictedRoomsLocalJoin(t *testing.T) {
8687 FailJoinRoom (bob , t , room , "hs1" )
8788
8889 // Invite the user and joining should work.
89- alice .InviteRoom (t , room , "@ bob:hs1" )
90+ alice .InviteRoom (t , room , bob . UserID )
9091 bob .JoinRoom (t , room , []string {"hs1" })
9192
9293 // Leave the room again, and join the space.
@@ -125,6 +126,36 @@ func TestRestrictedRoomsLocalJoin(t *testing.T) {
125126 },
126127 },
127128 )
128- // Fails since a fully invalid allow key rquires an invite.
129+ // Fails since a fully invalid allow key requires an invite.
129130 FailJoinRoom (bob , t , room , "hs1" )
130131}
132+
133+ // Test joining a room with join rules restricted to membership in a space.
134+ func TestRestrictedRoomsLocalJoin (t * testing.T ) {
135+ deployment := Deploy (t , "msc3083_local" , b .BlueprintOneToOneRoom )
136+ defer deployment .Destroy (t )
137+
138+ // Setup the user, space, and restricted room.
139+ alice , space , room := SetupRestrictedRoom (t , deployment )
140+
141+ // Create a second user on the same homeserver.
142+ bob := deployment .Client (t , "hs1" , "@bob:hs1" )
143+
144+ // Execute the checks.
145+ CheckRestrictedRoom (t , alice , bob , space , room )
146+ }
147+
148+ // Test joining a room with join rules restricted to membership in a space.
149+ func TestRestrictedRoomsRemoteJoin (t * testing.T ) {
150+ deployment := Deploy (t , "msc3083_remote" , b .BlueprintFederationOneToOneRoom )
151+ defer deployment .Destroy (t )
152+
153+ // Setup the user, space, and restricted room.
154+ alice , space , room := SetupRestrictedRoom (t , deployment )
155+
156+ // Create a second user on a different homeserver.
157+ bob := deployment .Client (t , "hs2" , "@bob:hs2" )
158+
159+ // Execute the checks.
160+ CheckRestrictedRoom (t , alice , bob , space , room )
161+ }
0 commit comments