-
Notifications
You must be signed in to change notification settings - Fork 47
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
Test that invites from ignored users are omitted from incremental syncs #267
Changes from 9 commits
fd3a555
301f2e9
910528e
5963201
908f4d1
3373df1
a347f1e
f38ae64
0b453d9
dfc81b7
512c226
1086814
7f6ec25
8b434d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// +build !dendrite_blacklist | ||
|
||
// Rationale for being included in Dendrite's blacklist: https://github.com/matrix-org/dendrite/issues/600 | ||
package csapi_tests | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/tidwall/gjson" | ||
|
||
"github.com/matrix-org/complement/internal/b" | ||
"github.com/matrix-org/complement/internal/client" | ||
"github.com/matrix-org/complement/internal/match" | ||
"github.com/matrix-org/complement/internal/must" | ||
) | ||
|
||
// The Spec says here | ||
// https://spec.matrix.org/v1.1/client-server-api/#server-behaviour-13 | ||
// that | ||
// > Servers must not send room invites from ignored users to clients. | ||
// | ||
// Synapse does not have this property, as detailed in | ||
// https://github.com/matrix-org/synapse/issues/11506. | ||
// This reproduces that bug. | ||
func TestInviteFromIgnoredUsersDoesNotAppearInSync(t *testing.T) { | ||
deployment := Deploy(t, b.BlueprintCleanHS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test could be much simpler, I think, by starting with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The third user was an attempt to stop this test from being racey. We want to be convinced that the server has processed Bob's invite and chosen to ignore it. I could assert that there's no invite from Bob in Alice's next sync, but... what if that's only true because Alice synced really quickly? In #237 (comment) suggested sending and awaiting a dummy event. The third user was my attempt at doing something similar here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could do that by sending a dummy user into the room, yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, would Alice expect to see state updates for a room she's invited to, but hasn't joined yet? If so that would be much clearer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, they would not see those. I think I'm confused though -- isn't this just checking that some sort of events got processed by any room? (I.e. sync is working at all?) |
||
defer deployment.Destroy(t) | ||
alice := deployment.RegisterUser(t, "hs1", "alice", "sufficiently_long_password_alice") | ||
bob := deployment.RegisterUser(t, "hs1", "bob", "sufficiently_long_password_bob") | ||
chris := deployment.RegisterUser(t, "hs1", "chris", "sufficiently_long_password_chris") | ||
|
||
// Alice creates a room for herself. | ||
public_room := alice.CreateRoom(t, map[string]interface{}{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not use underscores for variable names. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, old habits. Is there some way to configure |
||
"preset": "public_chat", | ||
}) | ||
|
||
// Alice waits to see the join event. | ||
alice.SyncUntilTimelineHas( | ||
t, public_room, func(ev gjson.Result) bool { | ||
return ev.Get("type").Str == "m.room.member" && | ||
ev.Get("state_key").Str == alice.UserID && | ||
ev.Get("content.membership").Str == "join" | ||
}, | ||
) | ||
|
||
// Alice ignores Bob. | ||
alice.MustDoFunc( | ||
t, | ||
"PUT", | ||
[]string{"_matrix", "client", "v3", "user", alice.UserID, "account_data", "m.ignored_user_list"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dendrite doesn't implement any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All r0 endpoints became v3 with Matrix 1.1 -- @DMRobertson Maybe we should just use r0 for now here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to use r0; I was just blindly going by what the latest spec said. |
||
client.WithJSONBody(t, map[string]interface{}{ | ||
"ignored_users": map[string]interface{}{ | ||
bob.UserID: map[string]interface{}{}, | ||
}, | ||
}), | ||
) | ||
|
||
// Alice waits to see that the ignore was successful. | ||
sinceJoinedAndIgnored := alice.SyncUntilGlobalAccountDataHas( | ||
t, | ||
func(ev gjson.Result) bool { | ||
t.Logf(ev.Raw + "\n") | ||
return ev.Get("type").Str == "m.ignored_user_list" && | ||
ev.Get("content.ignored_users."+client.GjsonEscape(bob.UserID)).Exists() | ||
}, | ||
) | ||
|
||
// Bob invites Alice to a private room. | ||
bobRoom := bob.CreateRoom(t, map[string]interface{}{ | ||
"preset": "private_chat", | ||
"invite": []string{alice.UserID}, | ||
}) | ||
|
||
// So does Chris. | ||
chrisRoom := chris.CreateRoom(t, map[string]interface{}{ | ||
"preset": "private_chat", | ||
"invite": []string{alice.UserID}, | ||
}) | ||
|
||
// Alice waits until she's seen Chris's invite. | ||
alice.SyncUntilInvitedTo(t, chrisRoom) | ||
|
||
// We re-request the sync with a `since` token. We should see Chris's invite, but not Bob's. | ||
queryParams := url.Values{ | ||
"since": {sinceJoinedAndIgnored}, | ||
"timeout": {"0"}, | ||
} | ||
// Note: SyncUntil only runs its callback on array elements. I want to investigate an object. | ||
// So let's make the HTTP request more directly. | ||
response := alice.MustDoFunc( | ||
t, | ||
"GET", | ||
[]string{"_matrix", "client", "v3", "sync"}, | ||
client.WithQueries(queryParams), | ||
) | ||
bobRoomPath := "rooms.invite." + client.GjsonEscape(bobRoom) | ||
chrisRoomPath := "rooms.invite." + client.GjsonEscape(chrisRoom) | ||
must.MatchResponse(t, response, match.HTTPResponse{ | ||
JSON: []match.JSON{ | ||
match.JSONKeyMissing(bobRoomPath), | ||
match.JSONKeyPresent(chrisRoomPath), | ||
}, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe?
I don't think this is true though since this is now fixed, it might be better to say: