refactor: funnel event creation through room versions (#3060)

In preparation of interfacing up the room version value.
This commit is contained in:
kegsay 2023-04-20 19:07:31 +01:00 committed by GitHub
parent 72285b2659
commit 71eeccf34a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 41 additions and 35 deletions

View file

@ -321,7 +321,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
) )
for _, tc := range testCases { for _, tc := range testCases {
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(tc.eventJSON), false, tc.roomVer) ev, err := tc.roomVer.NewEventFromTrustedJSON([]byte(tc.eventJSON), false)
if err != nil { if err != nil {
t.Errorf("failed to parse event: %s", err) t.Errorf("failed to parse event: %s", err)
} }

View file

@ -235,7 +235,7 @@ func (r *FederationInternalAPI) performJoinUsingServer(
// contain signatures that we don't know about. // contain signatures that we don't know about.
if len(respSendJoin.Event) > 0 { if len(respSendJoin.Event) > 0 {
var remoteEvent *gomatrixserverlib.Event var remoteEvent *gomatrixserverlib.Event
remoteEvent, err = gomatrixserverlib.UntrustedEvent(respSendJoin.Event, respMakeJoin.RoomVersion) remoteEvent, err = respMakeJoin.RoomVersion.NewEventFromUntrustedJSON(respSendJoin.Event)
if err == nil && isWellFormedMembershipEvent( if err == nil && isWellFormedMembershipEvent(
remoteEvent, roomID, userID, remoteEvent, roomID, userID,
) { ) {
@ -660,7 +660,7 @@ func (r *FederationInternalAPI) PerformInvite(
return fmt.Errorf("r.federation.SendInviteV2: failed to send invite: %w", err) return fmt.Errorf("r.federation.SendInviteV2: failed to send invite: %w", err)
} }
inviteEvent, err := gomatrixserverlib.UntrustedEvent(inviteRes.Event, request.RoomVersion) inviteEvent, err := request.RoomVersion.NewEventFromUntrustedJSON(inviteRes.Event)
if err != nil { if err != nil {
return fmt.Errorf("r.federation.SendInviteV2 failed to decode event response: %w", err) return fmt.Errorf("r.federation.SendInviteV2 failed to decode event response: %w", err)
} }
@ -808,7 +808,7 @@ func federatedAuthProvider(
// event ID again. // event ID again.
for _, pdu := range tx.PDUs { for _, pdu := range tx.PDUs {
// Try to parse the event. // Try to parse the event.
ev, everr := gomatrixserverlib.NewEventFromUntrustedJSON(pdu, roomVersion) ev, everr := roomVersion.NewEventFromUntrustedJSON(pdu)
if everr != nil { if everr != nil {
return nil, fmt.Errorf("missingAuth gomatrixserverlib.NewEventFromUntrustedJSON: %w", everr) return nil, fmt.Errorf("missingAuth gomatrixserverlib.NewEventFromUntrustedJSON: %w", everr)
} }

View file

@ -105,7 +105,7 @@ func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u
func mustCreatePDU(t *testing.T) *gomatrixserverlib.HeaderedEvent { func mustCreatePDU(t *testing.T) *gomatrixserverlib.HeaderedEvent {
t.Helper() t.Helper()
content := `{"type":"m.room.message"}` content := `{"type":"m.room.message"}`
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(content), false, gomatrixserverlib.RoomVersionV10) ev, err := gomatrixserverlib.RoomVersionV10.NewEventFromTrustedJSON([]byte(content), false)
if err != nil { if err != nil {
t.Fatalf("failed to create event: %v", err) t.Fatalf("failed to create event: %v", err)
} }

View file

@ -78,7 +78,7 @@ func InviteV1(
) util.JSONResponse { ) util.JSONResponse {
roomVer := gomatrixserverlib.RoomVersionV1 roomVer := gomatrixserverlib.RoomVersionV1
body := request.Content() body := request.Content()
event, err := gomatrixserverlib.NewEventFromTrustedJSON(body, false, roomVer) event, err := roomVer.NewEventFromTrustedJSON(body, false)
switch err.(type) { switch err.(type) {
case gomatrixserverlib.BadJSONError: case gomatrixserverlib.BadJSONError:
return util.JSONResponse{ return util.JSONResponse{
@ -157,7 +157,7 @@ func processInvite(
} }
// Check that the event is signed by the server sending the request. // Check that the event is signed by the server sending the request.
redacted, err := gomatrixserverlib.RedactEventJSON(event.JSON(), event.Version()) redacted, err := event.Version().RedactEventJSON(event.JSON())
if err != nil { if err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,

View file

@ -207,7 +207,7 @@ func SendJoin(
} }
} }
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion) event, err := verRes.RoomVersion.NewEventFromUntrustedJSON(request.Content())
if err != nil { if err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
@ -287,7 +287,7 @@ func SendJoin(
} }
// Check that the event is signed by the server sending the request. // Check that the event is signed by the server sending the request.
redacted, err := gomatrixserverlib.RedactEventJSON(event.JSON(), event.Version()) redacted, err := event.Version().RedactEventJSON(event.JSON())
if err != nil { if err != nil {
logrus.WithError(err).Errorf("XXX: join.go") logrus.WithError(err).Errorf("XXX: join.go")
return util.JSONResponse{ return util.JSONResponse{

View file

@ -150,7 +150,7 @@ func SendLeave(
} }
// Decode the event JSON from the request. // Decode the event JSON from the request.
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion) event, err := verRes.RoomVersion.NewEventFromUntrustedJSON(request.Content())
switch err.(type) { switch err.(type) {
case gomatrixserverlib.BadJSONError: case gomatrixserverlib.BadJSONError:
return util.JSONResponse{ return util.JSONResponse{
@ -253,7 +253,7 @@ func SendLeave(
} }
// Check that the event is signed by the server sending the request. // Check that the event is signed by the server sending the request.
redacted, err := gomatrixserverlib.RedactEventJSON(event.JSON(), event.Version()) redacted, err := event.Version().RedactEventJSON(event.JSON())
if err != nil { if err != nil {
logrus.WithError(err).Errorf("XXX: leave.go") logrus.WithError(err).Errorf("XXX: leave.go")
return util.JSONResponse{ return util.JSONResponse{

View file

@ -196,7 +196,7 @@ func ExchangeThirdPartyInvite(
util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed") util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }
inviteEvent, err := gomatrixserverlib.UntrustedEvent(signedEvent.Event, verRes.RoomVersion) inviteEvent, err := verRes.RoomVersion.NewEventFromUntrustedJSON(signedEvent.Event)
if err != nil { if err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed") util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()

2
go.mod
View file

@ -22,7 +22,7 @@ require (
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
github.com/matrix-org/gomatrixserverlib v0.0.0-20230419135026-7f3c8ee774a0 github.com/matrix-org/gomatrixserverlib v0.0.0-20230420172450-7ea8ead4a832
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
github.com/mattn/go-sqlite3 v1.14.16 github.com/mattn/go-sqlite3 v1.14.16

6
go.sum
View file

@ -331,6 +331,12 @@ github.com/matrix-org/gomatrixserverlib v0.0.0-20230418132954-2113ec20fc8e h1:nL
github.com/matrix-org/gomatrixserverlib v0.0.0-20230418132954-2113ec20fc8e/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU= github.com/matrix-org/gomatrixserverlib v0.0.0-20230418132954-2113ec20fc8e/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230419135026-7f3c8ee774a0 h1:u+1vK+Sj2gL8IWgaaSF4WM38iL/Cx7jf6Q/aa1g0Icc= github.com/matrix-org/gomatrixserverlib v0.0.0-20230419135026-7f3c8ee774a0 h1:u+1vK+Sj2gL8IWgaaSF4WM38iL/Cx7jf6Q/aa1g0Icc=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230419135026-7f3c8ee774a0/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU= github.com/matrix-org/gomatrixserverlib v0.0.0-20230419135026-7f3c8ee774a0/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230420162839-554da317ffc2 h1:4ie9gE3sPfR8ecyRCpCUbWXnvgxB7fWj7O/B5NS0orc=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230420162839-554da317ffc2/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230420165305-c51ffd14d28d h1:pShTdTsNhtkY9cv0+tbFBvLnQKUeZ23ismYMc9xP9aE=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230420165305-c51ffd14d28d/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230420172450-7ea8ead4a832 h1:xEUPCS8+BEJ9+JEazxkQS1+YnWyFAsHoIMp5ijA7NAY=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230420172450-7ea8ead4a832/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=

View file

@ -189,7 +189,7 @@ func TestPatternMatches(t *testing.T) {
} }
func mustEventFromJSON(t *testing.T, json string) *gomatrixserverlib.Event { func mustEventFromJSON(t *testing.T, json string) *gomatrixserverlib.Event {
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(json), false, gomatrixserverlib.RoomVersionV7) ev, err := gomatrixserverlib.RoomVersionV7.NewEventFromTrustedJSON([]byte(json), false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -137,7 +137,7 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *ut
continue continue
} }
roomVersion := getRoomVersion(header.RoomID) roomVersion := getRoomVersion(header.RoomID)
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(pdu, roomVersion) event, err := roomVersion.NewEventFromUntrustedJSON(pdu)
if err != nil { if err != nil {
if _, ok := err.(gomatrixserverlib.BadJSONError); ok { if _, ok := err.(gomatrixserverlib.BadJSONError); ok {
// Room version 6 states that homeservers should strictly enforce canonical JSON // Room version 6 states that homeservers should strictly enforce canonical JSON

View file

@ -633,7 +633,7 @@ func TestProcessTransactionRequestEDUUnhandled(t *testing.T) {
func init() { func init() {
for _, j := range testData { for _, j := range testData {
e, err := gomatrixserverlib.NewEventFromTrustedJSON(j, false, testRoomVersion) e, err := testRoomVersion.NewEventFromTrustedJSON(j, false)
if err != nil { if err != nil {
panic("cannot load test data: " + err.Error()) panic("cannot load test data: " + err.Error())
} }

View file

@ -149,7 +149,7 @@ func IsInvitePending(
return false, "", "", nil, fmt.Errorf("missing user for NID %d (%+v)", senderUserNIDs[0], senderUsers) return false, "", "", nil, fmt.Errorf("missing user for NID %d (%+v)", senderUserNIDs[0], senderUsers)
} }
event, err := gomatrixserverlib.NewEventFromTrustedJSON(eventJSON, false, info.RoomVersion) event, err := info.RoomVersion.NewEventFromTrustedJSON(eventJSON, false)
return true, senderUser, userNIDToEventID[senderUserNIDs[0]], event, err return true, senderUser, userNIDToEventID[senderUserNIDs[0]], event, err
} }

View file

@ -865,7 +865,7 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
} }
continue continue
} }
event, err = gomatrixserverlib.NewEventFromUntrustedJSON(txn.PDUs[0], roomVersion) event, err = roomVersion.NewEventFromUntrustedJSON(txn.PDUs[0])
if err != nil { if err != nil {
t.log.WithError(err).WithField("missing_event_id", missingEventID).Warnf("Failed to parse event JSON of event returned from /event") t.log.WithError(err).WithField("missing_event_id", missingEventID).Warnf("Failed to parse event JSON of event returned from /event")
continue continue

View file

@ -35,9 +35,9 @@ func TestSingleTransactionOnInput(t *testing.T) {
ctx, cancel := context.WithDeadline(processCtx.Context(), deadline) ctx, cancel := context.WithDeadline(processCtx.Context(), deadline)
defer cancel() defer cancel()
event, err := gomatrixserverlib.NewEventFromTrustedJSON( event, err := gomatrixserverlib.RoomVersionV6.NewEventFromTrustedJSON(
[]byte(`{"auth_events":[],"content":{"creator":"@neilalexander:dendrite.matrix.org","room_version":"6"},"depth":1,"hashes":{"sha256":"jqOqdNEH5r0NiN3xJtj0u5XUVmRqq9YvGbki1wxxuuM"},"origin":"dendrite.matrix.org","origin_server_ts":1644595362726,"prev_events":[],"prev_state":[],"room_id":"!jSZZRknA6GkTBXNP:dendrite.matrix.org","sender":"@neilalexander:dendrite.matrix.org","signatures":{"dendrite.matrix.org":{"ed25519:6jB2aB":"bsQXO1wketf1OSe9xlndDIWe71W9KIundc6rBw4KEZdGPW7x4Tv4zDWWvbxDsG64sS2IPWfIm+J0OOozbrWIDw"}},"state_key":"","type":"m.room.create"}`), []byte(`{"auth_events":[],"content":{"creator":"@neilalexander:dendrite.matrix.org","room_version":"6"},"depth":1,"hashes":{"sha256":"jqOqdNEH5r0NiN3xJtj0u5XUVmRqq9YvGbki1wxxuuM"},"origin":"dendrite.matrix.org","origin_server_ts":1644595362726,"prev_events":[],"prev_state":[],"room_id":"!jSZZRknA6GkTBXNP:dendrite.matrix.org","sender":"@neilalexander:dendrite.matrix.org","signatures":{"dendrite.matrix.org":{"ed25519:6jB2aB":"bsQXO1wketf1OSe9xlndDIWe71W9KIundc6rBw4KEZdGPW7x4Tv4zDWWvbxDsG64sS2IPWfIm+J0OOozbrWIDw"}},"state_key":"","type":"m.room.create"}`),
false, gomatrixserverlib.RoomVersionV6, false,
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View file

@ -54,8 +54,8 @@ func (db *getEventDB) addFakeEvent(eventID string, authIDs []string) error {
return err return err
} }
event, err := gomatrixserverlib.NewEventFromTrustedJSON( event, err := gomatrixserverlib.RoomVersionV1.NewEventFromTrustedJSON(
eventJSON, false, gomatrixserverlib.RoomVersionV1, eventJSON, false,
) )
if err != nil { if err != nil {
return err return err

View file

@ -232,7 +232,7 @@ func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(
result[eventID] = ev result[eventID] = ev
continue continue
} }
event, err := gomatrixserverlib.NewEventFromTrustedJSON(evJson, false, roomInfo.RoomVersion) event, err := roomInfo.RoomVersion.NewEventFromTrustedJSON(evJson, false)
if err != nil { if err != nil {
result[eventID] = &gomatrixserverlib.HeaderedEvent{} result[eventID] = &gomatrixserverlib.HeaderedEvent{}
// not fatal // not fatal

View file

@ -581,8 +581,8 @@ func (d *EventDatabase) events(
for _, eventJSON := range eventJSONs { for _, eventJSON := range eventJSONs {
redacted := gjson.GetBytes(eventJSON.EventJSON, "unsigned.redacted_because").Exists() redacted := gjson.GetBytes(eventJSON.EventJSON, "unsigned.redacted_because").Exists()
events[eventJSON.EventNID], err = gomatrixserverlib.NewEventFromTrustedJSONWithEventID( events[eventJSON.EventNID], err = roomInfo.RoomVersion.NewEventFromTrustedJSONWithEventID(
eventIDs[eventJSON.EventNID], eventJSON.EventJSON, redacted, roomInfo.RoomVersion, eventIDs[eventJSON.EventNID], eventJSON.EventJSON, redacted,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -1131,7 +1131,7 @@ func (d *Database) GetHistoryVisibilityState(ctx context.Context, roomInfo *type
if err != nil { if err != nil {
return nil, err return nil, err
} }
ev, err := gomatrixserverlib.NewEventFromTrustedJSONWithEventID(eventIDs[eventNID], data[0].EventJSON, false, roomInfo.RoomVersion) ev, err := roomInfo.RoomVersion.NewEventFromTrustedJSONWithEventID(eventIDs[eventNID], data[0].EventJSON, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1195,7 +1195,7 @@ func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey s
if len(data) == 0 { if len(data) == 0 {
return nil, fmt.Errorf("GetStateEvent: no json for event nid %d", e.EventNID) return nil, fmt.Errorf("GetStateEvent: no json for event nid %d", e.EventNID)
} }
ev, err := gomatrixserverlib.NewEventFromTrustedJSONWithEventID(eventIDs[e.EventNID], data[0].EventJSON, false, roomInfo.RoomVersion) ev, err := roomInfo.RoomVersion.NewEventFromTrustedJSONWithEventID(eventIDs[e.EventNID], data[0].EventJSON, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1252,7 +1252,7 @@ func (d *Database) GetStateEventsWithEventType(ctx context.Context, roomID, evTy
} }
var result []*gomatrixserverlib.HeaderedEvent var result []*gomatrixserverlib.HeaderedEvent
for _, pair := range eventPairs { for _, pair := range eventPairs {
ev, err := gomatrixserverlib.NewEventFromTrustedJSONWithEventID(eventIDs[pair.EventNID], pair.EventJSON, false, roomInfo.RoomVersion) ev, err := roomInfo.RoomVersion.NewEventFromTrustedJSONWithEventID(eventIDs[pair.EventNID], pair.EventJSON, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1372,7 +1372,7 @@ func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tu
result := make([]tables.StrippedEvent, len(events)) result := make([]tables.StrippedEvent, len(events))
for i := range events { for i := range events {
roomVer := eventNIDToVer[events[i].EventNID] roomVer := eventNIDToVer[events[i].EventNID]
ev, err := gomatrixserverlib.NewEventFromTrustedJSONWithEventID(eventIDs[events[i].EventNID], events[i].EventJSON, false, roomVer) ev, err := roomVer.NewEventFromTrustedJSONWithEventID(eventIDs[events[i].EventNID], events[i].EventJSON, false)
if err != nil { if err != nil {
return nil, fmt.Errorf("GetBulkStateContent: failed to load event JSON for event NID %v : %w", events[i].EventNID, err) return nil, fmt.Errorf("GetBulkStateContent: failed to load event JSON for event NID %v : %w", events[i].EventNID, err)
} }

View file

@ -24,7 +24,7 @@ import (
) )
func TestToClientEvent(t *testing.T) { // nolint: gocyclo func TestToClientEvent(t *testing.T) { // nolint: gocyclo
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(`{ ev, err := gomatrixserverlib.RoomVersionV1.NewEventFromTrustedJSON([]byte(`{
"type": "m.room.name", "type": "m.room.name",
"state_key": "", "state_key": "",
"event_id": "$test:localhost", "event_id": "$test:localhost",
@ -39,7 +39,7 @@ func TestToClientEvent(t *testing.T) { // nolint: gocyclo
"name": "Goodbye World" "name": "Goodbye World"
} }
} }
}`), false, gomatrixserverlib.RoomVersionV1) }`), false)
if err != nil { if err != nil {
t.Fatalf("failed to create Event: %s", err) t.Fatalf("failed to create Event: %s", err)
} }
@ -79,7 +79,7 @@ func TestToClientEvent(t *testing.T) { // nolint: gocyclo
} }
func TestToClientFormatSync(t *testing.T) { func TestToClientFormatSync(t *testing.T) {
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(`{ ev, err := gomatrixserverlib.RoomVersionV1.NewEventFromTrustedJSON([]byte(`{
"type": "m.room.name", "type": "m.room.name",
"state_key": "", "state_key": "",
"event_id": "$test:localhost", "event_id": "$test:localhost",
@ -94,7 +94,7 @@ func TestToClientFormatSync(t *testing.T) {
"name": "Goodbye World" "name": "Goodbye World"
} }
} }
}`), false, gomatrixserverlib.RoomVersionV1) }`), false)
if err != nil { if err != nil {
t.Fatalf("failed to create Event: %s", err) t.Fatalf("failed to create Event: %s", err)
} }

View file

@ -50,7 +50,7 @@ func TestNewInviteResponse(t *testing.T) {
event := `{"auth_events":["$SbSsh09j26UAXnjd3RZqf2lyA3Kw2sY_VZJVZQAV9yA","$EwL53onrLwQ5gL8Dv3VrOOCvHiueXu2ovLdzqkNi3lo","$l2wGmz9iAwevBDGpHT_xXLUA5O8BhORxWIGU1cGi1ZM","$GsWFJLXgdlF5HpZeyWkP72tzXYWW3uQ9X28HBuTztHE"],"content":{"avatar_url":"","displayname":"neilalexander","membership":"invite"},"depth":9,"hashes":{"sha256":"8p+Ur4f8vLFX6mkIXhxI0kegPG7X3tWy56QmvBkExAg"},"origin":"matrix.org","origin_server_ts":1602087113066,"prev_events":["$1v-O6tNwhOZcA8bvCYY-Dnj1V2ZDE58lLPxtlV97S28"],"prev_state":[],"room_id":"!XbeXirGWSPXbEaGokF:matrix.org","sender":"@neilalexander:matrix.org","signatures":{"dendrite.neilalexander.dev":{"ed25519:BMJi":"05KQ5lPw0cSFsE4A0x1z7vi/3cc8bG4WHUsFWYkhxvk/XkXMGIYAYkpNThIvSeLfdcHlbm/k10AsBSKH8Uq4DA"},"matrix.org":{"ed25519:a_RXGa":"jeovuHr9E/x0sHbFkdfxDDYV/EyoeLi98douZYqZ02iYddtKhfB7R3WLay/a+D3V3V7IW0FUmPh/A404x5sYCw"}},"state_key":"@neilalexander:dendrite.neilalexander.dev","type":"m.room.member","unsigned":{"age":2512,"invite_room_state":[{"content":{"join_rule":"invite"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.join_rules"},{"content":{"avatar_url":"mxc://matrix.org/BpDaozLwgLnlNStxDxvLzhPr","displayname":"neilalexander","membership":"join"},"sender":"@neilalexander:matrix.org","state_key":"@neilalexander:matrix.org","type":"m.room.member"},{"content":{"name":"Test room"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.name"}]},"_room_version":"5"}` event := `{"auth_events":["$SbSsh09j26UAXnjd3RZqf2lyA3Kw2sY_VZJVZQAV9yA","$EwL53onrLwQ5gL8Dv3VrOOCvHiueXu2ovLdzqkNi3lo","$l2wGmz9iAwevBDGpHT_xXLUA5O8BhORxWIGU1cGi1ZM","$GsWFJLXgdlF5HpZeyWkP72tzXYWW3uQ9X28HBuTztHE"],"content":{"avatar_url":"","displayname":"neilalexander","membership":"invite"},"depth":9,"hashes":{"sha256":"8p+Ur4f8vLFX6mkIXhxI0kegPG7X3tWy56QmvBkExAg"},"origin":"matrix.org","origin_server_ts":1602087113066,"prev_events":["$1v-O6tNwhOZcA8bvCYY-Dnj1V2ZDE58lLPxtlV97S28"],"prev_state":[],"room_id":"!XbeXirGWSPXbEaGokF:matrix.org","sender":"@neilalexander:matrix.org","signatures":{"dendrite.neilalexander.dev":{"ed25519:BMJi":"05KQ5lPw0cSFsE4A0x1z7vi/3cc8bG4WHUsFWYkhxvk/XkXMGIYAYkpNThIvSeLfdcHlbm/k10AsBSKH8Uq4DA"},"matrix.org":{"ed25519:a_RXGa":"jeovuHr9E/x0sHbFkdfxDDYV/EyoeLi98douZYqZ02iYddtKhfB7R3WLay/a+D3V3V7IW0FUmPh/A404x5sYCw"}},"state_key":"@neilalexander:dendrite.neilalexander.dev","type":"m.room.member","unsigned":{"age":2512,"invite_room_state":[{"content":{"join_rule":"invite"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.join_rules"},{"content":{"avatar_url":"mxc://matrix.org/BpDaozLwgLnlNStxDxvLzhPr","displayname":"neilalexander","membership":"join"},"sender":"@neilalexander:matrix.org","state_key":"@neilalexander:matrix.org","type":"m.room.member"},{"content":{"name":"Test room"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.name"}]},"_room_version":"5"}`
expected := `{"invite_state":{"events":[{"content":{"join_rule":"invite"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.join_rules"},{"content":{"avatar_url":"mxc://matrix.org/BpDaozLwgLnlNStxDxvLzhPr","displayname":"neilalexander","membership":"join"},"sender":"@neilalexander:matrix.org","state_key":"@neilalexander:matrix.org","type":"m.room.member"},{"content":{"name":"Test room"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.name"},{"content":{"avatar_url":"","displayname":"neilalexander","membership":"invite"},"event_id":"$GQmw8e8-26CQv1QuFoHBHpKF1hQj61Flg3kvv_v_XWs","origin_server_ts":1602087113066,"sender":"@neilalexander:matrix.org","state_key":"@neilalexander:dendrite.neilalexander.dev","type":"m.room.member"}]}}` expected := `{"invite_state":{"events":[{"content":{"join_rule":"invite"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.join_rules"},{"content":{"avatar_url":"mxc://matrix.org/BpDaozLwgLnlNStxDxvLzhPr","displayname":"neilalexander","membership":"join"},"sender":"@neilalexander:matrix.org","state_key":"@neilalexander:matrix.org","type":"m.room.member"},{"content":{"name":"Test room"},"sender":"@neilalexander:matrix.org","state_key":"","type":"m.room.name"},{"content":{"avatar_url":"","displayname":"neilalexander","membership":"invite"},"event_id":"$GQmw8e8-26CQv1QuFoHBHpKF1hQj61Flg3kvv_v_XWs","origin_server_ts":1602087113066,"sender":"@neilalexander:matrix.org","state_key":"@neilalexander:dendrite.neilalexander.dev","type":"m.room.member"}]}}`
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(event), false, gomatrixserverlib.RoomVersionV5) ev, err := gomatrixserverlib.RoomVersionV5.NewEventFromTrustedJSON([]byte(event), false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -36,7 +36,7 @@ func mustCreateDatabase(t *testing.T, dbType test.DBType) (storage.UserDatabase,
func mustCreateEvent(t *testing.T, content string) *gomatrixserverlib.HeaderedEvent { func mustCreateEvent(t *testing.T, content string) *gomatrixserverlib.HeaderedEvent {
t.Helper() t.Helper()
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(content), false, gomatrixserverlib.RoomVersionV10) ev, err := gomatrixserverlib.RoomVersionV10.NewEventFromTrustedJSON([]byte(content), false)
if err != nil { if err != nil {
t.Fatalf("failed to create event: %v", err) t.Fatalf("failed to create event: %v", err)
} }