-
Notifications
You must be signed in to change notification settings - Fork 52
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 MSC3083 - joining a restricted room. #98
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f06fb7b
Test MSC3083 - joining a restricted room.
clokep 158fd18
Expand tests to handle invites.
clokep d6a6652
Lint
clokep 51cc9b4
Add edge cases of bad data.
clokep e12cf88
Clarify comments.
clokep 3eaf139
Updates to match the behavior of bad data.
clokep 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 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,131 @@ | ||
// +build msc3083 | ||
|
||
// Tests MSC3083, an experimental feature for joining restricted rooms based on | ||
// membership in a space. | ||
|
||
package tests | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/matrix-org/complement/internal/b" | ||
"github.com/matrix-org/complement/internal/client" | ||
) | ||
|
||
var ( | ||
spaceChildEventType = "org.matrix.msc1772.space.child" | ||
spaceParentEventType = "org.matrix.msc1772.space.parent" | ||
) | ||
|
||
func FailJoinRoom(c *client.CSAPI, t *testing.T, roomIDOrAlias string, serverName string) { | ||
// This is copied from Client.JoinRoom to test a join failure. | ||
query := make(url.Values, 1) | ||
query.Set("server_name", serverName) | ||
c.MustDoWithStatusRaw( | ||
t, | ||
"POST", | ||
[]string{"_matrix", "client", "r0", "join", roomIDOrAlias}, | ||
nil, | ||
"application/json", | ||
query, | ||
403, | ||
) | ||
} | ||
|
||
// Test joining a room with join rules restricted to membership in a space. | ||
func TestRestrictedRoomsLocalJoin(t *testing.T) { | ||
deployment := Deploy(t, "msc3083", b.BlueprintOneToOneRoom) | ||
defer deployment.Destroy(t) | ||
|
||
// Create the space and put a room in it. | ||
alice := deployment.Client(t, "hs1", "@alice:hs1") | ||
space := alice.CreateRoom(t, map[string]interface{}{ | ||
"preset": "public_chat", | ||
"name": "Space", | ||
}) | ||
// The room is an unstable room version which supports the restricted join_rule. | ||
room := alice.CreateRoom(t, map[string]interface{}{ | ||
"preset": "public_chat", | ||
"name": "Room", | ||
"room_version": "org.matrix.msc3083", | ||
"initial_state": []map[string]interface{}{ | ||
{ | ||
"type": "m.room.join_rules", | ||
"state_key": "", | ||
"content": map[string]interface{}{ | ||
"join_rule": "restricted", | ||
"allow": []map[string]interface{}{ | ||
{ | ||
"space": &space, | ||
"via": []string{"hs1"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
alice.SendEventSynced(t, space, b.Event{ | ||
Type: spaceChildEventType, | ||
StateKey: &room, | ||
Content: map[string]interface{}{ | ||
"via": []string{"hs1"}, | ||
}, | ||
}) | ||
|
||
// Create a second user and attempt to join the room, it should fail. | ||
bob := deployment.Client(t, "hs1", "@bob:hs1") | ||
FailJoinRoom(bob, t, room, "hs1") | ||
|
||
// Join the space, attempt to join the room again, which now should succeed. | ||
bob.JoinRoom(t, space, []string{"hs1"}) | ||
bob.JoinRoom(t, room, []string{"hs1"}) | ||
|
||
// Leaving the room works and the user is unable to re-join. | ||
bob.LeaveRoom(t, room) | ||
bob.LeaveRoom(t, space) | ||
FailJoinRoom(bob, t, room, "hs1") | ||
|
||
// Invite the user and joining should work. | ||
alice.InviteRoom(t, room, "@bob:hs1") | ||
bob.JoinRoom(t, room, []string{"hs1"}) | ||
|
||
// Leave the room again, and join the space. | ||
bob.LeaveRoom(t, room) | ||
bob.JoinRoom(t, space, []string{"hs1"}) | ||
|
||
// Update the room to have bad values in the "allow" field, which should stop | ||
// joining from working properly. | ||
emptyStateKey := "" | ||
alice.SendEventSynced( | ||
t, | ||
room, | ||
b.Event{ | ||
Type: "m.room.join_rules", | ||
Sender: alice.UserID, | ||
StateKey: &emptyStateKey, | ||
Content: map[string]interface{}{ | ||
"join_rule": "restricted", | ||
"allow": []string{"invalid"}, | ||
}, | ||
}, | ||
) | ||
// Fails since invalid values get filtered out of allow. | ||
FailJoinRoom(bob, t, room, "hs1") | ||
|
||
alice.SendEventSynced( | ||
t, | ||
room, | ||
b.Event{ | ||
Type: "m.room.join_rules", | ||
Sender: alice.UserID, | ||
StateKey: &emptyStateKey, | ||
Content: map[string]interface{}{ | ||
"join_rule": "restricted", | ||
"allow": "invalid", | ||
}, | ||
}, | ||
) | ||
// Fails since a fully invalid allow key rquires an invite. | ||
FailJoinRoom(bob, t, room, "hs1") | ||
} |
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.
What happens if you leave the space first?
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.
Leaving the space first should be fine. The ordering of these two steps doesn't matter.