Merge PR #4220: Empty mnemonic should return error during key recovery

This commit is contained in:
Frank Yang 2019-04-30 00:49:35 +08:00 committed by Alexander Bezobchuk
parent 6bb94ae814
commit 5344e8d768
4 changed files with 12 additions and 13 deletions

View File

@ -0,0 +1 @@
#4219 Return an error when an empty mnemonic is provided during key recovery.

View File

@ -33,11 +33,6 @@ const (
flagNoSort = "nosort"
)
const (
maxValidAccountValue = int(0x80000000 - 1)
maxValidIndexalue = int(0x80000000 - 1)
)
func addKeyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "add <name>",
@ -200,6 +195,10 @@ func runAddCmd(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
if !bip39.IsMnemonicValid(mnemonic) {
return errors.New("invalid mnemonic")
}
}
if len(mnemonic) == 0 {
@ -215,11 +214,6 @@ func runAddCmd(_ *cobra.Command, args []string) error {
}
}
if !bip39.IsMnemonicValid(mnemonic) {
fmt.Fprintf(os.Stderr, "Error: Mnemonic is not valid.\n")
return nil
}
// override bip39 passphrase
if interactive {
bip39Passphrase, err = client.GetString(

View File

@ -51,7 +51,11 @@ func TestGaiaCLIKeysAddRecover(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
exitSuccess, _, _ := f.KeysAddRecover("empty-mnemonic", "")
require.False(t, exitSuccess)
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
require.True(t, exitSuccess)
require.Equal(t, "cosmos1qcfdf69js922qrdr4yaww3ax7gjml6pdds46f4", f.KeyAddress("test-recover").String())
}

View File

@ -264,9 +264,9 @@ func (f *Fixtures) KeysAdd(name string, flags ...string) {
}
// KeysAddRecover prepares gaiacli keys add --recover
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) {
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string) {
cmd := fmt.Sprintf("%s keys add --home=%s --recover %s", f.GaiacliBinary, f.GaiacliHome, name)
executeWriteCheckErr(f.T, addFlags(cmd, flags), client.DefaultKeyPass, mnemonic)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass, mnemonic)
}
// KeysAddRecoverHDPath prepares gaiacli keys add --recover --account --index