From 0de292f077bfe53d24ba927eada923c54f9dc3e5 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 25 May 2021 14:04:05 -0400 Subject: [PATCH 1/2] Do not recurse into non-spaces. --- tests/msc2946_test.go | 47 +++++++++++++++++++++++++++++++++++++------ tests/msc3083_test.go | 9 +++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/tests/msc2946_test.go b/tests/msc2946_test.go index d718287a..e82bed56 100644 --- a/tests/msc2946_test.go +++ b/tests/msc2946_test.go @@ -31,8 +31,8 @@ func eventKey(srcRoomID, dstRoomID, evType string) string { // _____|________ // | | | // R1 SS1 R2 -// | -// SS2 +// | | +// SS2 R5 // |________ // | | // R3 R4 @@ -41,7 +41,6 @@ func eventKey(srcRoomID, dstRoomID, evType string) string { // - the user is joined to all rooms except R4. // - R2 <---> Root is a two-way link. // - The remaining links are just children links. -// - SS1 is marked as a "space", but SS2 is not. // // Tests that: // - Querying the root returns the entire graph @@ -61,6 +60,9 @@ func TestClientSpacesSummary(t *testing.T) { root := alice.CreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Root", + "creation_content": map[string]interface{}{ + "type": "m.space", + }, }) roomNames[root] = "Root" r1 := alice.CreateRoom(t, map[string]interface{}{ @@ -85,6 +87,9 @@ func TestClientSpacesSummary(t *testing.T) { ss2 := alice.CreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "SS2", + "creation_content": map[string]interface{}{ + "type": "m.space", + }, }) roomNames[ss2] = "SS2" r3 := alice.CreateRoom(t, map[string]interface{}{ @@ -108,6 +113,10 @@ func TestClientSpacesSummary(t *testing.T) { }, }) roomNames[r4] = "R4" + r5 := bob.CreateRoom(t, map[string]interface{}{ + "preset": "public_chat", + "name": "R5", + }) // create the links rootToR1 := eventKey(root, r1, spaceChildEventType) @@ -134,6 +143,14 @@ func TestClientSpacesSummary(t *testing.T) { "via": []string{"hs1"}, }, }) + // Note that this link gets ignored since R2 is not a space. + alice.SendEventSynced(t, r2, b.Event{ + Type: spaceChildEventType, + StateKey: &r5, + Content: map[string]interface{}{ + "via": []string{"hs1"}, + }, + }) alice.SendEventSynced(t, r2, b.Event{ // parent link Type: spaceParentEventType, StateKey: &root, @@ -283,6 +300,9 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { root := alice.CreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Root", + "creation_content": map[string]interface{}{ + "type": "m.space", + }, }) r1 := alice.CreateRoom(t, map[string]interface{}{ "preset": "private_chat", @@ -438,15 +458,30 @@ func TestFederatedClientSpaces(t *testing.T) { }, }, } + worldReadableSpace := map[string]interface{}{ + "preset": "public_chat", + "creation_content": map[string]interface{}{ + "type": "m.space", + }, + "initial_state": []map[string]interface{}{ + { + "type": "m.room.history_visibility", + "state_key": "", + "content": map[string]string{ + "history_visibility": "world_readable", + }, + }, + }, + } // create the rooms alice := deployment.Client(t, "hs1", "@alice:hs1") - root := alice.CreateRoom(t, worldReadable) + root := alice.CreateRoom(t, worldReadableSpace) r1 := alice.CreateRoom(t, worldReadable) - ss1 := alice.CreateRoom(t, worldReadable) + ss1 := alice.CreateRoom(t, worldReadableSpace) r4 := alice.CreateRoom(t, worldReadable) bob := deployment.Client(t, "hs2", "@bob:hs2") r2 := bob.CreateRoom(t, worldReadable) - ss2 := bob.CreateRoom(t, worldReadable) + ss2 := bob.CreateRoom(t, worldReadableSpace) r3 := bob.CreateRoom(t, worldReadable) // create the links diff --git a/tests/msc3083_test.go b/tests/msc3083_test.go index 706b20ec..9a100633 100644 --- a/tests/msc3083_test.go +++ b/tests/msc3083_test.go @@ -44,6 +44,9 @@ func setupRestrictedRoom(t *testing.T, deployment *docker.Deployment) (*client.C space := alice.CreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Space", + "creation_content": map[string]interface{}{ + "type": "m.space", + }, }) // The room is an unstable room version which supports the restricted join_rule. room := alice.CreateRoom(t, map[string]interface{}{ @@ -195,6 +198,9 @@ func TestRestrictedRoomsSpacesSummary(t *testing.T) { space := alice.CreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Space", + "creation_content": map[string]interface{}{ + "type": "m.space", + }, // World readable to allow peeking without joining. "initial_state": []map[string]interface{}{ { @@ -272,6 +278,9 @@ func TestRestrictedRoomsSpacesSummaryFederation(t *testing.T) { space := alice.CreateRoom(t, map[string]interface{}{ "preset": "public_chat", "name": "Space", + "creation_content": map[string]interface{}{ + "type": "m.space", + }, "initial_state": []map[string]interface{}{ { "type": "m.room.history_visibility", From d3ee57057c4afa6aa389167eeaebf9d84500acc9 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 9 Jun 2021 16:09:51 -0400 Subject: [PATCH 2/2] Do not include links to inaccessible rooms. --- tests/msc2946_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/msc2946_test.go b/tests/msc2946_test.go index e82bed56..efc9540a 100644 --- a/tests/msc2946_test.go +++ b/tests/msc2946_test.go @@ -379,9 +379,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { }, func(r gjson.Result) interface{} { return r.Get("room_id").Str }, nil), - match.JSONCheckOff("events", []interface{}{ - rootToR1, rootToSS1, - }, func(r gjson.Result) interface{} { + match.JSONCheckOff("events", []interface{}{}, func(r gjson.Result) interface{} { return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str) }, nil), }, @@ -400,7 +398,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { return r.Get("room_id").Str }, nil), match.JSONCheckOff("events", []interface{}{ - rootToR1, rootToSS1, + rootToR1, }, func(r gjson.Result) interface{} { return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str) }, nil),