Skip to content

Commit

Permalink
Test aliases during a partial join resync (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson authored Nov 2, 2022
1 parent ec6e09c commit ec35877
Showing 1 changed file with 91 additions and 1 deletion.
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 @@ -1813,7 +1813,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 @@ -3087,6 +3086,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

0 comments on commit ec35877

Please sign in to comment.