-
Notifications
You must be signed in to change notification settings - Fork 69
Add test case reproducing matrix-org/synapse#5677 for local users #199
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
26 commits
Select commit
Hold shift + click to select a range
cd709e8
Add test case reproducing matrix-org/synapse#5677
DMRobertson 05d148a
goimports
DMRobertson 877f6a1
Mark MustDo as Deprecated
DMRobertson 8209286
Introduce SyncUntilInvitedTo
DMRobertson 07afbaa
client: Helper function SearchUserDirectory
DMRobertson 75ef397
match: use rs.Exists() in JSONKeyEqual
DMRobertson 68cf89a
match: matcher that seeks an array of a fixed size
DMRobertson ce8f3a9
Update tests after review
DMRobertson ed7d66e
Fix format string
DMRobertson 5435622
Make lint accept use of deprecated things
DMRobertson 6ce2fc4
Remove from synapse blacklist
DMRobertson 26aad20
Introduce `AnyOf` matcher
DMRobertson 9f4b9a0
Expand test cases to inspect Bob's behaviour too
DMRobertson a2e0d06
Tweak expected behaviour
DMRobertson b10655f
Enforce Displaynames in blueprints
DMRobertson b52c712
Fix typo
DMRobertson c95b011
Add case for remote user with per-room nickname
DMRobertson d650c5a
Ensure pub name, priv name & localpart all differ
DMRobertson 815cf7b
Remove testing comment
DMRobertson 4c95d45
Prefer MustDoFunc; test joining with private name
DMRobertson ef171f3
Fix PUT call to set displayname
DMRobertson 707b530
Cleanup deployment after test, not after setup!
DMRobertson 2b4609a
aliceId -> aliceUserID
DMRobertson 700e300
Allow remote users' displaynames to be localparts
DMRobertson 56bf3e3
Remove the tests which apply over federation
DMRobertson c0b3ecd
Blacklist tests for dendrite
DMRobertson 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
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,187 @@ | ||
| // +build !dendrite_blacklist | ||
|
|
||
| // Rationale for being included in Dendrite's blacklist: https://github.com/matrix-org/complement/pull/199#issuecomment-904852233 | ||
| package csapi_tests | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "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" | ||
| ) | ||
|
|
||
| const aliceUserID = "@alice:hs1" | ||
| const alicePublicName = "Alice Cooper" | ||
| const alicePrivateName = "Freddy" | ||
|
|
||
| var justAliceByPublicName = []match.JSON{ | ||
| match.JSONKeyArrayOfSize("results", 1), | ||
| match.JSONKeyEqual("results.0.display_name", alicePublicName), | ||
| match.JSONKeyEqual("results.0.user_id", aliceUserID), | ||
| } | ||
|
|
||
| var noResults = []match.JSON{ | ||
| match.JSONKeyArrayOfSize("results", 0), | ||
| } | ||
|
|
||
| func setupUsers(t *testing.T) (*client.CSAPI, *client.CSAPI, *client.CSAPI, func(*testing.T)) { | ||
| // Originally written to reproduce https://github.com/matrix-org/synapse/issues/5677 | ||
| // In that bug report, | ||
| // - Bob knows about Alice, and | ||
| // - Alice has revealed a private name to another friend X, | ||
| // - Bob can see that private name when he shouldn't be able to. | ||
| // | ||
| // I've tweaked the names to be more traditional: | ||
| // - Eve knows about Alice, | ||
| // - Alice reveals a private name to another friend Bob | ||
| // - Eve shouldn't be able to see that private name via the directory. | ||
| deployment := Deploy(t, b.BlueprintAlice) | ||
| cleanup := func(t *testing.T) { | ||
| deployment.Destroy(t) | ||
| } | ||
|
|
||
| alice := deployment.Client(t, "hs1", aliceUserID) | ||
| bob := deployment.RegisterUser(t, "hs1", "bob", "bob-has-a-very-secret-pw") | ||
| eve := deployment.RegisterUser(t, "hs1", "eve", "eve-has-a-very-secret-pw") | ||
|
|
||
| // Alice sets her profile displayname. This ensures that her | ||
| // public name, private name and userid localpart are all | ||
| // distinguishable, even case-insensitively. | ||
| alice.MustDoFunc( | ||
| t, | ||
| "PUT", | ||
| []string{"_matrix", "client", "r0", "profile", alice.UserID, "displayname"}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "displayname": alicePublicName, | ||
| }), | ||
| ) | ||
|
|
||
| // Alice creates a public room (so when Eve searches, she can see that Alice exists) | ||
| alice.CreateRoom(t, map[string]interface{}{"visibility": "public"}) | ||
| return alice, bob, eve, cleanup | ||
| } | ||
|
|
||
| func checkExpectations(t *testing.T, bob, eve *client.CSAPI) { | ||
| t.Run("Eve can find Alice by profile display name", func(t *testing.T) { | ||
| res := eve.MustDoFunc( | ||
| t, | ||
| "POST", | ||
| []string{"_matrix", "client", "r0", "user_directory", "search"}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "search_term": alicePublicName, | ||
| }), | ||
| ) | ||
| must.MatchResponse(t, res, match.HTTPResponse{JSON: justAliceByPublicName}) | ||
| }) | ||
|
|
||
| t.Run("Eve can find Alice by mxid", func(t *testing.T) { | ||
| res := eve.MustDoFunc( | ||
| t, | ||
| "POST", | ||
| []string{"_matrix", "client", "r0", "user_directory", "search"}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "search_term": aliceUserID, | ||
| }), | ||
| ) | ||
| must.MatchResponse(t, res, match.HTTPResponse{JSON: justAliceByPublicName}) | ||
| }) | ||
|
|
||
| t.Run("Eve cannot find Alice by room-specific name that Eve is not privy to", func(t *testing.T) { | ||
| res := eve.MustDoFunc( | ||
| t, | ||
| "POST", | ||
| []string{"_matrix", "client", "r0", "user_directory", "search"}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "search_term": alicePrivateName, | ||
| }), | ||
| ) | ||
| must.MatchResponse(t, res, match.HTTPResponse{JSON: noResults}) | ||
| }) | ||
|
|
||
| t.Run("Bob can find Alice by profile display name", func(t *testing.T) { | ||
| res := bob.MustDoFunc( | ||
| t, | ||
| "POST", | ||
| []string{"_matrix", "client", "r0", "user_directory", "search"}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "search_term": alicePublicName, | ||
| }), | ||
| ) | ||
| must.MatchResponse(t, res, match.HTTPResponse{ | ||
| JSON: justAliceByPublicName, | ||
| }) | ||
| }) | ||
|
|
||
| t.Run("Bob can find Alice by mxid", func(t *testing.T) { | ||
| res := bob.MustDoFunc( | ||
| t, | ||
| "POST", | ||
| []string{"_matrix", "client", "r0", "user_directory", "search"}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "search_term": aliceUserID, | ||
| }), | ||
| ) | ||
| must.MatchResponse(t, res, match.HTTPResponse{ | ||
|
DMRobertson marked this conversation as resolved.
|
||
| JSON: justAliceByPublicName, | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| func TestRoomSpecificUsernameChange(t *testing.T) { | ||
| alice, bob, eve, cleanup := setupUsers(t) | ||
| defer cleanup(t) | ||
|
|
||
| // Bob creates a new room and invites Alice. | ||
| privateRoom := bob.CreateRoom(t, map[string]interface{}{ | ||
| "visibility": "private", | ||
| "invite": []string{alice.UserID}, | ||
| }) | ||
|
|
||
| // Alice waits until she sees the invite, then accepts. | ||
| alice.SyncUntilInvitedTo(t, privateRoom) | ||
| alice.JoinRoom(t, privateRoom, nil) | ||
|
|
||
| // Alice reveals her private name to Bob | ||
| alice.MustDoFunc( | ||
| t, | ||
| "PUT", | ||
| []string{"_matrix", "client", "r0", "rooms", privateRoom, "state", "m.room.member", alice.UserID}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "displayname": alicePrivateName, | ||
| "membership": "join", | ||
| }), | ||
| ) | ||
|
|
||
| checkExpectations(t, bob, eve) | ||
| } | ||
|
|
||
| func TestRoomSpecificUsernameAtJoin(t *testing.T) { | ||
| alice, bob, eve, cleanup := setupUsers(t) | ||
| defer cleanup(t) | ||
|
|
||
| // Bob creates a new room and invites Alice. | ||
| privateRoom := bob.CreateRoom(t, map[string]interface{}{ | ||
| "visibility": "private", | ||
| "invite": []string{alice.UserID}, | ||
| }) | ||
|
|
||
| // Alice waits until she sees the invite, then accepts. | ||
| // When she accepts, she does so with a specific displayname. | ||
| alice.SyncUntilInvitedTo(t, privateRoom) | ||
| alice.JoinRoom(t, privateRoom, nil) | ||
|
|
||
| // Alice reveals her private name to Bob | ||
| alice.MustDoFunc( | ||
| t, | ||
| "PUT", | ||
| []string{"_matrix", "client", "r0", "rooms", privateRoom, "state", "m.room.member", alice.UserID}, | ||
| client.WithJSONBody(t, map[string]interface{}{ | ||
| "displayname": alicePrivateName, | ||
| "membership": "join", | ||
| }), | ||
| ) | ||
|
|
||
| checkExpectations(t, bob, eve) | ||
| } | ||
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.