Skip to content

Commit

Permalink
Test against the stable endpoint from MSC2946 (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Nov 29, 2021
1 parent 6126e9c commit b02743c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build msc2946
// +build msc2946
// +build !dendrite_blacklist

// Tests MSC3083, joining restricted spaces based on membership in another room.

Expand All @@ -20,7 +19,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", "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{} {
Expand All @@ -37,7 +36,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)

Expand Down
155 changes: 11 additions & 144 deletions tests/msc2946_test.go → tests/room_hierarchy_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build msc2946
// +build !dendrite_blacklist

// This file includes tests for MSC2946, the spaces summary API.
//
Expand Down Expand Up @@ -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", "v1", "rooms", root, "hierarchy"}, nil)
must.MatchResponse(t, res, match.HTTPResponse{
JSON: []match.JSON{
match.JSONCheckOff("rooms", []interface{}{
Expand Down Expand Up @@ -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.
Expand All @@ -308,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{
Expand Down Expand Up @@ -336,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{
Expand Down Expand Up @@ -364,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{
Expand All @@ -383,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{
Expand All @@ -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{}{
Expand Down Expand Up @@ -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", "v1", "rooms", root, "hierarchy"}, nil)
must.MatchResponse(t, res, match.HTTPResponse{
JSON: []match.JSON{
match.JSONCheckOff("rooms", []interface{}{
Expand All @@ -569,22 +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, "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)
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{}{
Expand All @@ -603,22 +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, "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)
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{}{
Expand Down Expand Up @@ -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", "v1", "rooms", root, "hierarchy"}, nil)
must.MatchResponse(t, res, match.HTTPResponse{
JSON: []match.JSON{
match.JSONCheckOff("rooms", []interface{}{
Expand Down

0 comments on commit b02743c

Please sign in to comment.