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

acl: do not add records if limits is 1-1

This commit is contained in:
Sergey Cherepanov 2024-03-18 14:58:22 +01:00
parent 045ab61962
commit 214c63d6c0
No known key found for this signature in database
GPG key ID: 87F8EDE8FBDF637C
2 changed files with 13 additions and 2 deletions

View file

@ -83,12 +83,17 @@ func (as *aclService) get(ctx context.Context, spaceId string) (list.AclList, er
}
func (as *aclService) AddRecord(ctx context.Context, spaceId string, rec *consensusproto.RawRecord, limits Limits) (result *consensusproto.RawRecordWithId, err error) {
if limits.ReadMembers <= 1 && limits.WriteMembers <= 1 {
return nil, ErrLimitExceed
}
acl, err := as.get(ctx, spaceId)
if err != nil {
return nil, err
}
acl.RLock()
defer acl.RUnlock()
err = acl.ValidateRawRecord(rec, func(state *list.AclState) error {
var readers, writers int
for _, acc := range state.CurrentAccounts() {

View file

@ -82,7 +82,13 @@ func TestAclService_AddRecord(t *testing.T) {
assert.EqualError(t, err, testErr.Error())
})
t.Run("limit exceed", func(t *testing.T) {
// TODO:
fx := newFixture(t)
defer fx.finish(t)
_, err := fx.AddRecord(ctx, spaceId, inv.InviteRec, Limits{
ReadMembers: 1,
WriteMembers: 1,
})
assert.ErrorIs(t, err, ErrLimitExceed)
})
}
@ -136,7 +142,7 @@ func TestAclService(t *testing.T) {
require.NoError(t, err)
assert.True(t, res.IsOwner())
})
t.Run("ownerPUbKey", func(t *testing.T) {
t.Run("ownerPubKey", func(t *testing.T) {
res, err := fx.OwnerPubKey(ctx, spaceId)
require.NoError(t, err)
assert.Equal(t, ownerKeys.SignKey.GetPublic().Account(), res.Account())