|
| 1 | +package csapi_tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/tidwall/gjson" |
| 7 | + |
| 8 | + "github.com/matrix-org/complement/internal/b" |
| 9 | + "github.com/matrix-org/complement/internal/client" |
| 10 | + "github.com/matrix-org/complement/internal/match" |
| 11 | + "github.com/matrix-org/complement/internal/must" |
| 12 | +) |
| 13 | + |
| 14 | +// This is technically a tad different from the sytest, in that it doesnt try to ban a @random_dude:test, |
| 15 | +// but this will actually validate against a present user in the room. |
| 16 | +// sytest: Non-present room members cannot ban others |
| 17 | +func TestNotPresentUserCannotBanOthers(t *testing.T) { |
| 18 | + deployment := Deploy(t, b.MustValidate(b.Blueprint{ |
| 19 | + Name: "abc", |
| 20 | + Homeservers: []b.Homeserver{ |
| 21 | + { |
| 22 | + Name: "hs1", |
| 23 | + Users: []b.User{ |
| 24 | + { |
| 25 | + Localpart: "@alice", |
| 26 | + DisplayName: "Alice", |
| 27 | + }, |
| 28 | + { |
| 29 | + Localpart: "@bob", |
| 30 | + DisplayName: "Bob", |
| 31 | + }, |
| 32 | + { |
| 33 | + Localpart: "@charlie", |
| 34 | + DisplayName: "Charlie", |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + })) |
| 40 | + defer deployment.Destroy(t) |
| 41 | + |
| 42 | + alice := deployment.Client(t, "hs1", "@alice:hs1") |
| 43 | + bob := deployment.Client(t, "hs1", "@bob:hs1") |
| 44 | + charlie := deployment.Client(t, "hs1", "@charlie:hs1") |
| 45 | + |
| 46 | + roomID := alice.CreateRoom(t, map[string]interface{}{ |
| 47 | + "preset": "public_chat", |
| 48 | + }) |
| 49 | + |
| 50 | + bob.JoinRoom(t, roomID, nil) |
| 51 | + |
| 52 | + alice.SendEventSynced(t, roomID, b.Event{ |
| 53 | + Type: "m.room.power_levels", |
| 54 | + StateKey: b.Ptr(""), |
| 55 | + Content: map[string]interface{}{ |
| 56 | + "users": map[string]interface{}{ |
| 57 | + charlie.UserID: 100, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }) |
| 61 | + |
| 62 | + // todo: replace with `SyncUntilJoined` |
| 63 | + bob.SyncUntilTimelineHas(t, roomID, func(event gjson.Result) bool { |
| 64 | + return event.Get("type").Str == "m.room.member" && |
| 65 | + event.Get("content.membership").Str == "join" && |
| 66 | + event.Get("state_key").Str == bob.UserID |
| 67 | + }) |
| 68 | + |
| 69 | + res := charlie.DoFunc(t, "POST", []string{"_matrix", "client", "r0", "rooms", roomID, "ban"}, client.WithJSONBody(t, map[string]interface{}{ |
| 70 | + "user_id": bob.UserID, |
| 71 | + "reason": "testing", |
| 72 | + })) |
| 73 | + |
| 74 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 75 | + StatusCode: 403, |
| 76 | + }) |
| 77 | +} |
0 commit comments