preserve vault meta when changing pwd (#4650)

This commit is contained in:
Svyatoslav Nikolsky 2017-02-23 21:01:12 +03:00 committed by Gav Wood
parent 496a6dcfa0
commit 88cdc92ed4
2 changed files with 21 additions and 0 deletions

View File

@ -135,6 +135,10 @@ impl VaultKeyDirectory for VaultDiskDirectory {
let temp_vault = VaultDiskDirectory::create_temp_vault(self, new_key.clone()).map_err(|err| SetKeyError::NonFatalOld(err))?;
let mut source_path = temp_vault.path().expect("temp_vault is instance of DiskDirectory; DiskDirectory always returns path; qed").clone();
let mut target_path = self.path().expect("self is instance of DiskDirectory; DiskDirectory always returns path; qed").clone();
// preserve meta
temp_vault.set_meta(&self.meta()).map_err(SetKeyError::NonFatalOld)?;
// jump to next fs level
source_path.push("next");
target_path.push("next");

View File

@ -1015,4 +1015,21 @@ mod tests {
// and we can sign with the derived contract
assert!(store.sign(&derived, "test", &Default::default()).is_ok(), "Second password should work for second store.");
}
#[test]
fn should_save_meta_when_setting_before_password() {
// given
let mut dir = RootDiskDirectoryGuard::new();
let store = EthStore::open(dir.key_dir.take().unwrap()).unwrap();
let name = "vault"; let password = "password1";
let new_password = "password2";
// when
store.create_vault(name, password).unwrap();
store.set_vault_meta(name, "OldMeta").unwrap();
store.change_vault_password(name, new_password).unwrap();
// then
assert_eq!(store.get_vault_meta(name).unwrap(), "OldMeta".to_owned());
}
}