[#684] neofs-adm: add size validation to generate-alphabet

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-07-17 15:51:43 +03:00 committed by Alex Vanin
parent 459fe40758
commit be6b8ca179
2 changed files with 11 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package morph package morph
import ( import (
"errors"
"fmt" "fmt"
"path" "path"
@ -19,6 +20,9 @@ func generateAlphabetCreds(cmd *cobra.Command, args []string) error {
if err != nil { if err != nil {
return err return err
} }
if size == 0 {
return errors.New("size must be > 0")
}
walletDir := viper.GetString(alphabetWalletsFlag) walletDir := viper.GetString(alphabetWalletsFlag)
pwds, err := initializeWallets(walletDir, int(size)) pwds, err := initializeWallets(walletDir, int(size))

View file

@ -27,6 +27,13 @@ func TestGenerateAlphabet(t *testing.T) {
cmd := generateAlphabetCmd cmd := generateAlphabetCmd
v := viper.GetViper() v := viper.GetViper()
t.Run("zero size", func(t *testing.T) {
buf.Reset()
v.Set(alphabetWalletsFlag, walletDir)
require.NoError(t, cmd.Flags().Set(alphabetSizeFlag, "0"))
buf.WriteString("pass\r")
require.Error(t, generateAlphabetCreds(cmd, nil))
})
t.Run("no password provided", func(t *testing.T) { t.Run("no password provided", func(t *testing.T) {
buf.Reset() buf.Reset()
v.Set(alphabetWalletsFlag, walletDir) v.Set(alphabetWalletsFlag, walletDir)