Skip to content
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

Add test case reproducing matrix-org/synapse#5677 for local users #199

Merged
merged 26 commits into from
Nov 15, 2021
Merged
Changes from 2 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 Aug 23, 2021
05d148a
goimports
DMRobertson Aug 23, 2021
877f6a1
Mark MustDo as Deprecated
DMRobertson Aug 23, 2021
8209286
Introduce SyncUntilInvitedTo
DMRobertson Aug 24, 2021
07afbaa
client: Helper function SearchUserDirectory
DMRobertson Aug 24, 2021
75ef397
match: use rs.Exists() in JSONKeyEqual
DMRobertson Aug 24, 2021
68cf89a
match: matcher that seeks an array of a fixed size
DMRobertson Aug 24, 2021
ce8f3a9
Update tests after review
DMRobertson Aug 24, 2021
ed7d66e
Fix format string
DMRobertson Aug 24, 2021
5435622
Make lint accept use of deprecated things
DMRobertson Aug 24, 2021
6ce2fc4
Remove from synapse blacklist
DMRobertson Aug 24, 2021
26aad20
Introduce `AnyOf` matcher
DMRobertson Aug 25, 2021
9f4b9a0
Expand test cases to inspect Bob's behaviour too
DMRobertson Aug 25, 2021
a2e0d06
Tweak expected behaviour
DMRobertson Aug 26, 2021
b10655f
Enforce Displaynames in blueprints
DMRobertson Aug 31, 2021
b52c712
Fix typo
DMRobertson Sep 2, 2021
c95b011
Add case for remote user with per-room nickname
DMRobertson Sep 2, 2021
d650c5a
Ensure pub name, priv name & localpart all differ
DMRobertson Sep 2, 2021
815cf7b
Remove testing comment
DMRobertson Sep 2, 2021
4c95d45
Prefer MustDoFunc; test joining with private name
DMRobertson Sep 6, 2021
ef171f3
Fix PUT call to set displayname
DMRobertson Sep 6, 2021
707b530
Cleanup deployment after test, not after setup!
DMRobertson Sep 6, 2021
2b4609a
aliceId -> aliceUserID
DMRobertson Sep 7, 2021
700e300
Allow remote users' displaynames to be localparts
DMRobertson Sep 7, 2021
56bf3e3
Remove the tests which apply over federation
DMRobertson Nov 10, 2021
c0b3ecd
Blacklist tests for dendrite
DMRobertson Nov 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions tests/csapi/user_directory_display_names_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// +build !synapse_blacklist

// Rationale for being included in Synapse's blacklist: https://github.com/matrix-org/synapse/issues/5677
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably don't want this on Synapse's blacklist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that I wouldn't want synapse CI to suddenly light up red. But maybe your point is "it should do!"

package csapi_tests

import (
"testing"

"github.com/matrix-org/complement/internal/b"
"github.com/matrix-org/complement/internal/match"
"github.com/matrix-org/complement/internal/must"
)

func TestRoomSpecificUsernameNotLeaked(t *testing.T) {
// Reproduces https://github.com/matrix-org/synapse/issues/5677
// In that bug report, Alice has revealed a private name to a friend X,
// and Bob can see that private name when he shouldn't be able to.
// I've tweaked the names to be more traditional: Alice reveals a private name
// to Bob, and Eve shouldn't be able to see that name.
deployment := Deploy(t, b.BlueprintAlice)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")
bob := deployment.RegisterUser(t, "hs1", "bob", "bob-pw")
eve := deployment.RegisterUser(t, "hs1", "eve", "eve-pw")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These passwords will be too short for some servers, which is probably why it 400s on Dendrite.


t.Run("Usernames specific to a room aren't leaked in the user directory", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no real need to do this as a subtest, unless you plan to add more tests around username leaks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. Could add one for avatar leaks too perhaps.

// Bob creates a new room and invites Alice. She accepts.
privateRoom := bob.CreateRoom(t, map[string]interface{}{
"m.federate": false,
})
bob.InviteRoom(t, privateRoom, "@alice:hs1")
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
alice.JoinRoom(t, privateRoom, nil)
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved

// Alice reveals her private name to Bob
alice.MustDo(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer MustDoFunc. MustDo is the older format which doesn't allow for vargs and will be removed in the future. MustDoFunc also logs HTTP response bodies on error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, thanks. Mind if I mark MustDo as deprecated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup!

t,
"PUT",
[]string{"_matrix", "client", "r0", "rooms", privateRoom, "state", "m.room.member",
"@alice:hs1"},
map[string]interface{}{
"displayname": "Alice Cooper",
"membership": "join",
},
)

// Eve looks up alice in the directory using her public name
res := eve.MustDo(
t,
"POST",
[]string{"_matrix", "client", "r0", "user_directory", "search"},
map[string]interface{}{
"search_term": "alice",
},
)

must.MatchResponse(t, res, match.HTTPResponse{
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
JSON: []match.JSON{
match.JSONKeyEqual("results.0.display_name", "alice"),
match.JSONKeyEqual("results.0.user_id", "@alice:hs1"),
},
})
})
}