-
Notifications
You must be signed in to change notification settings - Fork 62
Add TestRestrictedRoomsLocalJoinNoCreatorsUsesPowerLevels
#836
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -446,3 +446,77 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j | |
| return true | ||
| })) | ||
| } | ||
|
|
||
| // A server will attempt to perform a local join to a room with creators (v12), | ||
| // using a creator as the authorising user, but falling back to power levels if | ||
| // an appropriate creator cannot be found. | ||
| // | ||
| // ref: https://github.com/element-hq/synapse/issues/19120 | ||
| func TestRestrictedRoomsLocalJoinNoCreatorsUsesPowerLevels(t *testing.T) { | ||
|
Collaborator
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. Thanks for taking the time to write a test! It looks great overall 🤩
Collaborator
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've tested to make sure it fails with the latest |
||
| doTestRestrictedRoomsLocalJoinNoCreatorsUsesPowerLevels(t, "12", "restricted") | ||
|
Collaborator
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. We should also test with a room version before 12 |
||
| } | ||
|
|
||
| func doTestRestrictedRoomsLocalJoinNoCreatorsUsesPowerLevels(t *testing.T, roomVersion string, joinRule string) { | ||
|
Collaborator
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. It looks like the reason other tests are written this way is so that it can be shared with |
||
| deployment := complement.Deploy(t, 2) | ||
| defer deployment.Destroy(t) | ||
| // Create the room | ||
| alice, allowed_room, room := setupRestrictedRoom(t, deployment, roomVersion, joinRule) | ||
| // Create two users on the other homeserver. | ||
| bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) | ||
| charlie := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) | ||
|
|
||
| // Bob joins the allowed room. | ||
| bob.JoinRoom(t, allowed_room, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
| }) | ||
| // Bob joins the restricted room. This join should go remotely | ||
| // and consequently be authorised by Alice as she is the only | ||
| // member. | ||
| bob.JoinRoom(t, room, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
| }) | ||
| // Ensure the join was authorised by alice | ||
| bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, room, func(ev gjson.Result) bool { | ||
| must.MatchGJSON(t, ev, | ||
| match.JSONKeyEqual("content.join_authorised_via_users_server", alice.UserID), | ||
| ) | ||
| return true | ||
| })) | ||
|
|
||
| // Alice restricts the invite power level to moderators and promotes Bob to | ||
| // moderator. | ||
| state_key := "" | ||
| alice.SendEventSynced(t, room, b.Event{ | ||
| Type: "m.room.power_levels", | ||
| StateKey: &state_key, | ||
| Content: map[string]interface{}{ | ||
| "invite": 50, | ||
| "users": map[string]interface{}{ | ||
| bob.UserID: 50, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| // Charlie joins the allowed room. | ||
| charlie.JoinRoom(t, allowed_room, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
| }) | ||
| // Charlie attempts to join the restricted room. | ||
| // hs2 should attempt to find a creator to authorise the room join, | ||
| // but can't as the only creator is remote. It should then fall back | ||
| // to checking the power levels for a user that can authorise the join. | ||
| // The end result should be that charlie is allowed to join. | ||
|
Comment on lines
+504
to
+508
Collaborator
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. Probably needs a slight adjustment like the main test description comment above. |
||
| charlie.JoinRoom(t, room, []spec.ServerName{ | ||
| deployment.GetFullyQualifiedHomeserverName(t, "hs2"), | ||
| }) | ||
|
|
||
| // Ensure the join was authorised by bob. The join should not be | ||
| // authorised by alice as hs2 should not have attempted a remote | ||
| // join given bob is a local user that can authorise the join. | ||
| bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, room, func(ev gjson.Result) bool { | ||
| must.MatchGJSON(t, ev, | ||
| match.JSONKeyEqual("content.join_authorised_via_users_server", bob.UserID), | ||
| ) | ||
| return true | ||
| })) | ||
|
Comment on lines
+513
to
+521
Collaborator
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. Great comment/assertion 👍 |
||
| } | ||
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 this is explaining too many specifics of the Synapse implementation. Unless this is explained somewhere in the spec?
Here is an iteration: