Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/federation_room_event_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) {
* regular event. Doing so means that the regular event should itself be
* rejected.
*
* We actually send two such events. On one of them, we reply to the
* incoming /event_auth request with the bogus outlier in
* the auth_events; for the other, we return a 404. This means we can
* exercise different code paths in Synapse.
*
* We finish up by sending a final, normal, event which should be accepted
* everywhere. This acts as a sentinel so that we can be sure that the
* events have all been correctly propagated.
Expand All @@ -42,6 +47,8 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) {
* | ... O
* | ^
* X .......
* | ^
* Y .......
* |
* S
*
Expand All @@ -53,6 +60,8 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) {
* O is an outlier, which should be rejected
* X is an event with O among its auth_events, which should be rejected
* as a side-effect of O being rejected
* Y is a second regular event with O in its auth_events, but we give a
* different reply to /event_auth
* S is the final regular event, which acts as a sentinel
*
* To check if the outlier is rejected, we simply request the event via
Expand Down Expand Up @@ -163,6 +172,19 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) {
eventAuthMap[sentEvent1.EventID()] = sentEventAuthEvents
t.Logf("Created sent event 1 %s", sentEvent1.EventID())

// another a regular event which refers to the outlier event, but
// this time we will give a different answer to /event_auth
sentEvent2 := srv.MustCreateEvent(t, room, b.Event{
Type: "m.room.message",
Sender: charlie,
Content: map[string]interface{}{"body": "sentEvent1"},
AuthEvents: room.EventIDsOrReferences(sentEventAuthEvents),
})
room.AddEvent(sentEvent2)
// we deliberately add nothing to eventAuthMap for this event, to make /event_auth
// return a 404.
t.Logf("Created sent event 2 %s", sentEvent2.EventID())

// finally, a genuine regular event.
sentinelEvent := srv.MustCreateEvent(t, room, b.Event{
Type: "m.room.message",
Expand All @@ -178,6 +200,7 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) {
OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
PDUs: []json.RawMessage{
sentEvent1.JSON(),
sentEvent2.JSON(),
sentinelEvent.JSON(),
},
})
Expand Down Expand Up @@ -209,4 +232,12 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) {
t.Errorf("Expected a 404 when fetching sent event 1, but got %d", res.StatusCode)
}
})

t.Run("sent event 2 should be rejected", func(t *testing.T) {
res := alice.DoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", room.RoomID, "event", sentEvent2.EventID()})
defer res.Body.Close()
if res.StatusCode != 404 {
t.Errorf("Expected a 404 when fetching sent event 2, but got %d", res.StatusCode)
}
})
}