From c7f7ae69ebd37a4bdb3fdc7c5d0d949445c837dc Mon Sep 17 00:00:00 2001 From: Kegsay Date: Wed, 17 Jun 2020 15:12:09 +0100 Subject: [PATCH 1/5] Are we synapse yet: Accept tests without a group rather than dying (#1142) Produces output like: ``` Non-Spec APIs: 0% (0/52 tests) -------------- Non-Spec API : 0% (0/50 tests) Unknown API (no group specified): 0% (0/2 tests) ``` Co-authored-by: Neil Alexander --- are-we-synapse-yet.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/are-we-synapse-yet.py b/are-we-synapse-yet.py index 5d512847..30979a12 100755 --- a/are-we-synapse-yet.py +++ b/are-we-synapse-yet.py @@ -33,6 +33,7 @@ import sys test_mappings = { "nsp": "Non-Spec API", + "unk": "Unknown API (no group specified)", "f": "Federation", # flag to mark test involves federation "federation_apis": { @@ -214,7 +215,8 @@ def main(results_tap_path, verbose): # } }, "nonspec": { - "nsp": {} + "nsp": {}, + "unk": {} }, } with open(results_tap_path, "r") as f: @@ -225,7 +227,7 @@ def main(results_tap_path, verbose): name = test_result["name"] group_id = test_name_to_group_id.get(name) if not group_id: - raise Exception("The test '%s' doesn't have a group" % (name,)) + summary["nonspec"]["unk"][name] = test_result["ok"] if group_id == "nsp": summary["nonspec"]["nsp"][name] = test_result["ok"] elif group_id in test_mappings["federation_apis"]: From 8e7c1eda05dddec5842711ce3d80036e7eff70d7 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Wed, 17 Jun 2020 15:40:37 +0100 Subject: [PATCH 2/5] Enable more sytests (#1145) --- go.mod | 2 +- go.sum | 2 ++ sytest-whitelist | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 6154d0f3..ff73ad07 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4 github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 - github.com/matrix-org/gomatrixserverlib v0.0.0-20200616150727-7ac22b6f8e65 + github.com/matrix-org/gomatrixserverlib v0.0.0-20200617141855-5539854e4abc github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 github.com/mattn/go-sqlite3 v2.0.2+incompatible diff --git a/go.sum b/go.sum index 3fa242c7..f62b14b6 100644 --- a/go.sum +++ b/go.sum @@ -373,6 +373,8 @@ github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bh github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0= github.com/matrix-org/gomatrixserverlib v0.0.0-20200616150727-7ac22b6f8e65 h1:2CcCcBnWdDPDOqFKiGOM+mi/KDDZXSTKmvFy/0/+ZJI= github.com/matrix-org/gomatrixserverlib v0.0.0-20200616150727-7ac22b6f8e65/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200617141855-5539854e4abc h1:Oxidxr/H1Nh8aOFWAhTzQYLDOc9OuoJwfDjgEHpyqNE= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200617141855-5539854e4abc/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU= github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f h1:pRz4VTiRCO4zPlEMc3ESdUOcW4PXHH4Kj+YDz1XyE+Y= github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f/go.mod h1:y0oDTjZDv5SM9a2rp3bl+CU+bvTRINQsdb7YlDql5Go= github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 h1:ntrLa/8xVzeSs8vHFHK25k0C+NV74sYMJnNSg5NoSRo= diff --git a/sytest-whitelist b/sytest-whitelist index e6860562..3fb96ff4 100644 --- a/sytest-whitelist +++ b/sytest-whitelist @@ -334,3 +334,5 @@ Can download specifying a different ASCII file name Can download with Unicode file name over federation Can download specifying a different Unicode file name Inbound /v1/send_join rejects joins from other servers +Outbound federation can query v1 /send_join +Inbound /v1/send_join rejects incorrectly-signed joins From 8efeb8eb3b347f1afc16b7fe2e2efe4edd593027 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Wed, 17 Jun 2020 16:21:42 +0100 Subject: [PATCH 3/5] Return the correct /joined_members response and allow ?format=event (#1146) --- clientapi/routing/memberships.go | 27 +++++++++++++++++++++++++++ clientapi/routing/routing.go | 6 ++++-- clientapi/routing/state.go | 12 ++++++++++-- sytest-whitelist | 2 ++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/clientapi/routing/memberships.go b/clientapi/routing/memberships.go index 574a2c48..1c9800b6 100644 --- a/clientapi/routing/memberships.go +++ b/clientapi/routing/memberships.go @@ -15,6 +15,7 @@ package routing import ( + "encoding/json" "net/http" "github.com/matrix-org/dendrite/userapi/storage/accounts" @@ -35,6 +36,16 @@ type getJoinedRoomsResponse struct { JoinedRooms []string `json:"joined_rooms"` } +// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-joined-members +type getJoinedMembersResponse struct { + Joined map[string]joinedMember `json:"joined"` +} + +type joinedMember struct { + DisplayName string `json:"display_name"` + AvatarURL string `json:"avatar_url"` +} + // GetMemberships implements GET /rooms/{roomId}/members func GetMemberships( req *http.Request, device *userapi.Device, roomID string, joinedOnly bool, @@ -59,6 +70,22 @@ func GetMemberships( } } + if joinedOnly { + var res getJoinedMembersResponse + res.Joined = make(map[string]joinedMember) + for _, ev := range queryRes.JoinEvents { + var content joinedMember + if err := json.Unmarshal(ev.Content, &content); err != nil { + util.GetLogger(req.Context()).WithError(err).Error("failed to unmarshal event content") + return jsonerror.InternalServerError() + } + res.Joined[ev.Sender] = content + } + return util.JSONResponse{ + Code: http.StatusOK, + JSON: res, + } + } return util.JSONResponse{ Code: http.StatusOK, JSON: getMembershipResponse{queryRes.JoinEvents}, diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 0fe687b3..41c7fb18 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -164,7 +164,8 @@ func Setup( if err != nil { return util.ErrorResponse(err) } - return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], "") + eventFormat := req.URL.Query().Get("format") == "event" + return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], "", eventFormat) })).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse { @@ -172,7 +173,8 @@ func Setup( if err != nil { return util.ErrorResponse(err) } - return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], vars["stateKey"]) + eventFormat := req.URL.Query().Get("format") == "event" + return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], vars["stateKey"], eventFormat) })).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}", diff --git a/clientapi/routing/state.go b/clientapi/routing/state.go index e3e5bdb6..2ec7a33f 100644 --- a/clientapi/routing/state.go +++ b/clientapi/routing/state.go @@ -98,7 +98,8 @@ func OnIncomingStateRequest(ctx context.Context, rsAPI api.RoomserverInternalAPI // /rooms/{roomID}/state/{type}/{statekey} request. It will look in current // state to see if there is an event with that type and state key, if there // is then (by default) we return the content, otherwise a 404. -func OnIncomingStateTypeRequest(ctx context.Context, rsAPI api.RoomserverInternalAPI, roomID string, evType, stateKey string) util.JSONResponse { +// If eventFormat=true, sends the whole event else just the content. +func OnIncomingStateTypeRequest(ctx context.Context, rsAPI api.RoomserverInternalAPI, roomID, evType, stateKey string, eventFormat bool) util.JSONResponse { // TODO(#287): Auth request and handle the case where the user has left (where // we should return the state at the poin they left) util.GetLogger(ctx).WithFields(log.Fields{ @@ -134,8 +135,15 @@ func OnIncomingStateTypeRequest(ctx context.Context, rsAPI api.RoomserverInterna ClientEvent: gomatrixserverlib.HeaderedToClientEvent(stateRes.StateEvents[0], gomatrixserverlib.FormatAll), } + var res interface{} + if eventFormat { + res = stateEvent + } else { + res = stateEvent.Content + } + return util.JSONResponse{ Code: http.StatusOK, - JSON: stateEvent.Content, + JSON: res, } } diff --git a/sytest-whitelist b/sytest-whitelist index 3fb96ff4..a6427cac 100644 --- a/sytest-whitelist +++ b/sytest-whitelist @@ -53,6 +53,8 @@ PUT /rooms/:room_id/send/:event_type/:txn_id deduplicates the same txn id GET /rooms/:room_id/state/m.room.power_levels can fetch levels PUT /rooms/:room_id/state/m.room.power_levels can set levels PUT power_levels should not explode if the old power levels were empty +GET /rooms/:room_id/state/m.room.member/:user_id?format=event fetches my membership event +GET /rooms/:room_id/joined_members fetches my membership Both GET and PUT work POST /rooms/:room_id/read_markers can create read marker User signups are forbidden from starting with '_' From 9b408c19fbe3ca3908f9dcf44978d038fe0d230f Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 17 Jun 2020 16:47:21 +0100 Subject: [PATCH 4/5] Missing sytests --- sytest-whitelist | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sytest-whitelist b/sytest-whitelist index a6427cac..be45b434 100644 --- a/sytest-whitelist +++ b/sytest-whitelist @@ -338,3 +338,10 @@ Can download specifying a different Unicode file name Inbound /v1/send_join rejects joins from other servers Outbound federation can query v1 /send_join Inbound /v1/send_join rejects incorrectly-signed joins +POST /rooms/:room_id/state/m.room.name sets name +GET /rooms/:room_id/state/m.room.name gets name +POST /rooms/:room_id/state/m.room.topic sets topic +GET /rooms/:room_id/state/m.room.topic gets topic +GET /rooms/:room_id/state fetches entire room state +Setting room topic reports m.room.topic to myself +setting 'm.room.name' respects room powerlevel From 84a7881468a57bd4225f5c990c03b5fce729f914 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Wed, 17 Jun 2020 17:01:03 +0100 Subject: [PATCH 5/5] Make account data sytests pass (#1147) --- clientapi/routing/account_data.go | 2 +- sytest-whitelist | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clientapi/routing/account_data.go b/clientapi/routing/account_data.go index 875249b3..68e0dc5d 100644 --- a/clientapi/routing/account_data.go +++ b/clientapi/routing/account_data.go @@ -51,7 +51,7 @@ func GetAccountData( ); err == nil { return util.JSONResponse{ Code: http.StatusOK, - JSON: data, + JSON: data.Content, } } diff --git a/sytest-whitelist b/sytest-whitelist index be45b434..971f8cf0 100644 --- a/sytest-whitelist +++ b/sytest-whitelist @@ -115,6 +115,8 @@ User can invite local user to room with version 1 Should reject keys claiming to belong to a different user Can add account data Can add account data to room +Can get account data without syncing +Can get room account data without syncing #Latest account data appears in v2 /sync New account data appears in incremental v2 /sync Checking local federation server