Skip to content

Commit 8c91070

Browse files
committed
Add remote invite -> join/reject tests for rooms the homeserver is already participating in
Regression tests for element-hq/synapse#18075
1 parent 08ab613 commit 8c91070

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

tests/federation_rooms_invite_test.go

+60-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"encoding/json"
45
"testing"
56

67
"github.com/matrix-org/complement"
@@ -17,8 +18,17 @@ func TestFederationRoomsInvite(t *testing.T) {
1718
deployment := complement.Deploy(t, 2)
1819
defer deployment.Destroy(t)
1920

20-
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
21-
bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{})
21+
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{LocalpartSuffix: "alice"})
22+
bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{LocalpartSuffix: "bob"})
23+
bob2 := deployment.Register(t, "hs2", helpers.RegistrationOpts{LocalpartSuffix: "bob2"})
24+
25+
includeLeaveSyncFilterBytes, err := json.Marshal(map[string]interface{}{
26+
"room": map[string]interface{}{
27+
"include_leave": true,
28+
},
29+
})
30+
must.NotError(t, "failed to marshal include_leave filter", err)
31+
includeLeaveSyncFilter := string(includeLeaveSyncFilterBytes)
2232

2333
t.Run("Parallel", func(t *testing.T) {
2434
// sytest: Invited user can reject invite over federation
@@ -30,7 +40,7 @@ func TestFederationRoomsInvite(t *testing.T) {
3040
})
3141
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
3242
bob.MustLeaveRoom(t, roomID)
33-
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID))
43+
alice.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob.UserID, roomID))
3444
})
3545

3646
// sytest: Invited user can reject invite over federation several times
@@ -43,7 +53,7 @@ func TestFederationRoomsInvite(t *testing.T) {
4353
alice.MustInviteRoom(t, roomID, bob.UserID)
4454
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
4555
bob.MustLeaveRoom(t, roomID)
46-
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID))
56+
alice.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob.UserID, roomID))
4757
}
4858
})
4959

@@ -57,9 +67,9 @@ func TestFederationRoomsInvite(t *testing.T) {
5767
aliceSince := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))
5868
bobSince := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
5969
alice.MustLeaveRoom(t, roomID)
60-
alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncLeftFrom(alice.UserID, roomID))
70+
alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince, Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(alice.UserID, roomID))
6171
bob.MustLeaveRoom(t, roomID)
62-
bob.MustSyncUntil(t, client.SyncReq{Since: bobSince}, client.SyncLeftFrom(bob.UserID, roomID))
72+
bob.MustSyncUntil(t, client.SyncReq{Since: bobSince, Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob.UserID, roomID))
6373
})
6474

6575
// sytest: Remote invited user can see room metadata
@@ -85,6 +95,50 @@ func TestFederationRoomsInvite(t *testing.T) {
8595
verifyState(t, res, wantFields, wantValues, roomID, alice)
8696
})
8797

98+
t.Run("Remote invited user can join the room when homeserver is already participating in the room", func(t *testing.T) {
99+
t.Parallel()
100+
roomID := alice.MustCreateRoom(t, map[string]interface{}{
101+
"preset": "private_chat",
102+
})
103+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))
104+
105+
// bob1 is invited and can join the room (hs2 is now participating of the room)
106+
alice.MustInviteRoom(t, roomID, bob.UserID)
107+
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
108+
bob.MustJoinRoom(t, roomID, []string{"hs1"})
109+
// Make sure alice can see bob in the room
110+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
111+
112+
// bob2 is invited and can also join the room
113+
alice.MustInviteRoom(t, roomID, bob2.UserID)
114+
bob2.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob2.UserID, roomID))
115+
bob2.MustJoinRoom(t, roomID, []string{"hs1"})
116+
// Make sure alice can see bob2 in the room
117+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob2.UserID, roomID))
118+
})
119+
120+
t.Run("Remote invited user can reject invite when homeserver is already participating in the room", func(t *testing.T) {
121+
t.Parallel()
122+
roomID := alice.MustCreateRoom(t, map[string]interface{}{
123+
"preset": "private_chat",
124+
})
125+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))
126+
127+
// bob1 is invited and can join the room (hs2 is now participating of the room)
128+
alice.MustInviteRoom(t, roomID, bob.UserID)
129+
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
130+
bob.MustJoinRoom(t, roomID, []string{"hs1"})
131+
// Make sure alice can see bob in the room
132+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
133+
134+
// bob2 is invited and can reject the invite (leave the room)
135+
alice.MustInviteRoom(t, roomID, bob2.UserID)
136+
bob2.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob2.UserID, roomID))
137+
bob2.MustLeaveRoom(t, roomID)
138+
// Make sure alice can see bob2 left the room
139+
alice.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob2.UserID, roomID))
140+
})
141+
88142
t.Run("Invited user has 'is_direct' flag in prev_content after joining", func(t *testing.T) {
89143
roomID := alice.MustCreateRoom(t, map[string]interface{}{
90144
"preset": "private_chat",

0 commit comments

Comments
 (0)