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
61 changes: 58 additions & 3 deletions tests/federation_rooms_invite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
)

func TestFederationRoomsInvite(t *testing.T) {
deployment := complement.Deploy(t, 2)
deployment := complement.Deploy(t, 3)
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"})
charlie := deployment.Register(t, "hs3", helpers.RegistrationOpts{LocalpartSuffix: "charlie"})

includeLeaveSyncFilterBytes, err := json.Marshal(map[string]interface{}{
"room": map[string]interface{}{
Expand Down Expand Up @@ -168,7 +169,7 @@ func TestFederationRoomsInvite(t *testing.T) {
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) {
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
Expand All @@ -193,7 +194,61 @@ func TestFederationRoomsInvite(t *testing.T) {
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.
// in bob seeing the rescission. Ideally we would see the
// rescission, but currently we have no way to auth that over
// federation.
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))
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion:

		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` invites bob
			alice2.MustInviteRoom(t, roomID2, bob.UserID)
			bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID2))

			// `alice`, not the original inviter (`alice2`), kicks bob.
			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
			// `roomID1` (on the same homeserver as `roomID2`) and checking that once Bob
			// receives that new message in `roomID1` he still hasn't seen the leave for `roomID2`.
			//
			// Ideally, bob could see the rescission, but currently we have no way to auth
			// that over federation.
			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 to `roomID2` by doing an initial sync
			bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID2))
		})


t.Run("Non-inviter user cannot rescind invite over federation on different server", 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 Charlie join, Charlie invites Bob and
// then Alice kicks him.
roomID2 := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "private_chat",
"invite": []string{charlie.UserID},
})
charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(charlie.UserID, roomID2))
charlie.MustJoinRoom(t, roomID2, []spec.ServerName{})

charlie.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. Ideally we would see the
// rescission, but currently we have no way to auth that over
// federation.
alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID2, "kick"},
client.WithJSONBody(t, map[string]interface{}{
"user_id": bob.UserID,
Expand Down
Loading