-
Notifications
You must be signed in to change notification settings - Fork 69
Add some tests for push rule behavior on room upgrade #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
07387a0
Add some tests for push rule behavior on room upgrade
MadLittleMods 3fdbd02
Make the test generic with multiple push rules types
MadLittleMods cc58ec9
Revert "Make the test generic with multiple push rules types"
MadLittleMods 1167cee
Add `MustUpgradeRoom`
MadLittleMods d53a307
Test multiple users
MadLittleMods e00c1c0
Better remote tests
MadLittleMods fd90c90
Run tests in parallel
MadLittleMods ad2a7ea
More robust test (`MustAwaitPartialStateJoinCompletion`)
MadLittleMods 5ebcc9f
Even better test
MadLittleMods e71b03e
Add manually upgraded variant and more robust
MadLittleMods 4fb255c
Specify predecessor when manually upgrading room
MadLittleMods 369250a
Skip test until Synapse is fixed
MadLittleMods 3b4ca0b
Use `SetPushRule`
MadLittleMods 6e2c6f2
Wait/sync until push rules show up
MadLittleMods 10755c2
Fix waiting since the correct spot
MadLittleMods a7da686
Merge branch 'main' into madlittlemods/room-upgrade-push-rules
MadLittleMods 7a601fa
Skip earlier
MadLittleMods 201a93f
Skip on Dendrite
MadLittleMods 126cc9b
This does sometimes pass but skip since not reliable
MadLittleMods 32aff46
Accurate plural language
MadLittleMods bae2b74
`upgradeDescriptorPrefix` typo
MadLittleMods 87d6ef0
Explain state of the spec
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| package csapi_tests | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/matrix-org/complement" | ||
| "github.com/matrix-org/complement/client" | ||
| "github.com/matrix-org/complement/helpers" | ||
| "github.com/matrix-org/complement/match" | ||
| "github.com/matrix-org/complement/must" | ||
| "github.com/matrix-org/gomatrixserverlib/spec" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestPushRuleRoomUpgrade(t *testing.T) { | ||
| deployment := complement.Deploy(t, 2) | ||
| defer deployment.Destroy(t) | ||
|
|
||
| alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
| alice2 := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
| bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) | ||
| bob2 := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) | ||
|
|
||
| t.Run("parallel", func(t *testing.T) { | ||
| // When a homeserver becomes aware of a room upgrade (upgrade is done on local | ||
| // homeserver), it should copy over any existing push rules for all of its local users | ||
| // from the old room to the new room at the time of upgrade. | ||
| t.Run("upgrading a room carries over existing push rules for local users", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Create a room | ||
| roomID := alice.MustCreateRoom(t, map[string]interface{}{ | ||
| "preset": "public_chat", | ||
| "room_version": "10", | ||
| }) | ||
| // Have alice2 join the room | ||
| // | ||
| // We use two users to ensure that all users get taken care of (not just the person | ||
| // upgrading the room). | ||
| alice2.MustJoinRoom(t, roomID, nil) | ||
|
|
||
| // Add some push rules | ||
| alice.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "pushrules", "global", "room", roomID}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "actions": []string{"dont_notify"}, | ||
| }), | ||
| ) | ||
| alice2.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "pushrules", "global", "room", roomID}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "actions": []string{"dont_notify"}, | ||
| }), | ||
| ) | ||
|
|
||
| // Sanity check the push rules are in the expected state before the upgrade | ||
| for _, client := range []*client.CSAPI{alice, alice2} { | ||
| pushRulesBefore := client.GetAllPushRules(t) | ||
| must.MatchGJSON(t, pushRulesBefore, | ||
| match.JSONCheckOff("global.room", []interface{}{ | ||
| roomID, | ||
| }, | ||
| match.CheckOffMapper(func(r gjson.Result) interface{} { return r.Get("rule_id").Str }), | ||
| match.CheckOffForEach(func(roomIDFromPushRule interface{}, result gjson.Result) error { | ||
| return match.JSONKeyEqual("actions.0", "dont_notify")(result) | ||
| }), | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| // Upgrade the room | ||
| newRoomID := alice.MustUpgradeRoom(t, roomID, "11") | ||
|
|
||
| // Alice2 joins the new room | ||
| alice2.MustJoinRoom(t, newRoomID, nil) | ||
|
|
||
| // Sanity check the push rules are in the expected state after the upgrade | ||
| for _, client := range []*client.CSAPI{alice, alice2} { | ||
| pushRulesAfter := client.GetAllPushRules(t) | ||
| must.MatchGJSON(t, pushRulesAfter, | ||
| match.JSONCheckOff("global.room", []interface{}{ | ||
| roomID, | ||
| newRoomID, | ||
| }, | ||
| match.CheckOffMapper(func(r gjson.Result) interface{} { return r.Get("rule_id").Str }), | ||
| match.CheckOffForEach(func(roomIDFromPushRule interface{}, result gjson.Result) error { | ||
| return match.JSONKeyEqual("actions.0", "dont_notify")(result) | ||
| }), | ||
| ), | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| // When a homeserver becomes aware of a room upgrade (upgrade is done on remote | ||
| // homeserver), it should copy over any existing push rules for all of its local users | ||
| // from the old room to the new room at the time of upgrade. | ||
| t.Run("joining a remote upgraded room carries over existing push rules", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Alice create a room | ||
| roomID := alice.MustCreateRoom(t, map[string]interface{}{ | ||
| "preset": "public_chat", | ||
| "room_version": "10", | ||
| }) | ||
| // Remote bob joins the room | ||
| bob.MustJoinRoom(t, roomID, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
| }) | ||
| // Remote bob2 joins the room | ||
| // | ||
| // We use two users to ensure that all users get taken care of (not just the first | ||
| // user on the homeserver). | ||
| bob2.MustJoinRoom(t, roomID, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
| }) | ||
|
|
||
| // Add some push rules | ||
| bob.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "pushrules", "global", "room", roomID}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "actions": []string{"dont_notify"}, | ||
| }), | ||
| ) | ||
| bob2.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "pushrules", "global", "room", roomID}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "actions": []string{"dont_notify"}, | ||
| }), | ||
| ) | ||
|
|
||
| // Sanity check the push rules are in the expected state before the upgrade | ||
| for _, client := range []*client.CSAPI{bob, bob2} { | ||
| pushRulesBefore := client.GetAllPushRules(t) | ||
| must.MatchGJSON(t, pushRulesBefore, | ||
| match.JSONCheckOff("global.room", []interface{}{ | ||
| roomID, | ||
| }, | ||
| match.CheckOffMapper(func(r gjson.Result) interface{} { return r.Get("rule_id").Str }), | ||
| match.CheckOffForEach(func(roomIDFromPushRule interface{}, result gjson.Result) error { | ||
| return match.JSONKeyEqual("actions.0", "dont_notify")(result) | ||
| }), | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| // Upgrade the room | ||
| newRoomID := alice.MustUpgradeRoom(t, roomID, "11") | ||
|
|
||
| // Remote bob joins the new room | ||
| bob.MustJoinRoom(t, newRoomID, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
| }) | ||
| // Remote bob2 joins the new room | ||
| bob2.MustJoinRoom(t, newRoomID, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
| }) | ||
|
|
||
| // Sanity check the push rules are in the expected state after the upgrade | ||
| for _, client := range []*client.CSAPI{bob, bob2} { | ||
| pushRulesAfter := client.GetAllPushRules(t) | ||
| must.MatchGJSON(t, pushRulesAfter, | ||
| match.JSONCheckOff("global.room", []interface{}{ | ||
| roomID, | ||
| newRoomID, | ||
| }, | ||
| match.CheckOffMapper(func(r gjson.Result) interface{} { return r.Get("rule_id").Str }), | ||
| match.CheckOffForEach(func(roomIDFromPushRule interface{}, result gjson.Result) error { | ||
| return match.JSONKeyEqual("actions.0", "dont_notify")(result) | ||
| }), | ||
| ), | ||
| ) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.