Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions tests/federation_rooms_invite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/tidwall/gjson"

"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
Expand All @@ -23,6 +24,7 @@ func TestFederationRoomsInvite(t *testing.T) {
defer deployment.Destroy(t)

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

Expand Down Expand Up @@ -149,6 +151,73 @@ func TestFederationRoomsInvite(t *testing.T) {
alice.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob2.UserID, roomID))
})

t.Run("Inviter user can rescind invite over federation", func(t *testing.T) {
t.Parallel()
roomID := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
"invite": []string{bob.UserID},
})
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "kick"},
Copy link
Collaborator

@MadLittleMods MadLittleMods Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a test where someone else rescinds the invite (someone different than the inviter)

Also a test for someone else from another server in the room

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test was added for the first case but not the second for someone else from another server in the room

client.WithJSONBody(t, map[string]interface{}{
"user_id": bob.UserID,
"reason": "testing",
}),
)

bob.MustSyncUntil(t, client.SyncReq{Filter: includeLeaveSyncFilter}, client.SyncLeftFrom(bob.UserID, roomID))
})

t.Run("Non-invitee user cannot rescind invite over federation", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.Run("Non-invitee user cannot rescind invite over federation", func(t *testing.T) {
t.Run("Non-inviter user cannot rescind invite over federation", func(t *testing.T) {

t.Parallel()

// First create a room that Bob is in. This is so that later we can
// send a message to test that Bob doesn't see the rescission.
roomID1 := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
"invite": []string{bob.UserID},
})
since := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID1))
bob.MustJoinRoom(t, roomID1, []spec.ServerName{})

// Second room which Alice and Alice2 join, Alice2 invites Bob and
// then Alice kicks him.
roomID2 := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
"invite": []string{alice2.UserID},
})
alice2.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice2.UserID, roomID2))
alice2.MustJoinRoom(t, roomID2, []spec.ServerName{})

alice2.MustInviteRoom(t, roomID2, bob.UserID)
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID2))

// Alice, not the original inviter, kicks bob. This does not result
// in bob seeing the rescission.
Comment on lines +195 to +196
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should comment that it would be fine for bob to see the rescission but they have no way to auth it because of X so they can't take it into account

alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID2, "kick"},
client.WithJSONBody(t, map[string]interface{}{
"user_id": bob.UserID,
"reason": "testing",
}),
)

// Check bob *doesn't* see the rescission. We do this by sending a
// message in room1 and checking that once Bob receives that message
// he still hasn't seen the leave.
eventID := alice.SendEventSynced(t, roomID1, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"body": "1",
"msgtype": "m.text",
},
Sender: alice.UserID,
})
bob.MustSyncUntil(t, client.SyncReq{Since: since}, client.SyncTimelineHasEventID(roomID1, eventID))

// Check bob is still invited by doing an initial sync
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID2))
})

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
Loading