Ensure API create_wallet returns failure when provided with invalid mnemonic seeds (#319)

* Ensure  returns failure with invalid mnemonic seeds, add tests

* test fixes resulting from change
This commit is contained in:
Yeastplume
2020-01-31 12:00:49 +00:00
committed by GitHub
parent e71d79dc38
commit ed5b9008c0
6 changed files with 51 additions and 3 deletions
+11 -1
View File
@@ -183,7 +183,16 @@ where
return Err(ErrorKind::WalletSeedExists(msg))?;
}
}
let _ = WalletSeed::init_file(&data_dir_name, mnemonic_length, mnemonic.clone(), password);
WalletSeed::init_file(
&data_dir_name,
mnemonic_length,
mnemonic.clone(),
password,
test_mode,
)
.context(ErrorKind::Lifecycle(
"Error creating wallet seed (is mnemonic valid?)".into(),
))?;
info!("Wallet seed file created");
let mut wallet: LMDBBackend<'a, C, K> =
match LMDBBackend::new(&data_dir_name, self.node_client.clone()) {
@@ -327,6 +336,7 @@ where
0,
Some(ZeroingString::from(orig_mnemonic)),
new.clone(),
false,
);
info!("Wallet seed file created");
+3 -1
View File
@@ -150,6 +150,7 @@ impl WalletSeed {
seed_length: usize,
recovery_phrase: Option<util::ZeroingString>,
password: util::ZeroingString,
test_mode: bool,
) -> Result<WalletSeed, Error> {
// create directory if it doesn't exist
fs::create_dir_all(data_file_dir).context(ErrorKind::IO)?;
@@ -158,8 +159,9 @@ impl WalletSeed {
warn!("Generating wallet seed file at: {}", seed_file_path);
let exists = WalletSeed::seed_file_exists(data_file_dir)?;
if exists {
if exists && !test_mode {
let msg = format!("Wallet seed already exists at: {}", data_file_dir);
error!("{}", msg);
return Err(ErrorKind::WalletSeedExists(msg))?;
}