Fix up failing sytest

This commit is contained in:
Kegan Dougal 2020-09-16 16:09:22 +01:00
parent 52d911bfc6
commit 5ca4558de7
5 changed files with 44 additions and 43 deletions

View file

@ -122,15 +122,7 @@ func SendEventWithRewrite(
// We will handle an event as if it's an outlier if one of the // We will handle an event as if it's an outlier if one of the
// following conditions is true: // following conditions is true:
storeAsOutlier := false storeAsOutlier := false
if authOrStateEvent.Type() == event.Type() && *authOrStateEvent.StateKey() == *event.StateKey() { if _, ok := isCurrentState[authOrStateEvent.EventID()]; !ok {
// The event is a state event but the input event is going to
// replace it, therefore it can't be added to the state or we'll
// get duplicate state keys in the state block. We'll send it
// as an outlier because we don't know if something will be
// referring to it as an auth event, but need it to be stored
// just in case.
storeAsOutlier = true
} else if _, ok := isCurrentState[authOrStateEvent.EventID()]; !ok {
// The event is an auth event and isn't a part of the state set. // The event is an auth event and isn't a part of the state set.
// We'll send it as an outlier because we need it to be stored // We'll send it as an outlier because we need it to be stored
// in case something is referring to it as an auth event. // in case something is referring to it as an auth event.

View file

@ -32,7 +32,18 @@ func CheckForSoftFail(
ctx context.Context, ctx context.Context,
db storage.Database, db storage.Database,
event gomatrixserverlib.HeaderedEvent, event gomatrixserverlib.HeaderedEvent,
stateEventIDs []string,
) (bool, error) { ) (bool, error) {
rewritesState := len(stateEventIDs) > 1
var authStateEntries []types.StateEntry
var err error
if rewritesState {
authStateEntries, err = db.StateEntriesForEventIDs(ctx, stateEventIDs)
if err != nil {
return true, fmt.Errorf("StateEntriesForEventIDs failed: %w", err)
}
} else {
// Work out if the room exists. // Work out if the room exists.
roomInfo, err := db.RoomInfo(ctx, event.RoomID()) roomInfo, err := db.RoomInfo(ctx, event.RoomID())
if err != nil { if err != nil {
@ -42,19 +53,14 @@ func CheckForSoftFail(
return false, nil return false, nil
} }
// If the room exist, gets the current state snapshot.
_, stateSnapshotNID, _, err := db.LatestEventIDs(ctx, roomInfo.RoomNID)
if err != nil {
return true, fmt.Errorf("r.DB.LatestEventIDs: %w", err)
}
// Then get the state entries for the current state snapshot. // Then get the state entries for the current state snapshot.
// We'll use this to check if the event is allowed right now. // We'll use this to check if the event is allowed right now.
roomState := state.NewStateResolution(db, *roomInfo) roomState := state.NewStateResolution(db, *roomInfo)
authStateEntries, err := roomState.LoadStateAtSnapshot(ctx, stateSnapshotNID) authStateEntries, err = roomState.LoadStateAtSnapshot(ctx, roomInfo.StateSnapshotNID)
if err != nil { if err != nil {
return true, fmt.Errorf("roomState.LoadStateAtSnapshot: %w", err) return true, fmt.Errorf("roomState.LoadStateAtSnapshot: %w", err)
} }
}
// As a special case, it's possible that the room will have no // As a special case, it's possible that the room will have no
// state because we haven't received a m.room.create event yet. // state because we haven't received a m.room.create event yet.

View file

@ -43,7 +43,6 @@ func (r *Inputer) processRoomEvent(
// Parse and validate the event JSON // Parse and validate the event JSON
headered := input.Event headered := input.Event
event := headered.Unwrap() event := headered.Unwrap()
softfail := false
// Check that the event passes authentication checks and work out // Check that the event passes authentication checks and work out
// the numeric IDs for the auth events. // the numeric IDs for the auth events.
@ -54,9 +53,11 @@ func (r *Inputer) processRoomEvent(
isRejected = true isRejected = true
} }
var softfail bool
if input.Kind == api.KindBackfill || input.Kind == api.KindNew {
// Check that the event passes authentication checks based on the // Check that the event passes authentication checks based on the
// current room state. // current room state.
softfail, err = helpers.CheckForSoftFail(ctx, r.DB, headered) softfail, err = helpers.CheckForSoftFail(ctx, r.DB, headered, input.StateEventIDs)
if err != nil { if err != nil {
logrus.WithFields(logrus.Fields{ logrus.WithFields(logrus.Fields{
"event_id": event.EventID(), "event_id": event.EventID(),
@ -64,6 +65,7 @@ func (r *Inputer) processRoomEvent(
"room": event.RoomID(), "room": event.RoomID(),
}).WithError(err).Info("Error authing soft-failed event") }).WithError(err).Info("Error authing soft-failed event")
} }
}
// If we don't have a transaction ID then get one. // If we don't have a transaction ID then get one.
if input.TransactionID != nil { if input.TransactionID != nil {
@ -100,6 +102,7 @@ func (r *Inputer) processRoomEvent(
"event_id": event.EventID(), "event_id": event.EventID(),
"type": event.Type(), "type": event.Type(),
"room": event.RoomID(), "room": event.RoomID(),
"sender": event.Sender(),
}).Debug("Stored outlier") }).Debug("Stored outlier")
return event.EventID(), nil return event.EventID(), nil
} }
@ -128,6 +131,7 @@ func (r *Inputer) processRoomEvent(
"type": event.Type(), "type": event.Type(),
"room": event.RoomID(), "room": event.RoomID(),
"soft_fail": softfail, "soft_fail": softfail,
"sender": event.Sender(),
}).Debug("Stored rejected event") }).Debug("Stored rejected event")
return event.EventID(), rejectionErr return event.EventID(), rejectionErr
} }

View file

@ -53,6 +53,3 @@ Outbound federation requests missing prev_events and then asks for /state_ids an
# We don't implement lazy membership loading yet. # We don't implement lazy membership loading yet.
The only membership state included in a gapped incremental sync is for senders in the timeline The only membership state included in a gapped incremental sync is for senders in the timeline
# flakey since implementing rejected events
Inbound federation correctly soft fails events

View file

@ -473,3 +473,5 @@ Local users can peek by room alias
Peeked rooms only turn up in the sync for the device who peeked them Peeked rooms only turn up in the sync for the device who peeked them
Room state at a rejected message event is the same as its predecessor Room state at a rejected message event is the same as its predecessor
Room state at a rejected state event is the same as its predecessor Room state at a rejected state event is the same as its predecessor
Inbound federation correctly soft fails events
Inbound federation accepts a second soft-failed event