From 3dd730820d64340dae8186a9d465c3d46941a06b Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 25 Oct 2022 16:50:36 +0100 Subject: [PATCH 1/3] Test aliases during a partial join resync --- ...federation_room_join_partial_state_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/federation_room_join_partial_state_test.go b/tests/federation_room_join_partial_state_test.go index 56f2711a..b40ad3d1 100644 --- a/tests/federation_room_join_partial_state_test.go +++ b/tests/federation_room_join_partial_state_test.go @@ -1502,6 +1502,58 @@ func TestPartialStateJoin(t *testing.T) { } }) + // 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", "t23alice", "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 := "#t23alice-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) + }) + 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. From 502d617a54e6b87c39abf097b80dbda87c0d874d Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 25 Oct 2022 18:02:58 +0100 Subject: [PATCH 2/3] Give Alice a unique test id --- ...federation_room_join_partial_state_test.go | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/tests/federation_room_join_partial_state_test.go b/tests/federation_room_join_partial_state_test.go index b40ad3d1..aab16bcb 100644 --- a/tests/federation_room_join_partial_state_test.go +++ b/tests/federation_room_join_partial_state_test.go @@ -1501,59 +1501,6 @@ func TestPartialStateJoin(t *testing.T) { t.Errorf("SendKnock: non-HTTPError: %v", err) } }) - - // 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", "t23alice", "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 := "#t23alice-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) - }) - 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. @@ -2827,6 +2774,59 @@ 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 reception of an event over federation during a resync From fbfa6675134f230f8ced6781d2919394082e68c9 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 1 Nov 2022 15:04:16 +0000 Subject: [PATCH 3/3] Also check you can DELETE during resync --- ...federation_room_join_partial_state_test.go | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/federation_room_join_partial_state_test.go b/tests/federation_room_join_partial_state_test.go index aab16bcb..747f2240 100644 --- a/tests/federation_room_join_partial_state_test.go +++ b/tests/federation_room_join_partial_state_test.go @@ -2827,6 +2827,44 @@ func TestPartialStateJoin(t *testing.T) { 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