-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fd3a555
Change SyncUntil* functions to return next_batch
DMRobertson 301f2e9
Add a matcher which checks that a key is missing
910528e
Reproduce matrix-org/synapse#11506
5963201
goimports
908f4d1
SyncUntilGlobalAccountDataHas
3373df1
Explicitly wait for the ignore to be synced
a347f1e
Fix format of the ignore request
f38ae64
Goimports
0b453d9
Blocklist this test on Dendrite
dfc81b7
Use lowerCamelCase for variables
512c226
Use r0 instead of v3
1086814
Try without dendrite blacklist
7f6ec25
Revert "Try without dendrite blacklist"
8b434d7
Describe this as a regression test
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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,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. | ||
// | ||
// This is a regression test for | ||
// https://github.com/matrix-org/synapse/issues/11506 | ||
// to ensure that Synapse complies with this part of the spec. | ||
func TestInviteFromIgnoredUsersDoesNotAppearInSync(t *testing.T) { | ||
deployment := Deploy(t, b.BlueprintCleanHS) | ||
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. | ||
publicRoom := alice.CreateRoom(t, map[string]interface{}{ | ||
"preset": "public_chat", | ||
}) | ||
|
||
// Alice waits to see the join event. | ||
alice.SyncUntilTimelineHas( | ||
t, publicRoom, 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", "r0", "user", alice.UserID, "account_data", "m.ignored_user_list"}, | ||
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", "r0", "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), | ||
}, | ||
}) | ||
} |
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.
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.
This test could be much simpler, I think, by starting with
BlueprintOneToOneRoom
? I'm not sure the third user is very helpful here.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.
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 comment
The 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 comment
The 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 comment
The 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?)