Skip to content

Commit

Permalink
Test that remote kicks work during resync
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Feb 17, 2023
1 parent 7f078f3 commit 2291653
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion tests/federation_room_join_partial_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3666,8 +3666,64 @@ func TestPartialStateJoin(t *testing.T) {
)

})

t.Run("can be triggered by remote kick", func(t *testing.T) {
alice := deployment.RegisterUser(t, "hs1", "t50alice", "secret", false)
handleTransactions := federation.HandleTransactionRequests(
// Accept all PDUs and EDUs
func(e *gomatrixserverlib.Event) {},
func(e gomatrixserverlib.EDU) {},
)
server := createTestServer(t, deployment, handleTransactions)
cancel := server.Listen()
defer cancel()

serverRoom := createTestRoom(t, server, alice.GetDefaultRoomVersion(t))
t.Log("Alice partial-joins her room")
psjResult := beginPartialStateJoin(t, server, serverRoom, alice)
// Alice is not joined to the room at the end of the test, so we do not
// `defer psjResult.Destroy(t)`.

t.Log("Alice waits to see her join")
aliceNextBatch := alice.MustSyncUntil(
t,
client.SyncReq{Filter: buildLazyLoadingSyncFilter(nil)},
client.SyncJoinedTo(alice.UserID, serverRoom.RoomID),
)

t.Log("A resident server user kicks Alice from the room.")
// This is incorrectly accepted, since the homeserver under test does not know whether
// @fred is really in the room.
// This event has to be a ban, rather than a kick, otherwise state resolution can bring
// @derek back into the room and ruin the test setup.
kickEvent := server.MustCreateEvent(t, serverRoom, b.Event{
Type: "m.room.member",
StateKey: b.Ptr(alice.UserID),
Sender: server.UserID("charlie"),
Content: map[string]interface{}{"membership": "leave"},
AuthEvents: serverRoom.EventIDsOrReferences([]*gomatrixserverlib.Event{
serverRoom.CurrentState("m.room.create", ""),
serverRoom.CurrentState("m.room.power_levels", ""),
serverRoom.CurrentState("m.room.member", alice.UserID),
serverRoom.CurrentState("m.room.member", server.UserID("charlie")),
}),
})
serverRoom.AddEvent(kickEvent)
server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{kickEvent.JSON()}, nil)

// The kick occurs mid-resync, because we have not yet called
// psjResult.FinishStateRequest().
t.Log("Alice sees that she's been kicked")
aliceNextBatch = alice.MustSyncUntil(
t,
client.SyncReq{Since: aliceNextBatch, Filter: buildLazyLoadingSyncFilter(nil)},
client.SyncLeftFrom(alice.UserID, serverRoom.RoomID),
)

// Cleanup.
psjResult.FinishStateRequest()
})
// TODO: tests which assert that:
// - Join + remote kick works
// - Join + remote ban works, then cannot rejoin
})

Expand Down

0 comments on commit 2291653

Please sign in to comment.