Skip to content

Commit 6c854fc

Browse files
authored
MSC4306: Thread Subscriptions Tests (#795)
* MSC4306: Thread Subscriptions Tests * Enable MSC4306 tests in CI for Synapse * GetPushRule -> MustGetPushRule * Add non-failing GetPushRule * Disable MSC4306 push rules in non-MSC4306 test
1 parent fd97e2b commit 6c854fc

File tree

6 files changed

+387
-10
lines changed

6 files changed

+387
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- homeserver: Synapse
4343
repo: element-hq/synapse
4444
tags: synapse_blacklist
45-
packages: ./tests/msc3874 ./tests/msc3902
45+
packages: ./tests/msc3874 ./tests/msc3902 ./tests/msc4306
4646
env: "COMPLEMENT_ENABLE_DIRTY_RUNS=1 COMPLEMENT_SHARE_ENV_PREFIX=PASS_ PASS_SYNAPSE_COMPLEMENT_DATABASE=sqlite"
4747
timeout: 20m
4848

client/client.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ func (c *CSAPI) GetAllPushRules(t ct.TestLike) gjson.Result {
261261
return gjson.ParseBytes(pushRulesBytes)
262262
}
263263

264-
// GetPushRule queries the contents of a client's push rule by scope, kind and rule ID.
264+
// MustGetPushRule queries the contents of a client's push rule by scope, kind and rule ID.
265265
// A parsed gjson result is returned. Fails the test if the query to server returns a non-2xx status code.
266266
//
267267
// Example of checking that a global underride rule contains the expected actions:
268268
//
269-
// containsDisplayNameRule := c.GetPushRule(t, "global", "underride", ".m.rule.contains_display_name")
269+
// containsDisplayNameRule := c.MustGetPushRule(t, "global", "underride", ".m.rule.contains_display_name")
270270
// must.MatchGJSON(
271271
// t,
272272
// containsDisplayNameRule,
@@ -276,14 +276,23 @@ func (c *CSAPI) GetAllPushRules(t ct.TestLike) gjson.Result {
276276
// map[string]interface{}{"set_tweak": "highlight"},
277277
// }),
278278
// )
279-
func (c *CSAPI) GetPushRule(t ct.TestLike, scope string, kind string, ruleID string) gjson.Result {
279+
func (c *CSAPI) MustGetPushRule(t ct.TestLike, scope string, kind string, ruleID string) gjson.Result {
280280
t.Helper()
281281

282-
res := c.MustDo(t, "GET", []string{"_matrix", "client", "v3", "pushrules", scope, kind, ruleID})
282+
res := c.GetPushRule(t, scope, kind, ruleID)
283+
mustRespond2xx(t, res)
284+
283285
pushRuleBytes := ParseJSON(t, res)
284286
return gjson.ParseBytes(pushRuleBytes)
285287
}
286288

289+
// GetPushRule queries the contents of a client's push rule by scope, kind and rule ID.
290+
func (c *CSAPI) GetPushRule(t ct.TestLike, scope string, kind string, ruleID string) *http.Response {
291+
t.Helper()
292+
293+
return c.Do(t, "GET", []string{"_matrix", "client", "v3", "pushrules", scope, kind, ruleID})
294+
}
295+
287296
// SetPushRule creates a new push rule on the user, or modifies an existing one.
288297
// If `before` or `after` parameters are not set to an empty string, their values
289298
// will be set as the `before` and `after` query parameters respectively on the
@@ -310,6 +319,14 @@ func (c *CSAPI) SetPushRule(t ct.TestLike, scope string, kind string, ruleID str
310319
return c.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "pushrules", scope, kind, ruleID}, WithJSONBody(t, body), WithQueries(queryParams))
311320
}
312321

322+
// MustDisablePushRule disables a push rule on the user.
323+
// Fails the test if response is non-2xx.
324+
func (c *CSAPI) MustDisablePushRule(t ct.TestLike, scope string, kind string, ruleID string) {
325+
c.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "pushrules", scope, kind, ruleID, "enabled"}, WithJSONBody(t, map[string]interface{}{
326+
"enabled": false,
327+
}))
328+
}
329+
313330
// Unsafe_SendEventUnsynced sends `e` into the room. This function is UNSAFE as it does not wait
314331
// for the event to be fully processed. This can cause flakey tests. Prefer `SendEventSynced`.
315332
// Returns the event ID of the sent event.

tests/csapi/thread_notifications_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ func syncHasThreadedReadReceipt(roomID, userID, eventID, threadID string) client
5151
})
5252
}
5353

54+
// Disables push rules that are introduced in MSC4306 (if present),
55+
// because they interfere with the normal semantics of notifications in threads.
56+
func disableMsc4306PushRules(t *testing.T, user *client.CSAPI) {
57+
rules := []string{".io.element.msc4306.rule.subscribed_thread", ".io.element.msc4306.rule.unsubscribed_thread"}
58+
for _, rule := range rules {
59+
res := user.GetPushRule(t, "global", "postcontent", rule)
60+
if res.StatusCode == 404 {
61+
// No push rule to disable
62+
continue
63+
}
64+
65+
user.MustDisablePushRule(t, "global", "postcontent", rule)
66+
}
67+
}
68+
5469
// Test behavior of threaded receipts and notifications.
5570
//
5671
// 1. Send a series of messages, some of which are in threads.
@@ -79,7 +94,9 @@ func TestThreadedReceipts(t *testing.T) {
7994

8095
// Create a room with alice and bob.
8196
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
97+
disableMsc4306PushRules(t, alice)
8298
bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
99+
disableMsc4306PushRules(t, bob)
83100

84101
roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"})
85102
bob.MustJoinRoom(t, roomID, nil)
@@ -312,7 +329,9 @@ func TestThreadReceiptsInSyncMSC4102(t *testing.T) {
312329

313330
// Create a room with alice and bob.
314331
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
332+
disableMsc4306PushRules(t, alice)
315333
bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{})
334+
disableMsc4306PushRules(t, bob)
316335
roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"})
317336
bob.MustJoinRoom(t, roomID, []spec.ServerName{
318337
deployment.GetFullyQualifiedHomeserverName(t, "hs1"),

tests/msc3930/msc3930_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestPollsLocalPushRules(t *testing.T) {
3939
// Request each of the push rule IDs defined by MSC3930 and verify their structure.
4040

4141
// This push rule silences all poll responses.
42-
pollResponseRule := alice.GetPushRule(t, "global", "override", pollResponseRuleID)
42+
pollResponseRule := alice.MustGetPushRule(t, "global", "override", pollResponseRuleID)
4343
must.MatchGJSON(
4444
t,
4545
pollResponseRule,
@@ -55,7 +55,7 @@ func TestPollsLocalPushRules(t *testing.T) {
5555
)
5656

5757
// This push rule creates a sound and notifies the user when a poll is started in a one-to-one room.
58-
pollStartOneToOneRule := alice.GetPushRule(t, "global", "underride", pollStartOneToOneRuleID)
58+
pollStartOneToOneRule := alice.MustGetPushRule(t, "global", "underride", pollStartOneToOneRuleID)
5959
must.MatchGJSON(
6060
t,
6161
pollStartOneToOneRule,
@@ -78,7 +78,7 @@ func TestPollsLocalPushRules(t *testing.T) {
7878
)
7979

8080
// This push rule creates a sound and notifies the user when a poll is ended in a one-to-one room.
81-
pollEndOneToOneRule := alice.GetPushRule(t, "global", "underride", pollEndOneToOneRuleID)
81+
pollEndOneToOneRule := alice.MustGetPushRule(t, "global", "underride", pollEndOneToOneRuleID)
8282
must.MatchGJSON(
8383
t,
8484
pollEndOneToOneRule,
@@ -101,7 +101,7 @@ func TestPollsLocalPushRules(t *testing.T) {
101101
)
102102

103103
// This push rule notifies the user when a poll is started in any room.
104-
pollStartRule := alice.GetPushRule(t, "global", "underride", pollStartRuleID)
104+
pollStartRule := alice.MustGetPushRule(t, "global", "underride", pollStartRuleID)
105105
must.MatchGJSON(
106106
t,
107107
pollStartRule,
@@ -118,7 +118,7 @@ func TestPollsLocalPushRules(t *testing.T) {
118118
)
119119

120120
// This push rule notifies the user when a poll is ended in any room.
121-
pollEndRule := alice.GetPushRule(t, "global", "underride", pollEndRuleID)
121+
pollEndRule := alice.MustGetPushRule(t, "global", "underride", pollEndRuleID)
122122
must.MatchGJSON(
123123
t,
124124
pollEndRule,

tests/msc4306/main_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/matrix-org/complement"
7+
)
8+
9+
func TestMain(m *testing.M) {
10+
complement.TestMain(m, "msc4306")
11+
}

0 commit comments

Comments
 (0)