1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Fix incorrect root validation

This commit is contained in:
mcrakhman 2024-11-28 21:56:56 +01:00
parent 862827aeab
commit c899e45b29
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
3 changed files with 48 additions and 0 deletions

View file

@ -338,6 +338,42 @@ func TestObjectTree(t *testing.T) {
require.NoError(t, err)
})
t.Run("reject root referring to unknown acl", func(t *testing.T) {
exec := list.NewAclExecutor("spaceId")
type cmdErr struct {
cmd string
err error
}
cmds := []cmdErr{
{"a.init::a", nil},
}
for _, cmd := range cmds {
err := exec.Execute(cmd.cmd)
require.Equal(t, cmd.err, err, cmd)
}
aAccount := exec.ActualAccounts()["a"]
recs, err := aAccount.Acl.RecordsAfter(ctx, "")
require.NoError(t, err)
firstStorage, err := liststorage.NewInMemoryAclListStorage(recs[0].Id, recs)
require.NoError(t, err)
firstAcl, err := list.BuildAclListWithIdentity(aAccount.Keys, firstStorage, list.NoOpAcceptorVerifier{})
require.NoError(t, err)
err = exec.Execute("a.invite::invId")
require.NoError(t, err)
root, err := CreateObjectTreeRoot(ObjectTreeCreatePayload{
PrivKey: aAccount.Keys.SignKey,
ChangeType: "changeType",
ChangePayload: nil,
SpaceId: "spaceId",
IsEncrypted: true,
}, aAccount.Acl)
require.NoError(t, err)
store, err := treestorage.NewInMemoryTreeStorage(root, []string{root.Id}, []*treechangeproto.RawTreeChangeWithId{root})
require.NoError(t, err)
_, err = BuildKeyFilterableObjectTree(store, firstAcl)
require.Equal(t, list.ErrNoSuchRecord, err)
})
t.Run("filter changes when no aclHeadId", func(t *testing.T) {
exec := list.NewAclExecutor("spaceId")
type cmdErr struct {