mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Assert that the new room has a predecessor set
This commit is contained in:
parent
2b4f3a8bc2
commit
55ed63ef97
@ -110,7 +110,7 @@ func MatchRoomRequiredState(events []Event) m.RoomMatcher {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("required state want event %+v but it does not exist", want)
|
||||
return fmt.Errorf("required state want event %+v but did not find exact match", want)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -2,11 +2,13 @@ package syncv3_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/sync-v3/sync3"
|
||||
"github.com/matrix-org/sync-v3/testutils/m"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestTombstonesFlag(t *testing.T) {
|
||||
@ -22,6 +24,9 @@ func TestTombstonesFlag(t *testing.T) {
|
||||
Filters: &sync3.RequestFilters{
|
||||
IsTombstoned: &boolFalse,
|
||||
},
|
||||
RoomSubscription: sync3.RoomSubscription{
|
||||
RequiredState: [][2]string{{"m.room.create", ""}},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -36,6 +41,7 @@ func TestTombstonesFlag(t *testing.T) {
|
||||
t.Fatalf("failed to decode response: %s", err)
|
||||
}
|
||||
newRoomID := body["replacement_room"].(string)
|
||||
t.Logf("old %s new %s", roomID, newRoomID)
|
||||
time.Sleep(100 * time.Millisecond) // let the proxy process it
|
||||
|
||||
res = client.SlidingSync(t, sync3.Request{
|
||||
@ -45,24 +51,47 @@ func TestTombstonesFlag(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}, WithPos(res.Pos))
|
||||
var tombstoneEventID string
|
||||
// count is 1 as we are auto-joined to the upgraded room
|
||||
m.MatchResponse(t, res, m.MatchList(0, m.MatchV3Count(1), m.MatchV3Ops(
|
||||
m.MatchV3DeleteOp(1),
|
||||
m.MatchV3InsertOp(0, newRoomID), // insert new room
|
||||
m.MatchV3DeleteOp(1), // remove old room
|
||||
)), m.MatchRoomSubscriptionsStrict(map[string][]m.RoomMatcher{
|
||||
)), m.MatchRoomSubscriptions(map[string][]m.RoomMatcher{
|
||||
roomID: {
|
||||
m.MatchRoomInitial(false),
|
||||
MatchRoomTimeline([]Event{
|
||||
{
|
||||
Type: "m.room.tombstone",
|
||||
StateKey: ptr(""),
|
||||
},
|
||||
}),
|
||||
func(r sync3.Room) error {
|
||||
// last timeline event should be the tombstone
|
||||
lastEvent := r.Timeline[len(r.Timeline)-1]
|
||||
ev := gjson.ParseBytes(lastEvent)
|
||||
if ev.Get("type").Str != "m.room.tombstone" || !ev.Get("state_key").Exists() || ev.Get("state_key").Str != "" {
|
||||
return fmt.Errorf("last event wasn't a tombstone event: %v", string(lastEvent))
|
||||
}
|
||||
tombstoneEventID = ev.Get("event_id").Str
|
||||
return nil
|
||||
},
|
||||
},
|
||||
// 2nd MatchRoomSubscriptions so we can pull out the event ID from the old room
|
||||
}), m.MatchRoomSubscriptions(map[string][]m.RoomMatcher{
|
||||
newRoomID: {
|
||||
m.MatchRoomInitial(true),
|
||||
m.MatchJoinCount(1),
|
||||
func(r sync3.Room) error { // nest it so the previous matcher has time to set tombstoneEventID
|
||||
return MatchRoomRequiredState([]Event{
|
||||
{
|
||||
Type: "m.room.create",
|
||||
StateKey: ptr(""),
|
||||
Content: map[string]interface{}{
|
||||
"room_version": "9",
|
||||
"predecessor": map[string]interface{}{
|
||||
"room_id": roomID,
|
||||
"event_id": tombstoneEventID,
|
||||
},
|
||||
"creator": client.UserID,
|
||||
},
|
||||
},
|
||||
})(r)
|
||||
},
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user