| 
 | 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