forked from matrix-org/complement
-
Notifications
You must be signed in to change notification settings - Fork 0
Famedly release/v1.161 #26
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0116400
bump: gomatrixserverlib to latest commit (#915)
jason-famedly 003643e
Bump zizmorcore/zizmor-action from 0.6.1 to 0.6.2 in the minor-and-pa…
dependabot[bot] 11ba33a
Bump the minor-and-patches group across 1 directory with 2 updates (#…
dependabot[bot] 7b9ab15
Implement MSC3389: Relation redactions tests (#913)
bxdxnn cb9f457
Merge remote-tracking branch 'upstream/release-v1.161' into famedly-r…
itsoyou 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
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
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,11 @@ | ||
| package tests | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/matrix-org/complement" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| complement.TestMain(m, "msc3389") | ||
| } |
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,155 @@ | ||
| package tests | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/matrix-org/complement" | ||
| "github.com/matrix-org/complement/b" | ||
| "github.com/matrix-org/complement/client" | ||
| "github.com/matrix-org/complement/helpers" | ||
| "github.com/matrix-org/complement/match" | ||
| "github.com/matrix-org/complement/must" | ||
| ) | ||
|
|
||
| // The room version that enables MSC3389 ("Redaction changes for events with a relation"). | ||
| const msc3389RoomVersion = "org.matrix.msc3389.10" | ||
|
|
||
| // sendRelatedEvent sends a reaction (m.annotation) targeting parentID, with an extra | ||
| // `key` field that should not survive redaction, and returns the event ID of the reaction. | ||
| func sendRelatedEvent(t *testing.T, alice *client.CSAPI, roomID, parentID string) string { | ||
| return alice.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.reaction", | ||
| Content: map[string]interface{}{ | ||
| "m.relates_to": map[string]interface{}{ | ||
| "rel_type": "m.annotation", | ||
| "event_id": parentID, | ||
| "key": "👍", | ||
| }, | ||
| }, | ||
| Sender: alice.UserID, | ||
| }) | ||
| } | ||
|
|
||
| // TestMSC3389RedactionPreservesRelation checks that, in a room version that implements | ||
| // MSC3389, redacting an event with an `m.relates_to` field keeps `rel_type` and `event_id` | ||
| // but strips every other key (such as the reaction `key`). | ||
| func TestMSC3389RedactionPreservesRelation(t *testing.T) { | ||
| deployment := complement.Deploy(t, 1) | ||
| defer deployment.Destroy(t) | ||
|
|
||
| alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
|
|
||
| // Alice creates a room in the MSC3389 unstable room version. | ||
| roomID := alice.MustCreateRoom(t, map[string]interface{}{ | ||
| "preset": "public_chat", | ||
| "room_version": msc3389RoomVersion, | ||
| }) | ||
|
|
||
| parentID := alice.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "root", | ||
| }, | ||
| Sender: alice.UserID, | ||
| }) | ||
|
|
||
| reactionID := sendRelatedEvent(t, alice, roomID, parentID) | ||
|
|
||
| // Verify the original event is fully intact before redaction. | ||
| eventJsonBefore := alice.MustGetEvent(t, roomID, reactionID) | ||
| must.MatchGJSON(t, eventJsonBefore, | ||
| match.JSONKeyEqual("content.m.relates_to.rel_type", "m.annotation"), | ||
| match.JSONKeyEqual("content.m.relates_to.event_id", parentID), | ||
| match.JSONKeyEqual("content.m.relates_to.key", "👍"), | ||
| ) | ||
|
|
||
| alice.MustSendRedaction(t, roomID, map[string]interface{}{}, reactionID) | ||
|
|
||
| // After redaction the `m.relates_to` object is retained, but only `rel_type` and | ||
| // `event_id` survive; the `key` is removed. | ||
| eventJsonAfter := alice.MustGetEvent(t, roomID, reactionID) | ||
| must.MatchGJSON(t, eventJsonAfter, | ||
| match.JSONKeyEqual("content.m.relates_to.rel_type", "m.annotation"), | ||
| match.JSONKeyEqual("content.m.relates_to.event_id", parentID), | ||
| match.JSONKeyMissing("content.m.relates_to.key"), | ||
| ) | ||
| } | ||
|
|
||
| // TestMSC3389RedactionStripsRelationInOlderVersions checks the contrast: in a room version | ||
| // that predates MSC3389 (e.g. v9), redaction removes the whole `m.relates_to` field. | ||
| func TestMSC3389RedactionStripsRelationInOlderVersions(t *testing.T) { | ||
| deployment := complement.Deploy(t, 1) | ||
| defer deployment.Destroy(t) | ||
|
|
||
| alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
|
|
||
| roomID := alice.MustCreateRoom(t, map[string]interface{}{ | ||
| "preset": "public_chat", | ||
| "room_version": "9", | ||
| }) | ||
|
|
||
| parentID := alice.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "root", | ||
| }, | ||
| Sender: alice.UserID, | ||
| }) | ||
|
|
||
| reactionID := sendRelatedEvent(t, alice, roomID, parentID) | ||
|
|
||
| alice.MustSendRedaction(t, roomID, map[string]interface{}{}, reactionID) | ||
|
|
||
| // In room v9 the whole `m.relates_to` is stripped, leaving no content. | ||
| eventJsonAfter := alice.MustGetEvent(t, roomID, reactionID) | ||
| must.MatchGJSON(t, eventJsonAfter, | ||
| match.JSONKeyMissing("content.m.relates_to"), | ||
| ) | ||
| } | ||
|
|
||
| // TestMSC3389RedactionPreservesPlainRelation checks that an `m.relates_to` containing only | ||
| // `rel_type` and `event_id` (with no extra keys) survives redaction unchanged. | ||
| func TestMSC3389RedactionPreservesPlainRelation(t *testing.T) { | ||
| deployment := complement.Deploy(t, 1) | ||
| defer deployment.Destroy(t) | ||
|
|
||
| alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
|
|
||
| roomID := alice.MustCreateRoom(t, map[string]interface{}{ | ||
| "preset": "public_chat", | ||
| "room_version": msc3389RoomVersion, | ||
| }) | ||
|
|
||
| parentID := alice.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "root", | ||
| }, | ||
| Sender: alice.UserID, | ||
| }) | ||
|
|
||
| // A threaded reply has no extra `m.relates_to` keys beyond rel_type + event_id. | ||
| replyID := alice.SendEventSynced(t, roomID, b.Event{ | ||
| Type: "m.room.message", | ||
| Content: map[string]interface{}{ | ||
| "msgtype": "m.text", | ||
| "body": "reply", | ||
| "m.relates_to": map[string]interface{}{ | ||
| "rel_type": "m.thread", | ||
| "event_id": parentID, | ||
| }, | ||
| }, | ||
| Sender: alice.UserID, | ||
| }) | ||
|
|
||
| alice.MustSendRedaction(t, roomID, map[string]interface{}{}, replyID) | ||
|
|
||
| eventJsonAfter := alice.MustGetEvent(t, roomID, replyID) | ||
| must.MatchGJSON(t, eventJsonAfter, | ||
| match.JSONKeyEqual("content.m.relates_to.rel_type", "m.thread"), | ||
| match.JSONKeyEqual("content.m.relates_to.event_id", parentID), | ||
| ) | ||
| } | ||
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.