From 517076cf7e20a1752e0367ef56738927e95d4dfb Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Fri, 25 Mar 2022 14:53:31 +0100 Subject: [PATCH 1/8] Add powerlevel tests --- tests/csapi/apidoc_room_levels_test.go | 104 +++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/csapi/apidoc_room_levels_test.go diff --git a/tests/csapi/apidoc_room_levels_test.go b/tests/csapi/apidoc_room_levels_test.go new file mode 100644 index 00000000..4097a38c --- /dev/null +++ b/tests/csapi/apidoc_room_levels_test.go @@ -0,0 +1,104 @@ +package csapi_tests + +import ( + "net/http" + "testing" + + "github.com/matrix-org/complement/internal/b" + "github.com/matrix-org/complement/internal/client" + "github.com/matrix-org/complement/internal/match" + "github.com/matrix-org/complement/internal/must" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +func TestRoomLevels(t *testing.T) { + deployment := Deploy(t, b.BlueprintAlice) + defer deployment.Destroy(t) + alice := deployment.Client(t, "hs1", "@alice:hs1") + + successCount := 0 + defer func() { + // sytest: Both GET and PUT work + if successCount != 2 { + t.Fatalf("expected GET and PUT to work") + } + }() + t.Run("Parallel", func(t *testing.T) { + // sytest: GET /rooms/:room_id/state/m.room.power_levels can fetch levels + t.Run("GET /rooms/:room_id/state/m.room.power_levels can fetch levels", func(t *testing.T) { + t.Parallel() + roomID := alice.CreateRoom(t, map[string]interface{}{}) + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) + res := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}) + + body := gjson.ParseBytes(must.ParseJSON(t, res.Body)) + requiredFields := []string{"ban", "kick", "redact", "state_default", "events_default", "events", "users"} + for i := range requiredFields { + if !body.Get(requiredFields[i]).Exists() { + t.Fatalf("expected json field %s, but it does not exist", requiredFields[i]) + } + } + users := body.Get("users").Map() + alicePowerLevel, ok := users[alice.UserID] + if !ok { + t.Fatalf("Expected room creator (%s) to exist in user powerlevel list", alice.UserID) + } + + userDefaults := body.Get("user_defaults").Int() + + if userDefaults > alicePowerLevel.Int() { + t.Fatalf("Expected room creator to have a higher-than-default powerlevel") + } + successCount++ + }) + // sytest: PUT /rooms/:room_id/state/m.room.power_levels can set levels + t.Run("PUT /rooms/:room_id/state/m.room.power_levels can set levels", func(t *testing.T) { + t.Parallel() + roomID := alice.CreateRoom(t, map[string]interface{}{}) + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) + res := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}) + + powerLevels := gjson.ParseBytes(must.ParseJSON(t, res.Body)) + changedUser := client.GjsonEscape("@random-other-user:their.home") + alicePowerLevel := powerLevels.Get("users." + alice.UserID).Int() + pl := map[string]int64{ + alice.UserID: alicePowerLevel, + "@random-other-user:their.home": 20, + } + newPowerlevels, err := sjson.Set(powerLevels.Str, "users", pl) + if err != nil { + t.Fatalf("unable to update powerlevel JSON") + } + reqBody := client.WithRawBody([]byte(newPowerlevels)) + alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}, reqBody) + res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}) + powerLevels = gjson.ParseBytes(must.ParseJSON(t, res.Body)) + if powerLevels.Get("users."+changedUser).Int() != 20 { + t.Fatal("Expected to have set other user's level to 20") + } + successCount++ + }) + // sytest: PUT power_levels should not explode if the old power levels were empty + t.Run("PUT power_levels should not explode if the old power levels were empty", func(t *testing.T) { + t.Parallel() + roomID := alice.CreateRoom(t, map[string]interface{}{}) + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) + + reqBody := client.WithJSONBody(t, map[string]interface{}{ + "users": map[string]int64{ + alice.UserID: 100, + }, + }) + alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}, reqBody) + // absence of a 'users' key + reqBody = client.WithJSONBody(t, map[string]interface{}{}) + alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}, reqBody) + // this should now give a 403 (not a 500) + res := alice.DoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}, reqBody) + must.MatchResponse(t, res, match.HTTPResponse{ + StatusCode: http.StatusForbidden, + }) + }) + }) +} From e95787d0b8f7b67507a693ad97ab082c2a343564 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Fri, 25 Mar 2022 15:12:05 +0100 Subject: [PATCH 2/8] Add topic test --- sytest.ignored.list | 6 +++++- tests/csapi/rooms_state_test.go | 24 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/sytest.ignored.list b/sytest.ignored.list index 792431b4..664df0cb 100644 --- a/sytest.ignored.list +++ b/sytest.ignored.list @@ -38,4 +38,8 @@ Newly created users see their own presence in /initialSync (SYT-34) Push rules come down in an initial /sync Guest user calling /events doesn't tightloop Guest user cannot call /events globally -!53groups \ No newline at end of file +!53groups +Global initialSync +Global initialSync with limit=0 gives no messages +Room initialSync +Room initialSync with limit=0 gives no messages \ No newline at end of file diff --git a/tests/csapi/rooms_state_test.go b/tests/csapi/rooms_state_test.go index 06a0bf4a..4c664352 100644 --- a/tests/csapi/rooms_state_test.go +++ b/tests/csapi/rooms_state_test.go @@ -27,12 +27,11 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { userID := "@alice:hs1" alice := deployment.Client(t, "hs1", userID) roomID := alice.CreateRoom(t, struct{}{}) - + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(userID, roomID)) t.Run("parallel", func(t *testing.T) { // sytest: Room creation reports m.room.create to myself t.Run("Room creation reports m.room.create to myself", func(t *testing.T) { t.Parallel() - alice := deployment.Client(t, "hs1", userID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(ev gjson.Result) bool { if ev.Get("type").Str != "m.room.create" { return false @@ -45,7 +44,6 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { // sytest: Room creation reports m.room.member to myself t.Run("Room creation reports m.room.member to myself", func(t *testing.T) { t.Parallel() - alice := deployment.Client(t, "hs1", userID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(ev gjson.Result) bool { if ev.Get("type").Str != "m.room.member" { return false @@ -56,5 +54,25 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { return true })) }) + // sytest: Setting room topic reports m.room.topic to myself + t.Run("Setting room topic reports m.room.topic to myself", func(t *testing.T) { + t.Parallel() + topic := "Testing topic for the new room" + reqBody := client.WithJSONBody(t, map[string]string{ + "topic": topic, + }) + alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.topic"}, reqBody) + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(ev gjson.Result) bool { + if ev.Get("type").Str != "m.room.topic" { + return false + } + if !ev.Get("sender").Exists() || !ev.Get("content").Exists() { + return false + } + must.EqualStr(t, ev.Get("sender").Str, userID, "wrong sender") + must.EqualStr(t, ev.Get("content.topic").Str, topic, "wrong topic") + return true + })) + }) }) } From bced71998f2217686217687e44f4d3f5f939c20c Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Fri, 25 Mar 2022 20:05:01 +0100 Subject: [PATCH 3/8] Add room version tests --- tests/csapi/room_versions_test.go | 192 ++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 tests/csapi/room_versions_test.go diff --git a/tests/csapi/room_versions_test.go b/tests/csapi/room_versions_test.go new file mode 100644 index 00000000..f4a8a9d4 --- /dev/null +++ b/tests/csapi/room_versions_test.go @@ -0,0 +1,192 @@ +package csapi_tests + +import ( + "fmt" + "net/url" + "testing" + + "github.com/matrix-org/complement/internal/b" + "github.com/matrix-org/complement/internal/client" + "github.com/matrix-org/complement/internal/must" + "github.com/matrix-org/gomatrixserverlib" + "github.com/tidwall/gjson" +) + +func TestRoomVersions(t *testing.T) { + deployment := Deploy(t, b.BlueprintFederationTwoLocalOneRemote) + defer deployment.Destroy(t) + + alice := deployment.Client(t, "hs1", "@alice:hs1") + bob := deployment.Client(t, "hs1", "@bob:hs1") + charlie := deployment.Client(t, "hs2", "@charlie:hs2") + + roomVersions := gomatrixserverlib.RoomVersions() + + t.Run("Parallel", func(t *testing.T) { + // iterate over all room versions + for v := range roomVersions { + roomVersion := v + // sytest: User can create and send/receive messages in a room with version $version + t.Run(fmt.Sprintf("User can create and send/receive messages in a room with version %s", roomVersion), func(t *testing.T) { + t.Parallel() + roomID := createRoomSynced(t, alice, map[string]interface{}{ + "room_version": roomVersion, + }) + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) + + res, _ := alice.MustSync(t, client.SyncReq{}) + room := res.Get("rooms.join." + client.GjsonEscape(roomID)) + ev0 := room.Get("timeline.events").Array()[0] + must.EqualStr(t, ev0.Get("type").Str, "m.room.create", "not a m.room.create event") + sendMessageSynced(t, alice, roomID) + }) + + userTypes := map[string]*client.CSAPI{ + "local": bob, + "remote": charlie, + } + for typ, joiner := range userTypes { + typ := typ + joiner := joiner + + // sytest: $user_type user can join room with version $version + t.Run(fmt.Sprintf("%s user can join room with version %s", typ, roomVersion), func(t *testing.T) { + t.Parallel() + roomAlias := fmt.Sprintf("roomAlias_V%s%s", typ, roomVersion) + t.Logf("RoomAlias: %s", roomAlias) + roomID := createRoomSynced(t, alice, map[string]interface{}{ + "room_version": roomVersion, + "room_alias_name": roomAlias, + "preset": "public_chat", + }) + joinRoomSynced(t, joiner, roomID, fmt.Sprintf("#%s:%s", roomAlias, "hs1")) + _, nextBatch := joiner.MustSync(t, client.SyncReq{}) + eventID := sendMessageSynced(t, alice, roomID) + joiner.MustSyncUntil(t, client.SyncReq{Since: nextBatch}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool { + if len(result.Array()) > 1 { + t.Fatal("Expected a single timeline event") + } + must.EqualStr(t, result.Array()[0].Get("event_id").Str, eventID, "wrong event id") + return true + })) + }) + + // sytest: User can invite $user_type user to room with version $version + t.Run(fmt.Sprintf("User can invite %s user to room with version %s", typ, roomVersion), func(t *testing.T) { + t.Parallel() + roomID := createRoomSynced(t, alice, map[string]interface{}{ + "room_version": roomVersion, + "preset": "private_chat", + }) + alice.InviteRoom(t, roomID, joiner.UserID) + joiner.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(joiner.UserID, roomID)) + joinRoomSynced(t, joiner, roomID, "") + _, nextBatch := joiner.MustSync(t, client.SyncReq{}) + eventID := sendMessageSynced(t, alice, roomID) + joiner.MustSyncUntil(t, client.SyncReq{Since: nextBatch}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool { + if len(result.Array()) > 1 { + t.Fatal("Expected a single timeline event") + } + must.EqualStr(t, result.Array()[0].Get("event_id").Str, eventID, "wrong event id") + return true + })) + }) + + } + + // sytest: Remote user can backfill in a room with version $version + t.Run(fmt.Sprintf("Remote user can backfill in a room with version %s", roomVersion), func(t *testing.T) { + t.Parallel() + roomID := createRoomSynced(t, alice, map[string]interface{}{ + "room_version": roomVersion, + "invite": []string{charlie.UserID}, + }) + for i := 0; i < 20; i++ { + sendMessageSynced(t, alice, roomID) + } + charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(charlie.UserID, roomID)) + joinRoomSynced(t, charlie, roomID, "") + + queryParams := url.Values{} + queryParams.Set("dir", "b") + queryParams.Set("limit", "6") + res := charlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams)) + body := gjson.ParseBytes(must.ParseJSON(t, res.Body)) + defer res.Body.Close() + if len(body.Get("chunk").Array()) != 6 { + t.Fatal("Expected 6 messages") + } + }) + + // sytest: Can reject invites over federation for rooms with version $version + t.Run(fmt.Sprintf("Can reject invites over federation for rooms with version %s", roomVersion), func(t *testing.T) { + t.Parallel() + roomID := createRoomSynced(t, alice, map[string]interface{}{ + "room_version": roomVersion, + "invite": []string{charlie.UserID}, + }) + charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(charlie.UserID, roomID)) + charlie.LeaveRoom(t, roomID) + }) + + // sytest: Can receive redactions from regular users over federation in room version $version + t.Run(fmt.Sprintf("Can receive redactions from regular users over federation in room version %s", roomVersion), func(t *testing.T) { + t.Parallel() + roomID := createRoomSynced(t, alice, map[string]interface{}{ + "room_version": roomVersion, + "invite": []string{charlie.UserID}, + }) + charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(charlie.UserID, roomID)) + joinRoomSynced(t, charlie, roomID, "") + eventID := sendMessageSynced(t, charlie, roomID) + // redact the message + res := charlie.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "redact", eventID}, client.WithRawBody([]byte("{}"))) + js := must.ParseJSON(t, res.Body) + defer res.Body.Close() + redactID := must.GetJSONFieldStr(t, js, "event_id") + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool { + return redactID == result.Get("event_id").Str + })) + // query messages + queryParams := url.Values{} + queryParams.Set("dir", "b") + res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithQueries(queryParams)) + body := gjson.ParseBytes(must.ParseJSON(t, res.Body)) + defer res.Body.Close() + events := body.Get("chunk").Array() + // first event should be the redaction + must.EqualStr(t, events[0].Get("event_id").Str, redactID, "wrong event") + must.EqualStr(t, events[0].Get("redacts").Str, eventID, "wrong event") + // second event should be the original event + must.EqualStr(t, events[1].Get("event_id").Str, eventID, "wrong event") + must.EqualStr(t, events[1].Get("unsigned.redacted_by").Str, redactID, "wrong event") + }) + } + }) +} + +func sendMessageSynced(t *testing.T, cl *client.CSAPI, roomID string) (eventID string) { + return cl.SendEventSynced(t, roomID, b.Event{ + Type: "m.room.message", + Content: map[string]interface{}{ + "msgtype": "m.text", + "body": "hello world", + }, + }) +} + +func joinRoomSynced(t *testing.T, cl *client.CSAPI, roomID, alias string) { + joinRoom := roomID + if alias != "" { + joinRoom = alias + } + cl.JoinRoom(t, joinRoom, []string{}) + cl.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(cl.UserID, roomID)) +} + +func createRoomSynced(t *testing.T, c *client.CSAPI, content map[string]interface{}) (roomID string) { + t.Helper() + roomID = c.CreateRoom(t, content) + c.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(c.UserID, roomID)) + return +} From abd890ef0cd1807fd982905e251f991002563882 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 29 Mar 2022 08:28:25 +0200 Subject: [PATCH 4/8] Linter.. --- tests/csapi/apidoc_room_levels_test.go | 5 +++-- tests/csapi/room_versions_test.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/csapi/apidoc_room_levels_test.go b/tests/csapi/apidoc_room_levels_test.go index 4097a38c..6f9b3256 100644 --- a/tests/csapi/apidoc_room_levels_test.go +++ b/tests/csapi/apidoc_room_levels_test.go @@ -4,12 +4,13 @@ import ( "net/http" "testing" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" + "github.com/matrix-org/complement/internal/b" "github.com/matrix-org/complement/internal/client" "github.com/matrix-org/complement/internal/match" "github.com/matrix-org/complement/internal/must" - "github.com/tidwall/gjson" - "github.com/tidwall/sjson" ) func TestRoomLevels(t *testing.T) { diff --git a/tests/csapi/room_versions_test.go b/tests/csapi/room_versions_test.go index f4a8a9d4..5b7e0514 100644 --- a/tests/csapi/room_versions_test.go +++ b/tests/csapi/room_versions_test.go @@ -5,11 +5,12 @@ import ( "net/url" "testing" + "github.com/matrix-org/gomatrixserverlib" + "github.com/tidwall/gjson" + "github.com/matrix-org/complement/internal/b" "github.com/matrix-org/complement/internal/client" "github.com/matrix-org/complement/internal/must" - "github.com/matrix-org/gomatrixserverlib" - "github.com/tidwall/gjson" ) func TestRoomVersions(t *testing.T) { From 6e6b895cf84da4f234e3cab6a15b221f60ce59ab Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Mon, 11 Apr 2022 09:09:23 +0200 Subject: [PATCH 5/8] Fix test; PR comment changes --- tests/csapi/apidoc_room_levels_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/csapi/apidoc_room_levels_test.go b/tests/csapi/apidoc_room_levels_test.go index 6f9b3256..9576a6a3 100644 --- a/tests/csapi/apidoc_room_levels_test.go +++ b/tests/csapi/apidoc_room_levels_test.go @@ -18,13 +18,7 @@ func TestRoomLevels(t *testing.T) { defer deployment.Destroy(t) alice := deployment.Client(t, "hs1", "@alice:hs1") - successCount := 0 - defer func() { - // sytest: Both GET and PUT work - if successCount != 2 { - t.Fatalf("expected GET and PUT to work") - } - }() + // sytest: Both GET and PUT work t.Run("Parallel", func(t *testing.T) { // sytest: GET /rooms/:room_id/state/m.room.power_levels can fetch levels t.Run("GET /rooms/:room_id/state/m.room.power_levels can fetch levels", func(t *testing.T) { @@ -51,7 +45,6 @@ func TestRoomLevels(t *testing.T) { if userDefaults > alicePowerLevel.Int() { t.Fatalf("Expected room creator to have a higher-than-default powerlevel") } - successCount++ }) // sytest: PUT /rooms/:room_id/state/m.room.power_levels can set levels t.Run("PUT /rooms/:room_id/state/m.room.power_levels can set levels", func(t *testing.T) { @@ -62,7 +55,7 @@ func TestRoomLevels(t *testing.T) { powerLevels := gjson.ParseBytes(must.ParseJSON(t, res.Body)) changedUser := client.GjsonEscape("@random-other-user:their.home") - alicePowerLevel := powerLevels.Get("users." + alice.UserID).Int() + alicePowerLevel := powerLevels.Get("users." + client.GjsonEscape(alice.UserID)).Int() pl := map[string]int64{ alice.UserID: alicePowerLevel, "@random-other-user:their.home": 20, @@ -78,7 +71,6 @@ func TestRoomLevels(t *testing.T) { if powerLevels.Get("users."+changedUser).Int() != 20 { t.Fatal("Expected to have set other user's level to 20") } - successCount++ }) // sytest: PUT power_levels should not explode if the old power levels were empty t.Run("PUT power_levels should not explode if the old power levels were empty", func(t *testing.T) { @@ -86,6 +78,7 @@ func TestRoomLevels(t *testing.T) { roomID := alice.CreateRoom(t, map[string]interface{}{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) + // absence of an 'events' key reqBody := client.WithJSONBody(t, map[string]interface{}{ "users": map[string]int64{ alice.UserID: 100, @@ -96,6 +89,9 @@ func TestRoomLevels(t *testing.T) { reqBody = client.WithJSONBody(t, map[string]interface{}{}) alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}, reqBody) // this should now give a 403 (not a 500) + reqBody = client.WithJSONBody(t, map[string]interface{}{ + "users": struct{}{}, + }) res := alice.DoFunc(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.power_levels"}, reqBody) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: http.StatusForbidden, From 31a00b18fb11b7f5e0a8ae2c503cc0688d50d32c Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Mon, 11 Apr 2022 09:34:11 +0200 Subject: [PATCH 6/8] Only run tests on room versions the server knows about PR comments --- tests/csapi/room_versions_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/csapi/room_versions_test.go b/tests/csapi/room_versions_test.go index 5b7e0514..75315d19 100644 --- a/tests/csapi/room_versions_test.go +++ b/tests/csapi/room_versions_test.go @@ -23,17 +23,25 @@ func TestRoomVersions(t *testing.T) { roomVersions := gomatrixserverlib.RoomVersions() + // Query room versions the server supports + capabilities := alice.GetCapabilities(t) + availableRoomVersions := gjson.GetBytes(capabilities, `capabilities.m\.room_versions.available`).Map() + t.Logf("available room versions: %+v", availableRoomVersions) t.Run("Parallel", func(t *testing.T) { // iterate over all room versions for v := range roomVersions { roomVersion := v + // skip versions the server doesn't know about + if _, ok := availableRoomVersions[string(roomVersion)]; !ok { + t.Logf("Skipping room version %s", roomVersion) + continue + } // sytest: User can create and send/receive messages in a room with version $version t.Run(fmt.Sprintf("User can create and send/receive messages in a room with version %s", roomVersion), func(t *testing.T) { t.Parallel() roomID := createRoomSynced(t, alice, map[string]interface{}{ "room_version": roomVersion, }) - alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) res, _ := alice.MustSync(t, client.SyncReq{}) room := res.Get("rooms.join." + client.GjsonEscape(roomID)) @@ -47,6 +55,7 @@ func TestRoomVersions(t *testing.T) { "remote": charlie, } for typ, joiner := range userTypes { + // Ensure to use the correct value and not only the last one. typ := typ joiner := joiner @@ -128,6 +137,7 @@ func TestRoomVersions(t *testing.T) { }) charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(charlie.UserID, roomID)) charlie.LeaveRoom(t, roomID) + alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(charlie.UserID, roomID)) }) // sytest: Can receive redactions from regular users over federation in room version $version From f5fcf4aea236600b5fc6f24e6c294da7dbc8fa3f Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Mon, 11 Apr 2022 09:38:03 +0200 Subject: [PATCH 7/8] Update log message --- tests/csapi/room_versions_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/csapi/room_versions_test.go b/tests/csapi/room_versions_test.go index 75315d19..99bfbab5 100644 --- a/tests/csapi/room_versions_test.go +++ b/tests/csapi/room_versions_test.go @@ -26,14 +26,13 @@ func TestRoomVersions(t *testing.T) { // Query room versions the server supports capabilities := alice.GetCapabilities(t) availableRoomVersions := gjson.GetBytes(capabilities, `capabilities.m\.room_versions.available`).Map() - t.Logf("available room versions: %+v", availableRoomVersions) t.Run("Parallel", func(t *testing.T) { // iterate over all room versions for v := range roomVersions { roomVersion := v // skip versions the server doesn't know about if _, ok := availableRoomVersions[string(roomVersion)]; !ok { - t.Logf("Skipping room version %s", roomVersion) + t.Logf("Skipping unsupported room version %s", roomVersion) continue } // sytest: User can create and send/receive messages in a room with version $version From fd714b5bc04a3a4ece3e7147025154d85c634955 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Mon, 11 Apr 2022 10:24:37 +0200 Subject: [PATCH 8/8] Add ratelimits for invites and 3pid validation --- dockerfiles/synapse/homeserver.yaml | 12 ++++++++++++ dockerfiles/synapse/workers-shared.yaml | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/dockerfiles/synapse/homeserver.yaml b/dockerfiles/synapse/homeserver.yaml index 5eae8087..7b50755a 100644 --- a/dockerfiles/synapse/homeserver.yaml +++ b/dockerfiles/synapse/homeserver.yaml @@ -93,6 +93,18 @@ rc_joins: per_second: 9999 burst_count: 9999 +rc_3pid_validation: + per_second: 1000 + burst_count: 1000 + +rc_invites: + per_room: + per_second: 1000 + burst_count: 1000 + per_user: + per_second: 1000 + burst_count: 1000 + federation_rr_transactions_per_room_per_second: 9999 ## API Configuration ## diff --git a/dockerfiles/synapse/workers-shared.yaml b/dockerfiles/synapse/workers-shared.yaml index 24526881..8989b256 100644 --- a/dockerfiles/synapse/workers-shared.yaml +++ b/dockerfiles/synapse/workers-shared.yaml @@ -58,6 +58,18 @@ rc_joins: per_second: 9999 burst_count: 9999 +rc_3pid_validation: + per_second: 1000 + burst_count: 1000 + +rc_invites: + per_room: + per_second: 1000 + burst_count: 1000 + per_user: + per_second: 1000 + burst_count: 1000 + federation_rr_transactions_per_room_per_second: 9999 ## Experimental Features ##