2020-10-19 13:25:42 +00:00
|
|
|
package acl_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRecordJSON(t *testing.T) {
|
|
|
|
exp := generateRecord(false)
|
|
|
|
|
|
|
|
t.Run("non empty", func(t *testing.T) {
|
2020-10-28 12:10:54 +00:00
|
|
|
data, err := acl.RecordToJSON(exp)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 13:25:42 +00:00
|
|
|
|
2020-10-28 12:10:54 +00:00
|
|
|
got, err := acl.RecordFromJSON(data)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 13:25:42 +00:00
|
|
|
|
|
|
|
require.Equal(t, exp, got)
|
|
|
|
})
|
2020-10-28 12:10:54 +00:00
|
|
|
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
_, err := acl.RecordToJSON(nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
_, err = acl.RecordFromJSON(nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
2020-10-19 13:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEACLTableJSON(t *testing.T) {
|
|
|
|
exp := generateEACL()
|
|
|
|
|
|
|
|
t.Run("non empty", func(t *testing.T) {
|
2020-10-28 12:10:54 +00:00
|
|
|
data, err := acl.TableToJSON(exp)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 13:25:42 +00:00
|
|
|
|
2020-10-28 12:10:54 +00:00
|
|
|
got, err := acl.TableFromJSON(data)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 13:25:42 +00:00
|
|
|
|
|
|
|
require.Equal(t, exp, got)
|
|
|
|
})
|
2020-10-28 12:10:54 +00:00
|
|
|
|
|
|
|
t.Run("empty", func(t *testing.T) {
|
|
|
|
_, err := acl.TableToJSON(nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
_, err = acl.TableFromJSON(nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
2020-10-19 13:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBearerTokenJSON(t *testing.T) {
|
|
|
|
exp := generateBearerToken("token")
|
|
|
|
|
|
|
|
t.Run("non empty", func(t *testing.T) {
|
2020-10-28 12:10:54 +00:00
|
|
|
data, err := acl.BearerTokenToJSON(exp)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 13:25:42 +00:00
|
|
|
|
2020-10-28 12:10:54 +00:00
|
|
|
got, err := acl.BearerTokenFromJSON(data)
|
|
|
|
require.NoError(t, err)
|
2020-10-19 13:25:42 +00:00
|
|
|
|
|
|
|
require.Equal(t, exp, got)
|
|
|
|
})
|
|
|
|
}
|
2020-11-13 11:31:53 +00:00
|
|
|
|
|
|
|
func TestFilterJSON(t *testing.T) {
|
|
|
|
f := generateFilter(acl.HeaderTypeObject, "key", "value")
|
|
|
|
|
|
|
|
data, err := f.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
f2 := new(acl.HeaderFilter)
|
|
|
|
require.NoError(t, f2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, f, f2)
|
|
|
|
}
|
2020-11-13 11:40:57 +00:00
|
|
|
|
|
|
|
func TestTargetJSON(t *testing.T) {
|
|
|
|
tar := generateTarget(acl.RoleSystem, 3)
|
|
|
|
|
|
|
|
data, err := tar.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tar2 := new(acl.Target)
|
|
|
|
require.NoError(t, tar2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, tar, tar2)
|
|
|
|
}
|