Merge pull request #3544 from nspcc-dev/fix-permission-extension

This commit is contained in:
Roman Khimov 2024-08-05 16:17:19 +03:00 committed by GitHub
commit 39e0d60221
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View file

@ -64,8 +64,12 @@ func (c *WildPermissionDescs) Restrict() {
// Add adds v to the container.
func (c *WildStrings) Add(v string) { c.Value = append(c.Value, v) }
// Add adds v to the container.
func (c *WildPermissionDescs) Add(v PermissionDesc) { c.Value = append(c.Value, v) }
// Add adds v to the container and converts container to non-wildcard (if it's still
// wildcard).
func (c *WildPermissionDescs) Add(v PermissionDesc) {
c.Value = append(c.Value, v)
c.Wildcard = false
}
// MarshalJSON implements the json.Marshaler interface.
func (c WildStrings) MarshalJSON() ([]byte, error) {

View file

@ -81,6 +81,17 @@ func TestContainer_Add(t *testing.T) {
require.False(t, c.Contains(PermissionDesc{Type: PermissionHash, Value: random.Uint160()}))
require.False(t, c.Contains(PermissionDesc{Type: PermissionGroup, Value: pkRand.PublicKey()}))
})
t.Run("from wildcard", func(t *testing.T) {
c := &WildPermissionDescs{
Value: nil,
Wildcard: true,
}
require.True(t, c.IsWildcard())
c.Add(PermissionDesc{Type: PermissionHash, Value: random.Uint160()})
require.False(t, c.IsWildcard())
})
}
func TestContainer_MarshalJSON(t *testing.T) {