mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-15 10:03:09 -06:00
Add tests
This commit is contained in:
parent
2b2f88a7dd
commit
ec0ee642b7
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
|
|
@ -19,6 +20,7 @@ import (
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
|
|
@ -978,3 +980,52 @@ func TestRecentEvents(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FakeQuerier struct {
|
||||||
|
api.QuerySenderIDAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FakeQuerier) QueryUserIDForSender(ctx context.Context, roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||||
|
return spec.NewUserID(string(senderID), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRedaction(t *testing.T) {
|
||||||
|
alice := test.NewUser(t)
|
||||||
|
room := test.NewRoom(t, alice)
|
||||||
|
|
||||||
|
redactedEvent := room.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{"body": "hi"})
|
||||||
|
redactionEvent := room.CreateEvent(t, alice, spec.MRoomRedaction, map[string]string{"redacts": redactedEvent.EventID()})
|
||||||
|
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
|
||||||
|
db, close := MustCreateDatabase(t, dbType)
|
||||||
|
t.Cleanup(close)
|
||||||
|
MustWriteEvents(t, db, room.Events())
|
||||||
|
|
||||||
|
err := db.RedactEvent(context.Background(), redactedEvent.EventID(), redactionEvent, &FakeQuerier{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
evs, err := db.Events(context.Background(), []string{redactedEvent.EventID()})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(evs) != 1 {
|
||||||
|
t.Fatalf("expected 1 event, got %d", len(evs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// check a few fields which shouldn't be there in unsigned
|
||||||
|
authEvs := gjson.GetBytes(evs[0].Unsigned(), "redacted_because.auth_events")
|
||||||
|
if authEvs.Exists() {
|
||||||
|
t.Error("unexpected auth_events in redacted event")
|
||||||
|
}
|
||||||
|
prevEvs := gjson.GetBytes(evs[0].Unsigned(), "redacted_because.prev_events")
|
||||||
|
if prevEvs.Exists() {
|
||||||
|
t.Error("unexpected auth_events in redacted event")
|
||||||
|
}
|
||||||
|
depth := gjson.GetBytes(evs[0].Unsigned(), "redacted_because.depth")
|
||||||
|
if depth.Exists() {
|
||||||
|
t.Error("unexpected auth_events in redacted event")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue