Skip to content

Commit 7f925b8

Browse files
authored
Add /event_auth test (#280)
* Add /event_auth test * bump gmsl * Expand event auth test wip * Add more comprehensive /event_auth tests * Slightly better logging
1 parent 5742fdd commit 7f925b8

File tree

5 files changed

+189
-9
lines changed

5 files changed

+189
-9
lines changed

go.mod

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ require (
99
github.com/docker/go-connections v0.4.0
1010
github.com/docker/go-units v0.4.0 // indirect
1111
github.com/gorilla/mux v1.8.0
12-
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26
13-
github.com/matrix-org/gomatrixserverlib v0.0.0-20211115130817-ba4a3b9a6f12
14-
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7
12+
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
13+
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
14+
github.com/matrix-org/gomatrixserverlib v0.0.0-20220106115324-39c7d37db009
15+
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
1516
github.com/opencontainers/go-digest v1.0.0 // indirect
1617
github.com/pkg/errors v0.9.1 // indirect
17-
github.com/sirupsen/logrus v1.6.0
18-
github.com/tidwall/gjson v1.9.3
19-
github.com/tidwall/sjson v1.1.5
20-
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
18+
github.com/sirupsen/logrus v1.8.1
19+
github.com/tidwall/gjson v1.12.1
20+
github.com/tidwall/sjson v1.2.4
21+
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
2122
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
22-
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
23+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
2324
maunium.net/go/mautrix v0.8.3
2425
)

go.sum

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
5151
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
5252
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bhrnp3Ky1qgx/fzCtCALOoGYylh2tpS9K4=
5353
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
54+
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 h1:ZtO5uywdd5dLDCud4r0r55eP4j9FuUNpl60Gmntcop4=
55+
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
5456
github.com/matrix-org/gomatrixserverlib v0.0.0-20211115130817-ba4a3b9a6f12 h1:vpZov9fXOydP3U5dexANC5yttnMXaSdStlb2mlbKqbs=
5557
github.com/matrix-org/gomatrixserverlib v0.0.0-20211115130817-ba4a3b9a6f12/go.mod h1:rB8tBUUUo1rzUqpzklRDSooxZ6YMhoaEPx4SO5fGeUc=
58+
github.com/matrix-org/gomatrixserverlib v0.0.0-20220106093527-339f99711f7e h1:mzdwdTWH6pJ7l5QBDntPQpAakq100fG/e4x/nuP6bTc=
59+
github.com/matrix-org/gomatrixserverlib v0.0.0-20220106093527-339f99711f7e/go.mod h1:rB8tBUUUo1rzUqpzklRDSooxZ6YMhoaEPx4SO5fGeUc=
60+
github.com/matrix-org/gomatrixserverlib v0.0.0-20220106115324-39c7d37db009 h1:RV3hT9eHpBSjg0m8W44bgonVUrJI866FkfrW6lf03a0=
61+
github.com/matrix-org/gomatrixserverlib v0.0.0-20220106115324-39c7d37db009/go.mod h1:qFvhfbQ5orQxlH9vCiFnP4dW27xxnWHdNUBKyj/fbiY=
5662
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 h1:ntrLa/8xVzeSs8vHFHK25k0C+NV74sYMJnNSg5NoSRo=
5763
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7/go.mod h1:vVQlW/emklohkZnOPwD3LrZUBqdfsbiyO3p1lNV8F6U=
64+
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4 h1:eCEHXWDv9Rm335MSuB49mFUK44bwZPFSDde3ORE3syk=
65+
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4/go.mod h1:vVQlW/emklohkZnOPwD3LrZUBqdfsbiyO3p1lNV8F6U=
5866
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
5967
github.com/miekg/dns v1.1.25 h1:dFwPR6SfLtrSwgDcIq2bcU/gVutB4sNApq2HBdqcakg=
6068
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
@@ -76,6 +84,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
7684
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
7785
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
7886
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
87+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
88+
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
7989
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8090
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8191
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@@ -85,6 +95,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
8595
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
8696
github.com/tidwall/gjson v1.9.3 h1:hqzS9wAHMO+KVBBkLxYdkEeeFHuqr95GfClRLKlgK0E=
8797
github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
98+
github.com/tidwall/gjson v1.12.1 h1:ikuZsLdhr8Ws0IdROXUS1Gi4v9Z4pGqpX/CvJkxvfpo=
99+
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
88100
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
89101
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
90102
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
@@ -94,6 +106,8 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso
94106
github.com/tidwall/sjson v1.0.3/go.mod h1:bURseu1nuBkFpIES5cz6zBtjmYeOQmEESshn7VpF15Y=
95107
github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
96108
github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
109+
github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc=
110+
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
97111
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
98112
golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
99113
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -102,6 +116,8 @@ golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPh
102116
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
103117
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
104118
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
119+
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
120+
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
105121
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
106122
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
107123
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -110,6 +126,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
110126
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
111127
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
112128
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
129+
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
130+
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
113131
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
114132
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
115133
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -127,13 +145,18 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
127145
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
128146
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
129147
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
148+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
149+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
130150
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
131151
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
152+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
153+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
132154
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
133155
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
134156
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
135157
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
136158
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
159+
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
137160
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
138161
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
139162
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/federation/handle.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ func HandleMediaRequests(mediaIds map[string]func(w http.ResponseWriter)) func(*
322322
}
323323

324324
// HandleTransactionRequests is an option which will process GET /_matrix/federation/v1/send/{transactionID} requests universally when requested.
325-
// pduCallback and eduCallback are functions that if non-nil will be called and passed each PDU or EDU event received in the transaction
325+
// pduCallback and eduCallback are functions that if non-nil will be called and passed each PDU or EDU event received in the transaction.
326+
// Callbacks will be fired AFTER the event has been stored onto the respective ServerRoom.
326327
func HandleTransactionRequests(pduCallback func(*gomatrixserverlib.Event), eduCallback func(gomatrixserverlib.EDU)) func(*Server) {
327328
return func(srv *Server) {
328329
srv.mux.Handle("/_matrix/federation/v1/send/{transactionID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {

internal/federation/server.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,44 @@ func (s *Server) MustJoinRoom(t *testing.T, deployment *docker.Deployment, remot
245245
return room
246246
}
247247

248+
// Leaves a room. If this is rejecting an invite then a make_leave request is made first, before send_leave.
249+
func (s *Server) MustLeaveRoom(t *testing.T, deployment *docker.Deployment, remoteServer gomatrixserverlib.ServerName, roomID string, userID string) {
250+
t.Helper()
251+
fedClient := s.FederationClient(deployment)
252+
var leaveEvent *gomatrixserverlib.Event
253+
room := s.rooms[roomID]
254+
if room == nil {
255+
// e.g rejecting an invite
256+
makeLeaveResp, err := fedClient.MakeLeave(context.Background(), remoteServer, roomID, userID)
257+
if err != nil {
258+
t.Fatalf("MustLeaveRoom: (rejecting invite) make_leave failed: %v", err)
259+
}
260+
roomVer := makeLeaveResp.RoomVersion
261+
leaveEvent, err = makeLeaveResp.LeaveEvent.Build(time.Now(), gomatrixserverlib.ServerName(s.ServerName), s.KeyID, s.Priv, roomVer)
262+
if err != nil {
263+
t.Fatalf("MustLeaveRoom: (rejecting invite) failed to sign event: %v", err)
264+
}
265+
} else {
266+
// make the leave event
267+
leaveEvent = s.MustCreateEvent(t, room, b.Event{
268+
Type: "m.room.member",
269+
StateKey: &userID,
270+
Sender: userID,
271+
Content: map[string]interface{}{
272+
"membership": "leave",
273+
},
274+
})
275+
}
276+
err := fedClient.SendLeave(context.Background(), gomatrixserverlib.ServerName(remoteServer), leaveEvent)
277+
if err != nil {
278+
t.Fatalf("MustLeaveRoom: send_leave failed: %v", err)
279+
}
280+
room.AddEvent(leaveEvent)
281+
s.rooms[roomID] = room
282+
283+
t.Logf("Server.MustLeaveRoom left room ID %s", roomID)
284+
}
285+
248286
// Mux returns this server's router so you can attach additional paths
249287
func (s *Server) Mux() *mux.Router {
250288
return s.mux
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package tests
2+
3+
import (
4+
"context"
5+
"testing"
6+
"time"
7+
8+
"github.com/matrix-org/complement/internal/b"
9+
"github.com/matrix-org/complement/internal/federation"
10+
"github.com/matrix-org/complement/internal/must"
11+
12+
"github.com/matrix-org/gomatrixserverlib"
13+
)
14+
15+
// Test basic functionality of /_matrix/federation/v1/event_auth/{roomId}/{eventId}
16+
// and critically ensures that no extraneous events are returned
17+
// this was a dendrite bug, see https://github.com/matrix-org/dendrite/issues/2084
18+
//
19+
// This test works by configuring the following room:
20+
// - New room over federation between the HS and Complement
21+
// - Charlie on Complement joins the room over federation, then leaves, then rejoins
22+
// - Alice updates join rules for the room (test waits until it sees this event over federation)
23+
// At this point we can then test:
24+
// - /event_auth for the join rules event just returns the chain for the join rules event, which
25+
// just means it returns the auth_events as that is equal to the auth chain for this event.
26+
// - /event_auth for the latest join event returns the complete auth chain for Charlie (all the
27+
// joins and leaves are included), without any extraneous events.
28+
func TestEventAuth(t *testing.T) {
29+
deployment := Deploy(t, b.BlueprintOneToOneRoom)
30+
defer deployment.Destroy(t)
31+
32+
alice := deployment.Client(t, "hs1", "@alice:hs1")
33+
34+
// create a remote homeserver which will make the /event_auth request
35+
var joinRuleEvent *gomatrixserverlib.Event
36+
waiter := NewWaiter()
37+
srv := federation.NewServer(t, deployment,
38+
federation.HandleKeyRequests(),
39+
federation.HandleMakeSendJoinRequests(),
40+
federation.HandleTransactionRequests(
41+
// listen for the new join rule event
42+
func(ev *gomatrixserverlib.Event) {
43+
if jr, _ := ev.JoinRule(); jr == "invite" {
44+
joinRuleEvent = ev
45+
waiter.Finish()
46+
}
47+
},
48+
nil,
49+
),
50+
)
51+
srv.UnexpectedRequestsAreErrors = false // we expect to be pushed events
52+
cancel := srv.Listen()
53+
defer cancel()
54+
55+
// make a room and join it
56+
charlie := srv.UserID("charlie")
57+
roomID := alice.CreateRoom(t, map[string]interface{}{
58+
"preset": "public_chat",
59+
})
60+
room := srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie)
61+
firstJoinEvent := room.CurrentState("m.room.member", charlie)
62+
srv.MustLeaveRoom(t, deployment, "hs1", roomID, charlie)
63+
leaveEvent := room.CurrentState("m.room.member", charlie)
64+
room = srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie)
65+
66+
// now update the auth chain a bit: dendrite had a bug where it returned the auth chain for all
67+
// the current state in addition to the event asked for
68+
alice.SendEventSynced(t, roomID, b.Event{
69+
Type: "m.room.join_rules",
70+
StateKey: b.Ptr(""),
71+
Content: map[string]interface{}{
72+
"join_rule": "invite",
73+
},
74+
})
75+
waiter.Wait(t, 1*time.Second) // wait for the join rule to make it to the complement server
76+
77+
getEventAuth := func(t *testing.T, eventID string, wantAuthEventIDs []string) {
78+
t.Helper()
79+
t.Logf("/event_auth for %s - want %v", eventID, wantAuthEventIDs)
80+
resp, err := srv.FederationClient(deployment).GetEventAuth(context.Background(), "hs1", room.Version, roomID, eventID)
81+
must.NotError(t, "failed to /event_auth", err)
82+
if len(resp.AuthEvents) == 0 {
83+
t.Fatalf("/event_auth returned 0 auth events")
84+
}
85+
if len(resp.AuthEvents) != len(wantAuthEventIDs) {
86+
msg := "got:\n"
87+
for _, e := range resp.AuthEvents {
88+
msg += e.EventID() + " : " + string(e.JSON()) + "\n\n"
89+
}
90+
t.Fatalf("got %d auth events, wanted %d.\n%s\nwant: %s", len(resp.AuthEvents), len(wantAuthEventIDs), msg, wantAuthEventIDs)
91+
}
92+
// make sure all the events match
93+
wantIDs := map[string]bool{}
94+
for _, id := range wantAuthEventIDs {
95+
wantIDs[id] = true
96+
}
97+
for _, e := range resp.AuthEvents {
98+
delete(wantIDs, e.EventID())
99+
}
100+
if len(wantIDs) > 0 {
101+
t.Errorf("missing events %v", wantIDs)
102+
}
103+
}
104+
105+
t.Run("returns auth events for the requested event", func(t *testing.T) {
106+
// now hit /event_auth for the join_rules event. The auth chain == the auth events.
107+
getEventAuth(t, joinRuleEvent.EventID(), joinRuleEvent.AuthEventIDs())
108+
})
109+
110+
t.Run("returns the auth chain for the requested event", func(t *testing.T) {
111+
latestJoinEvent := room.CurrentState("m.room.member", charlie)
112+
// we want all the auth event IDs for the latest join event AND the previous leave and join events
113+
wantAuthEvents := latestJoinEvent.AuthEventIDs()
114+
wantAuthEvents = append(wantAuthEvents, firstJoinEvent.EventID(), leaveEvent.EventID())
115+
getEventAuth(t, latestJoinEvent.EventID(), wantAuthEvents)
116+
})
117+
}

0 commit comments

Comments
 (0)