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:
parent
045ab61962
commit
214c63d6c0
2 changed files with 13 additions and 2 deletions
|
@ -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() {
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue