Anton Nikiforov
483a67b170
All checks were successful
DCO action / DCO (pull_request) Successful in 2m13s
Build / Build Components (1.20) (pull_request) Successful in 3m38s
Vulncheck / Vulncheck (pull_request) Successful in 3m13s
Tests and linters / Staticcheck (pull_request) Successful in 6m15s
Build / Build Components (1.21) (pull_request) Successful in 7m11s
Tests and linters / Lint (pull_request) Successful in 9m35s
Tests and linters / Tests (1.21) (pull_request) Successful in 13m56s
Tests and linters / Tests (1.20) (pull_request) Successful in 14m14s
Tests and linters / Tests with -race (pull_request) Successful in 6m2s
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
173 lines
3.5 KiB
Go
173 lines
3.5 KiB
Go
package morph
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/ape"
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
"github.com/spf13/viper"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFrostfsIDConfig(t *testing.T) {
|
|
pks := make([]*keys.PrivateKey, 4)
|
|
for i := range pks {
|
|
pk, err := keys.NewPrivateKey()
|
|
require.NoError(t, err)
|
|
pks[i] = pk
|
|
}
|
|
|
|
fmts := []string{
|
|
pks[0].GetScriptHash().StringLE(),
|
|
address.Uint160ToString(pks[1].GetScriptHash()),
|
|
hex.EncodeToString(pks[2].PublicKey().UncompressedBytes()),
|
|
hex.EncodeToString(pks[3].PublicKey().Bytes()),
|
|
}
|
|
|
|
for i := range fmts {
|
|
v := viper.New()
|
|
v.Set("frostfsid.admin", fmts[i])
|
|
|
|
actual, found, err := getFrostfsIDAdmin(v)
|
|
require.NoError(t, err)
|
|
require.True(t, found)
|
|
require.Equal(t, pks[i].GetScriptHash(), actual)
|
|
}
|
|
|
|
t.Run("bad key", func(t *testing.T) {
|
|
v := viper.New()
|
|
v.Set("frostfsid.admin", "abc")
|
|
|
|
_, found, err := getFrostfsIDAdmin(v)
|
|
require.Error(t, err)
|
|
require.True(t, found)
|
|
})
|
|
t.Run("missing key", func(t *testing.T) {
|
|
v := viper.New()
|
|
|
|
_, found, err := getFrostfsIDAdmin(v)
|
|
require.NoError(t, err)
|
|
require.False(t, found)
|
|
})
|
|
}
|
|
|
|
func TestNamespaceRegexp(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
namespace string
|
|
matched bool
|
|
}{
|
|
{
|
|
name: "root empty ns",
|
|
namespace: "",
|
|
matched: true,
|
|
},
|
|
{
|
|
name: "simple valid ns",
|
|
namespace: "my-namespace-123",
|
|
matched: true,
|
|
},
|
|
{
|
|
name: "root placeholder",
|
|
namespace: "<root>",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "too long",
|
|
namespace: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "start with hyphen",
|
|
namespace: "-ns",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "end with hyphen",
|
|
namespace: "ns-",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "with spaces",
|
|
namespace: "ns ns",
|
|
matched: false,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.Equal(t, tc.matched, ape.NamespaceNameRegexp.MatchString(tc.namespace))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSubjectNameRegexp(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
subject string
|
|
matched bool
|
|
}{
|
|
{
|
|
name: "empty",
|
|
subject: "",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "invalid",
|
|
subject: "invalid{name}",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "too long",
|
|
subject: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "valid",
|
|
subject: "valid_name.012345@6789",
|
|
matched: true,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.Equal(t, tc.matched, ape.SubjectNameRegexp.MatchString(tc.subject))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSubjectGroupRegexp(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
subject string
|
|
matched bool
|
|
}{
|
|
{
|
|
name: "empty",
|
|
subject: "",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "invalid",
|
|
subject: "invalid{name}",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "too long",
|
|
subject: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
|
matched: false,
|
|
},
|
|
{
|
|
name: "long",
|
|
subject: "abcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyzabcdefghijklmnopkrstuvwxyz",
|
|
matched: true,
|
|
},
|
|
{
|
|
name: "valid",
|
|
subject: "valid_name.012345@6789",
|
|
matched: true,
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.Equal(t, tc.matched, ape.GroupNameRegexp.MatchString(tc.subject))
|
|
})
|
|
}
|
|
}
|