|
| 1 | +// +build !dendrite_blacklist |
| 2 | + |
| 3 | +// Rationale for being included in Dendrite's blacklist: https://github.com/matrix-org/dendrite/issues/600 |
| 4 | +package csapi_tests |
| 5 | + |
| 6 | +import ( |
| 7 | + "net/url" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/tidwall/gjson" |
| 11 | + |
| 12 | + "github.com/matrix-org/complement/internal/b" |
| 13 | + "github.com/matrix-org/complement/internal/client" |
| 14 | + "github.com/matrix-org/complement/internal/match" |
| 15 | + "github.com/matrix-org/complement/internal/must" |
| 16 | +) |
| 17 | + |
| 18 | +// The Spec says here |
| 19 | +// https://spec.matrix.org/v1.1/client-server-api/#server-behaviour-13 |
| 20 | +// that |
| 21 | +// > Servers must not send room invites from ignored users to clients. |
| 22 | +// |
| 23 | +// This is a regression test for |
| 24 | +// https://github.com/matrix-org/synapse/issues/11506 |
| 25 | +// to ensure that Synapse complies with this part of the spec. |
| 26 | +func TestInviteFromIgnoredUsersDoesNotAppearInSync(t *testing.T) { |
| 27 | + deployment := Deploy(t, b.BlueprintCleanHS) |
| 28 | + defer deployment.Destroy(t) |
| 29 | + alice := deployment.RegisterUser(t, "hs1", "alice", "sufficiently_long_password_alice") |
| 30 | + bob := deployment.RegisterUser(t, "hs1", "bob", "sufficiently_long_password_bob") |
| 31 | + chris := deployment.RegisterUser(t, "hs1", "chris", "sufficiently_long_password_chris") |
| 32 | + |
| 33 | + // Alice creates a room for herself. |
| 34 | + publicRoom := alice.CreateRoom(t, map[string]interface{}{ |
| 35 | + "preset": "public_chat", |
| 36 | + }) |
| 37 | + |
| 38 | + // Alice waits to see the join event. |
| 39 | + alice.SyncUntilTimelineHas( |
| 40 | + t, publicRoom, func(ev gjson.Result) bool { |
| 41 | + return ev.Get("type").Str == "m.room.member" && |
| 42 | + ev.Get("state_key").Str == alice.UserID && |
| 43 | + ev.Get("content.membership").Str == "join" |
| 44 | + }, |
| 45 | + ) |
| 46 | + |
| 47 | + // Alice ignores Bob. |
| 48 | + alice.MustDoFunc( |
| 49 | + t, |
| 50 | + "PUT", |
| 51 | + []string{"_matrix", "client", "r0", "user", alice.UserID, "account_data", "m.ignored_user_list"}, |
| 52 | + client.WithJSONBody(t, map[string]interface{}{ |
| 53 | + "ignored_users": map[string]interface{}{ |
| 54 | + bob.UserID: map[string]interface{}{}, |
| 55 | + }, |
| 56 | + }), |
| 57 | + ) |
| 58 | + |
| 59 | + // Alice waits to see that the ignore was successful. |
| 60 | + sinceJoinedAndIgnored := alice.SyncUntilGlobalAccountDataHas( |
| 61 | + t, |
| 62 | + func(ev gjson.Result) bool { |
| 63 | + t.Logf(ev.Raw + "\n") |
| 64 | + return ev.Get("type").Str == "m.ignored_user_list" && |
| 65 | + ev.Get("content.ignored_users."+client.GjsonEscape(bob.UserID)).Exists() |
| 66 | + }, |
| 67 | + ) |
| 68 | + |
| 69 | + // Bob invites Alice to a private room. |
| 70 | + bobRoom := bob.CreateRoom(t, map[string]interface{}{ |
| 71 | + "preset": "private_chat", |
| 72 | + "invite": []string{alice.UserID}, |
| 73 | + }) |
| 74 | + |
| 75 | + // So does Chris. |
| 76 | + chrisRoom := chris.CreateRoom(t, map[string]interface{}{ |
| 77 | + "preset": "private_chat", |
| 78 | + "invite": []string{alice.UserID}, |
| 79 | + }) |
| 80 | + |
| 81 | + // Alice waits until she's seen Chris's invite. |
| 82 | + alice.SyncUntilInvitedTo(t, chrisRoom) |
| 83 | + |
| 84 | + // We re-request the sync with a `since` token. We should see Chris's invite, but not Bob's. |
| 85 | + queryParams := url.Values{ |
| 86 | + "since": {sinceJoinedAndIgnored}, |
| 87 | + "timeout": {"0"}, |
| 88 | + } |
| 89 | + // Note: SyncUntil only runs its callback on array elements. I want to investigate an object. |
| 90 | + // So let's make the HTTP request more directly. |
| 91 | + response := alice.MustDoFunc( |
| 92 | + t, |
| 93 | + "GET", |
| 94 | + []string{"_matrix", "client", "r0", "sync"}, |
| 95 | + client.WithQueries(queryParams), |
| 96 | + ) |
| 97 | + bobRoomPath := "rooms.invite." + client.GjsonEscape(bobRoom) |
| 98 | + chrisRoomPath := "rooms.invite." + client.GjsonEscape(chrisRoom) |
| 99 | + must.MatchResponse(t, response, match.HTTPResponse{ |
| 100 | + JSON: []match.JSON{ |
| 101 | + match.JSONKeyMissing(bobRoomPath), |
| 102 | + match.JSONKeyPresent(chrisRoomPath), |
| 103 | + }, |
| 104 | + }) |
| 105 | +} |
0 commit comments