Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for events whose auth_events cannot be found #211

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Changes from 1 commit
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
30 changes: 30 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,18 @@ 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)
// eventAuthMap[sentEvent2.EventID()] = []*gomatrixserverlib.Event{}
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 +199,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 +231,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)
}
})
}