From 25fc9b5b0054cf5597fb18f50ce5b9f217cc32c0 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 17 Nov 2021 12:53:07 -0500 Subject: [PATCH 1/5] Update the restrict rooms tests to use the hierarchy endpoint. --- tests/restricted_spaces_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/restricted_spaces_test.go b/tests/restricted_spaces_test.go index 3df08f86..de6a587b 100644 --- a/tests/restricted_spaces_test.go +++ b/tests/restricted_spaces_test.go @@ -20,7 +20,7 @@ import ( func requestAndAssertSummary(t *testing.T, user *client.CSAPI, space string, expected_rooms []interface{}) { t.Helper() - res := user.MustDo(t, "POST", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", space, "spaces"}, map[string]interface{}{}) + res := user.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", space, "hierarchy"}, map[string]interface{}{}) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", expected_rooms, func(r gjson.Result) interface{} { @@ -37,7 +37,7 @@ func requestAndAssertSummary(t *testing.T, user *client.CSAPI, space string, exp // // The user should be unable to see the room in the spaces summary unless they // are a member of the space. -func TestRestrictedRoomsSpacesSummary(t *testing.T) { +func TestRestrictedRoomsSpacesSummaryLocal(t *testing.T) { deployment := Deploy(t, b.BlueprintOneToOneRoom) defer deployment.Destroy(t) From 3f603057983acd6e57f4b37254286e28c2a102f4 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 17 Nov 2021 12:53:25 -0500 Subject: [PATCH 2/5] Mark tests as not needing a build flag. --- .github/workflows/ci.yaml | 2 +- tests/msc2946_test.go | 2 +- tests/restricted_spaces_test.go | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d331bebc..3a2c28eb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,7 +24,7 @@ jobs: matrix: include: - homeserver: Synapse - tags: synapse_blacklist,msc2403,msc2946,msc3083 + tags: synapse_blacklist,msc2403,msc3083 default_branch: develop - homeserver: Dendrite diff --git a/tests/msc2946_test.go b/tests/msc2946_test.go index 6cf777df..b6650759 100644 --- a/tests/msc2946_test.go +++ b/tests/msc2946_test.go @@ -1,4 +1,4 @@ -// +build msc2946 +// +build !dendrite_blacklist // This file includes tests for MSC2946, the spaces summary API. // diff --git a/tests/restricted_spaces_test.go b/tests/restricted_spaces_test.go index de6a587b..878c8652 100644 --- a/tests/restricted_spaces_test.go +++ b/tests/restricted_spaces_test.go @@ -1,5 +1,4 @@ -//go:build msc2946 -// +build msc2946 +// +build !dendrite_blacklist // Tests MSC3083, joining restricted spaces based on membership in another room. From 320a53e7c99ad105431d73bd5eecb80f1ae75dd3 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 17 Nov 2021 12:58:38 -0500 Subject: [PATCH 3/5] Remove tests against the /spaces endpoint. --- tests/msc2946_test.go | 141 ++---------------------------------------- 1 file changed, 4 insertions(+), 137 deletions(-) diff --git a/tests/msc2946_test.go b/tests/msc2946_test.go index b6650759..d462a5aa 100644 --- a/tests/msc2946_test.go +++ b/tests/msc2946_test.go @@ -204,40 +204,7 @@ func TestClientSpacesSummary(t *testing.T) { // - Rooms are returned correctly along with the custom fields `room_type`. // - Events are returned correctly. t.Run("query whole graph", func(t *testing.T) { - res := alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "spaces"}, nil) - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - match.JSONCheckOff("rooms", []interface{}{ - root, r1, r2, r3, r4, ss1, ss2, - }, func(r gjson.Result) interface{} { - return r.Get("room_id").Str - }, func(roomInt interface{}, data gjson.Result) error { - roomID := roomInt.(string) - // check fields - if name, ok := roomNames[roomID]; ok { - if data.Get("name").Str != name { - return fmt.Errorf("room %s got name %s want %s", roomID, data.Get("name").Str, name) - } - } - if roomID == ss1 { - wantType := "m.space" - if data.Get("room_type").Str != wantType { - return fmt.Errorf("room %s got type %s want %s", roomID, data.Get("room_type").Str, wantType) - } - } - return nil - }), - // Check that the links from Root down to other rooms and spaces exist. - match.JSONCheckOff("events", []interface{}{ - rootToR1, rootToR2, rootToSS1, - ss1ToSS2, ss2ToR3, ss2ToR4, - }, func(r gjson.Result) interface{} { - return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str) - }, nil), - }, - }) - - res = alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res := alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ @@ -271,35 +238,6 @@ func TestClientSpacesSummary(t *testing.T) { }) }) - // - Setting max_rooms_per_space works correctly - t.Run("max_rooms_per_space", func(t *testing.T) { - // should omit either R3 or R4 if we start from SS1 because we only return 1 link per room which will be: - // SS1 -> SS2 - // SS2 -> R3,R4 (but only 1 is allowed) - query := make(url.Values, 1) - query.Set("max_rooms_per_space", "1") - res := alice.MustDoFunc( - t, - "GET", - []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", ss1, "spaces"}, - client.WithQueries(query), - ) - wantItems := []interface{}{ - ss1ToSS2, - ss2ToR3, ss2ToR4, // one of these - } - body := must.ParseJSON(t, res.Body) - gjson.GetBytes(body, "events").ForEach(func(_, val gjson.Result) bool { - wantItems = must.CheckOff(t, wantItems, eventKey(val.Get("room_id").Str, val.Get("state_key").Str, val.Get("type").Str)) - return true - }) - if len(wantItems) != 1 { - if wantItems[0] != ss2ToR3 && wantItems[0] != ss2ToR4 { - t.Errorf("expected fewer events to be returned: %s", string(body)) - } - } - }) - // - Setting max_depth works correctly t.Run("max_depth", func(t *testing.T) { // Should only include R1, SS1, and R2. @@ -404,23 +342,7 @@ func TestClientSpacesSummary(t *testing.T) { StateKey: &ss1, Content: map[string]interface{}{}, }) - res := alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "spaces"}, nil) - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - match.JSONCheckOff("rooms", []interface{}{ - root, r1, r2, - }, func(r gjson.Result) interface{} { - return r.Get("room_id").Str - }, nil), - match.JSONCheckOff("events", []interface{}{ - rootToR1, rootToR2, - }, func(r gjson.Result) interface{} { - return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str) - }, nil), - }, - }) - - res = alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ @@ -534,22 +456,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") bob.JoinRoom(t, root, []string{"hs1"}) - res := bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "spaces"}, nil) - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - match.JSONCheckOff("rooms", []interface{}{ - root, - }, func(r gjson.Result) interface{} { - return r.Get("room_id").Str - }, nil), - match.JSONCheckOff("events", []interface{}{ - rootToR1, rootToSS1, - }, func(r gjson.Result) interface{} { - return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str) - }, nil), - }, - }) - res = bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res := bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ @@ -569,21 +476,6 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { alice.InviteRoom(t, r1, bob.UserID) alice.InviteRoom(t, r3, bob.UserID) - res = bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "spaces"}, nil) - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - match.JSONCheckOff("rooms", []interface{}{ - root, r1, - }, func(r gjson.Result) interface{} { - return r.Get("room_id").Str - }, nil), - match.JSONCheckOff("events", []interface{}{ - rootToR1, rootToSS1, - }, func(r gjson.Result) interface{} { - return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str) - }, nil), - }, - }) res = bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ @@ -603,21 +495,6 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { // Invite to SS1 and it now appears, as well as the rooms under it. alice.InviteRoom(t, ss1, bob.UserID) - res = bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "spaces"}, nil) - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - match.JSONCheckOff("rooms", []interface{}{ - root, r1, ss1, r2, r3, - }, func(r gjson.Result) interface{} { - return r.Get("room_id").Str - }, nil), - match.JSONCheckOff("events", []interface{}{ - rootToR1, rootToSS1, ss1ToR2, ss1ToR3, - }, func(r gjson.Result) interface{} { - return eventKey(r.Get("room_id").Str, r.Get("state_key").Str, r.Get("type").Str) - }, nil), - }, - }) res = bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ @@ -748,17 +625,7 @@ func TestFederatedClientSpaces(t *testing.T) { } t.Logf("rooms: %v", allEvents) - res := alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "spaces"}, nil) - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - match.JSONCheckOff("rooms", []interface{}{ - root, r1, r2, r3, r4, ss1, ss2, - }, func(r gjson.Result) interface{} { - return r.Get("room_id").Str - }, nil), - }, - }) - res = alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res := alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ From f07dc1b9f88d6254622528d411a31470610543f4 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 17 Nov 2021 12:59:14 -0500 Subject: [PATCH 4/5] Use the stable endpoint for /hierarchy. --- tests/msc2946_test.go | 18 +++++++++--------- tests/restricted_spaces_test.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/msc2946_test.go b/tests/msc2946_test.go index d462a5aa..ab54d512 100644 --- a/tests/msc2946_test.go +++ b/tests/msc2946_test.go @@ -204,7 +204,7 @@ func TestClientSpacesSummary(t *testing.T) { // - Rooms are returned correctly along with the custom fields `room_type`. // - Events are returned correctly. t.Run("query whole graph", func(t *testing.T) { - res := alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ @@ -246,7 +246,7 @@ func TestClientSpacesSummary(t *testing.T) { res := alice.MustDoFunc( t, "GET", - []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, + []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, client.WithQueries(query), ) must.MatchResponse(t, res, match.HTTPResponse{ @@ -274,7 +274,7 @@ func TestClientSpacesSummary(t *testing.T) { res := alice.MustDoFunc( t, "GET", - []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, + []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, client.WithQueries(query), ) must.MatchResponse(t, res, match.HTTPResponse{ @@ -302,7 +302,7 @@ func TestClientSpacesSummary(t *testing.T) { res := alice.MustDoFunc( t, "GET", - []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, + []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, client.WithQueries(query), ) body := must.MatchResponse(t, res, match.HTTPResponse{ @@ -321,7 +321,7 @@ func TestClientSpacesSummary(t *testing.T) { res = alice.MustDoFunc( t, "GET", - []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, + []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, client.WithQueries(query), ) must.MatchResponse(t, res, match.HTTPResponse{ @@ -456,7 +456,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { bob := deployment.Client(t, "hs1", "@bob:hs1") bob.JoinRoom(t, root, []string{"hs1"}) - res := bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res := bob.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ @@ -476,7 +476,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { alice.InviteRoom(t, r1, bob.UserID) alice.InviteRoom(t, r3, bob.UserID) - res = bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res = bob.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ @@ -495,7 +495,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { // Invite to SS1 and it now appears, as well as the rooms under it. alice.InviteRoom(t, ss1, bob.UserID) - res = bob.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res = bob.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ @@ -625,7 +625,7 @@ func TestFederatedClientSpaces(t *testing.T) { } t.Logf("rooms: %v", allEvents) - res := alice.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", root, "hierarchy"}, nil) + res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}, nil) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", []interface{}{ diff --git a/tests/restricted_spaces_test.go b/tests/restricted_spaces_test.go index 878c8652..0c293b16 100644 --- a/tests/restricted_spaces_test.go +++ b/tests/restricted_spaces_test.go @@ -19,7 +19,7 @@ import ( func requestAndAssertSummary(t *testing.T, user *client.CSAPI, space string, expected_rooms []interface{}) { t.Helper() - res := user.MustDo(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc2946", "rooms", space, "hierarchy"}, map[string]interface{}{}) + res := user.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", space, "hierarchy"}, map[string]interface{}{}) must.MatchResponse(t, res, match.HTTPResponse{ JSON: []match.JSON{ match.JSONCheckOff("rooms", expected_rooms, func(r gjson.Result) interface{} { From c6f46e7438f9714c09644f80851317457d572a95 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 17 Nov 2021 13:01:41 -0500 Subject: [PATCH 5/5] Rename files. --- ...estricted_spaces_test.go => restricted_room_hierarchy_test.go} | 0 tests/{msc2946_test.go => room_hierarchy_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/{restricted_spaces_test.go => restricted_room_hierarchy_test.go} (100%) rename tests/{msc2946_test.go => room_hierarchy_test.go} (100%) diff --git a/tests/restricted_spaces_test.go b/tests/restricted_room_hierarchy_test.go similarity index 100% rename from tests/restricted_spaces_test.go rename to tests/restricted_room_hierarchy_test.go diff --git a/tests/msc2946_test.go b/tests/room_hierarchy_test.go similarity index 100% rename from tests/msc2946_test.go rename to tests/room_hierarchy_test.go