pass command accepts now optionally the password from command line, instead of stdin.

This commit is contained in:
Oleksandr Kozachuk
2023-01-07 12:06:41 +01:00
parent 44c6f371a8
commit 4ee1d38be7
4 changed files with 34 additions and 7 deletions
+20 -1
View File
@@ -122,7 +122,7 @@ impl<'a> LKEval<'a> {
quit = self.cmd_source(&out, script);
}
Command::Dump(script) => self.cmd_dump(&out, script),
Command::Pass(name) => self.cmd_pass(&out, &name),
Command::Pass(name, pass) => self.cmd_pass(&out, &name, &pass),
Command::UnPass(name) => match self.state.lock().borrow_mut().secrets.remove(name) {
Some(_) => out.o(format!("Removed saved password for {}", name)),
None => out.e(format!("error: saved password for {} not found", name)),
@@ -412,4 +412,23 @@ mod tests {
)
);
}
#[test]
fn exec_cmd_pass() {
let lk = Arc::new(ReentrantMutex::new(RefCell::new(LK::new())));
let t1 = Password::from_password(Password::new(
None,
"t1".to_string(),
None,
Mode::Regular,
99,
Date::new(2022, 12, 30),
None,
));
LKEval::news(Command::Add(t1.clone()), lk.clone()).eval();
({ let mut e = LKEval::news(Command::Pass("t1".to_string(), None), lk.clone()); e.read_password = |_| { Ok("test pwd1".to_string()) }; e }).eval();
assert_eq!(lk.lock().borrow().secrets[&"t1".to_string()], "test pwd1");
LKEval::news(Command::Pass("t1".to_string(), Some("other pw".to_string())), lk.clone()).eval();
assert_eq!(lk.lock().borrow().secrets[&"t1".to_string()], "other pw");
}
}