Skip to content

Commit d762275

Browse files
add 30rooms/15kick (#505)
1 parent 9a11120 commit d762275

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/csapi/room_kick_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package csapi_tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/matrix-org/complement/internal/b"
7+
"github.com/matrix-org/complement/internal/client"
8+
"github.com/matrix-org/complement/internal/match"
9+
"github.com/matrix-org/complement/internal/must"
10+
)
11+
12+
// sytest: Users cannot kick users from a room they are not in
13+
func TestCannotKickNonPresentUser(t *testing.T) {
14+
deployment := Deploy(t, b.BlueprintOneToOneRoom)
15+
defer deployment.Destroy(t)
16+
17+
alice := deployment.Client(t, "hs1", "@alice:hs1")
18+
bob := deployment.Client(t, "hs1", "@bob:hs1")
19+
20+
roomID := alice.CreateRoom(t, map[string]interface{}{
21+
"preset": "public_chat",
22+
})
23+
24+
resp := alice.DoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "kick"},
25+
client.WithJSONBody(t, map[string]interface{}{
26+
"user_id": bob.UserID,
27+
"reason": "testing",
28+
}),
29+
)
30+
31+
must.MatchResponse(t, resp, match.HTTPResponse{
32+
StatusCode: 403,
33+
})
34+
}
35+
36+
// sytest: Users cannot kick users who have already left a room
37+
func TestCannotKickLeftUser(t *testing.T) {
38+
deployment := Deploy(t, b.BlueprintOneToOneRoom)
39+
defer deployment.Destroy(t)
40+
41+
alice := deployment.Client(t, "hs1", "@alice:hs1")
42+
bob := deployment.Client(t, "hs1", "@bob:hs1")
43+
44+
roomID := alice.CreateRoom(t, map[string]interface{}{
45+
"preset": "public_chat",
46+
})
47+
48+
bob.JoinRoom(t, roomID, nil)
49+
50+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
51+
52+
bob.LeaveRoom(t, roomID)
53+
54+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID))
55+
56+
resp := alice.DoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "kick"},
57+
client.WithJSONBody(t, map[string]interface{}{
58+
"user_id": bob.UserID,
59+
"reason": "testing",
60+
}),
61+
)
62+
63+
must.MatchResponse(t, resp, match.HTTPResponse{
64+
StatusCode: 403,
65+
})
66+
}

0 commit comments

Comments
 (0)