Skip to content

Commit

Permalink
Add remote invite -> join/reject tests for rooms that a homeserver is…
Browse files Browse the repository at this point in the history
… already participating in (#757)

Regression tests for element-hq/synapse#18075
  • Loading branch information
MadLittleMods authored Jan 27, 2025
1 parent 6dbf2bd commit 8f0c763
Showing 1 changed file with 64 additions and 6 deletions.
70 changes: 64 additions & 6 deletions tests/federation_rooms_invite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// These tests currently fail on Dendrite, due to Dendrite bugs.
//go:build !dendrite_blacklist
// +build !dendrite_blacklist

package tests

import (
"encoding/json"
"testing"

"github.com/matrix-org/complement"
Expand All @@ -17,8 +22,17 @@ func TestFederationRoomsInvite(t *testing.T) {
deployment := complement.Deploy(t, 2)
defer deployment.Destroy(t)

alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{})
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{LocalpartSuffix: "alice"})
bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{LocalpartSuffix: "bob"})
bob2 := deployment.Register(t, "hs2", helpers.RegistrationOpts{LocalpartSuffix: "bob2"})

includeLeaveSyncFilterBytes, err := json.Marshal(map[string]interface{}{
"room": map[string]interface{}{
"include_leave": true,
},
})
must.NotError(t, "failed to marshal include_leave filter", err)
includeLeaveSyncFilter := string(includeLeaveSyncFilterBytes)

t.Run("Parallel", func(t *testing.T) {
// sytest: Invited user can reject invite over federation
Expand All @@ -30,7 +44,7 @@ func TestFederationRoomsInvite(t *testing.T) {
})
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
bob.MustLeaveRoom(t, roomID)
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID))
alice.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob.UserID, roomID))
})

// sytest: Invited user can reject invite over federation several times
Expand All @@ -43,7 +57,7 @@ func TestFederationRoomsInvite(t *testing.T) {
alice.MustInviteRoom(t, roomID, bob.UserID)
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
bob.MustLeaveRoom(t, roomID)
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID))
alice.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob.UserID, roomID))
}
})

Expand All @@ -57,9 +71,9 @@ func TestFederationRoomsInvite(t *testing.T) {
aliceSince := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))
bobSince := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
alice.MustLeaveRoom(t, roomID)
alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncLeftFrom(alice.UserID, roomID))
alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince, Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(alice.UserID, roomID))
bob.MustLeaveRoom(t, roomID)
bob.MustSyncUntil(t, client.SyncReq{Since: bobSince}, client.SyncLeftFrom(bob.UserID, roomID))
bob.MustSyncUntil(t, client.SyncReq{Since: bobSince, Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob.UserID, roomID))
})

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

t.Run("Remote invited user can join the room when homeserver is already participating in the room", func(t *testing.T) {
t.Parallel()
roomID := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
})
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))

// bob1 is invited and can join the room (hs2 is now participating of the room)
alice.MustInviteRoom(t, roomID, bob.UserID)
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
bob.MustJoinRoom(t, roomID, []string{"hs1"})
// Make sure alice can see bob in the room
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))

// bob2 is invited and can also join the room
alice.MustInviteRoom(t, roomID, bob2.UserID)
bob2.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob2.UserID, roomID))
bob2.MustJoinRoom(t, roomID, []string{"hs1"})
// Make sure alice can see bob2 in the room
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob2.UserID, roomID))
})

t.Run("Remote invited user can reject invite when homeserver is already participating in the room", func(t *testing.T) {
t.Parallel()
roomID := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
})
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))

// bob1 is invited and can join the room (hs2 is now participating of the room)
alice.MustInviteRoom(t, roomID, bob.UserID)
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
bob.MustJoinRoom(t, roomID, []string{"hs1"})
// Make sure alice can see bob in the room
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))

// bob2 is invited and can reject the invite (leave the room)
alice.MustInviteRoom(t, roomID, bob2.UserID)
bob2.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob2.UserID, roomID))
bob2.MustLeaveRoom(t, roomID)
// Make sure alice can see bob2 left the room
alice.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob2.UserID, roomID))
})

t.Run("Invited user has 'is_direct' flag in prev_content after joining", func(t *testing.T) {
roomID := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
Expand Down

0 comments on commit 8f0c763

Please sign in to comment.