Skip to content

Commit

Permalink
Merge PR cosmos#4220: Empty mnemonic should return error during key r…
Browse files Browse the repository at this point in the history
…ecovery
  • Loading branch information
Frank Yang authored and alexanderbez committed Apr 29, 2019
1 parent 6bb94ae commit 5344e8d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions .pending/bugfixes/gaiacli/4219-Empty-mnemonic-
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4219 Return an error when an empty mnemonic is provided during key recovery.
14 changes: 4 additions & 10 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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>",
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5344e8d

Please sign in to comment.