Skip to content

Commit 44d3bf5

Browse files
test: make sure that allowed_room_ids is included in the /summary client-server API response for rooms with restricted join rules, as required by Matrix 1.15. (#873)
client-server API response for rooms with restricted join rules, as required by Matrix 1.15.
1 parent edfe298 commit 44d3bf5

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

tests/room_summary_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Tests the GET /_matrix/client/v1/room_summary/{roomIdOrAlias} endpoint
2+
// as specified in https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv1room_summaryroomidoralias
3+
4+
package tests
5+
6+
import (
7+
"testing"
8+
9+
"github.com/matrix-org/complement"
10+
"github.com/matrix-org/complement/helpers"
11+
"github.com/matrix-org/complement/match"
12+
"github.com/matrix-org/complement/must"
13+
)
14+
15+
// TestRoomSummaryAllowedRoomIDs checks that the /summary endpoint includes
16+
// allowed_room_ids for rooms with restricted join rules, and omits the field
17+
// for rooms that do not use restricted join rules.
18+
func TestRoomSummaryAllowedRoomIDs(t *testing.T) {
19+
deployment := complement.Deploy(t, 1)
20+
defer deployment.Destroy(t)
21+
22+
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
23+
24+
// Create a space that will be referenced by the restricted room.
25+
space := alice.MustCreateRoom(t, map[string]interface{}{
26+
"preset": "public_chat",
27+
"creation_content": map[string]interface{}{
28+
"type": "m.space",
29+
},
30+
})
31+
32+
// Create a room version 8 room with restricted join rules allowing members
33+
// of the space above.
34+
restrictedRoom := alice.MustCreateRoom(t, map[string]interface{}{
35+
"preset": "public_chat",
36+
"room_version": "8",
37+
"initial_state": []map[string]interface{}{
38+
{
39+
"type": "m.room.join_rules",
40+
"state_key": "",
41+
"content": map[string]interface{}{
42+
"join_rule": "restricted",
43+
"allow": []map[string]interface{}{
44+
{
45+
"type": "m.room_membership",
46+
"room_id": &space,
47+
},
48+
},
49+
},
50+
},
51+
},
52+
})
53+
54+
// Create an invite-only room.
55+
inviteRoom := alice.MustCreateRoom(t, map[string]interface{}{
56+
"preset": "private_chat",
57+
})
58+
59+
t.Run("restricted room includes allowed_room_ids", func(t *testing.T) {
60+
res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v1", "room_summary", restrictedRoom})
61+
must.MatchResponse(t, res, match.HTTPResponse{
62+
StatusCode: 200,
63+
JSON: []match.JSON{
64+
match.JSONKeyEqual("room_id", restrictedRoom),
65+
match.JSONKeyEqual("join_rule", "restricted"),
66+
match.JSONKeyEqual("allowed_room_ids", []interface{}{space}),
67+
},
68+
})
69+
})
70+
71+
t.Run("non-restricted room omits allowed_room_ids", func(t *testing.T) {
72+
res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v1", "room_summary", inviteRoom})
73+
must.MatchResponse(t, res, match.HTTPResponse{
74+
StatusCode: 200,
75+
JSON: []match.JSON{
76+
match.JSONKeyEqual("room_id", inviteRoom),
77+
match.JSONKeyMissing("allowed_room_ids"),
78+
},
79+
})
80+
})
81+
}

0 commit comments

Comments
 (0)