Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test aliases during a partial join resync #537

Merged
merged 3 commits into from
Nov 2, 2022
Merged
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
92 changes: 91 additions & 1 deletion tests/federation_room_join_partial_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,6 @@ func TestPartialStateJoin(t *testing.T) {
t.Errorf("SendKnock: non-HTTPError: %v", err)
}
})

t.Run("Outgoing device list updates", func(t *testing.T) {
// setupOutgoingDeviceListUpdateTest sets up two complement homeservers.
// A room is created on the first complement server, containing only local users.
Expand Down Expand Up @@ -2775,6 +2774,97 @@ func TestPartialStateJoin(t *testing.T) {
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
})
})

// Test that a) you can add a room alias during a resync and that
// b) querying that alias returns at least the servers we were told
// about in the /send_join response.
t.Run("Room aliases can be added and queried during a resync", func(t *testing.T) {
// Alice begins a partial join to a room.
alice := deployment.RegisterUser(t, "hs1", "t40alice", "secret", false)
server := createTestServer(t, deployment)
cancel := server.Listen()
defer cancel()

serverRoom := createTestRoom(t, server, alice.GetDefaultRoomVersion(t))
psjResult := beginPartialStateJoin(t, server, serverRoom, alice)
defer psjResult.Destroy()

// Alice creates an alias for the room
aliasName := "#t40alice-room:hs1"
alice.MustDoFunc(
t,
"PUT",
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
client.WithJSONBody(t, map[string]interface{}{
"room_id": serverRoom.RoomID,
}),
)

// Alice then queries that alias
response := alice.MustDoFunc(
t,
"GET",
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
client.WithJSONBody(t, map[string]interface{}{
"room_id": serverRoom.RoomID,
}),
)

// The response should be 200 OK, should include the room id and
// should include both HSes.
spec := match.HTTPResponse{
StatusCode: 200,
JSON: []match.JSON{
match.JSONKeyEqual("room_id", serverRoom.RoomID),
match.JSONCheckOff(
"servers",
[]interface{}{"hs1", server.ServerName()},
func(r gjson.Result) interface{} { return r.Str },
nil,
),
},
}
must.MatchResponse(t, response, spec)
})

// Test that you can delete a room alias during a resync that you added during
// the resync.
t.Run("Room aliases can be added and deleted during a resync", func(t *testing.T) {
// Alice begins a partial join to a room.
alice := deployment.RegisterUser(t, "hs1", "t41alice", "secret", false)
server := createTestServer(t, deployment)
cancel := server.Listen()
defer cancel()

serverRoom := createTestRoom(t, server, alice.GetDefaultRoomVersion(t))
psjResult := beginPartialStateJoin(t, server, serverRoom, alice)
defer psjResult.Destroy()

// Alice creates an alias for the room
aliasName := "#t41alice-room:hs1"
alice.MustDoFunc(
t,
"PUT",
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
client.WithJSONBody(t, map[string]interface{}{
"room_id": serverRoom.RoomID,
}),
)

// Alice then deletes that alias
response := alice.MustDoFunc(
t,
"DELETE",
[]string{"_matrix", "client", "v3", "directory", "room", aliasName},
)

// The response should be 200 OK. (Strictly speaking it should have an
// empty json object as the response body but that's not important here)
spec := match.HTTPResponse{
StatusCode: 200,
}
must.MatchResponse(t, response, spec)
})
}

// test reception of an event over federation during a resync
Expand Down