Adds RELICARIO_TEST_ITEM_SECRET env hatch for rpassword calls in cmd_add / cmd_edit so piped-stdin tests can exercise the password prompt paths without a TTY. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
2.2 KiB
Rust
60 lines
2.2 KiB
Rust
mod common;
|
|
|
|
use common::TestVault;
|
|
|
|
#[test]
|
|
fn edit_password_captures_history() {
|
|
let v = TestVault::init();
|
|
v.run(&["add", "login", "--title", "bank",
|
|
"--username", "u", "--password", "first-pw"]);
|
|
|
|
// edit: accept defaults on title/group/tags/username/url, then change pw.
|
|
let out = run_edit_with_pw_change(&v, "bank", "second-pw");
|
|
assert!(out.status.success(), "edit failed:\nstdout: {}\nstderr: {}",
|
|
String::from_utf8_lossy(&out.stdout),
|
|
String::from_utf8_lossy(&out.stderr));
|
|
|
|
// Verify the edit commit exists in git log.
|
|
let log = std::process::Command::new("git")
|
|
.current_dir(v.path()).args(["log", "--oneline"])
|
|
.output().unwrap();
|
|
let log_str = String::from_utf8(log.stdout).unwrap();
|
|
assert!(log_str.contains("edit: bank"), "missing edit commit: {log_str}");
|
|
|
|
// And the item file has been re-written (there's a single items/<id>.enc).
|
|
let items_dir = v.path().join("items");
|
|
let entries: Vec<_> = std::fs::read_dir(&items_dir).unwrap()
|
|
.map(|e| e.unwrap().path()).collect();
|
|
assert_eq!(entries.len(), 1);
|
|
}
|
|
|
|
/// Drives the interactive `edit` flow end-to-end:
|
|
/// 1. passphrase via env var.
|
|
/// 2. blank lines for title, group, tags, username, url.
|
|
/// 3. "y" for "Change password?"
|
|
/// 4. new password via RELICARIO_TEST_ITEM_SECRET env var.
|
|
fn run_edit_with_pw_change(v: &TestVault, query: &str, new_pw: &str) -> std::process::Output {
|
|
use assert_cmd::cargo::CommandCargoExt;
|
|
use std::io::Write;
|
|
use std::process::{Command, Stdio};
|
|
|
|
let mut cmd = Command::cargo_bin("relicario").unwrap();
|
|
cmd.current_dir(v.path())
|
|
.env("RELICARIO_IMAGE", &v.reference_image)
|
|
.env("RELICARIO_TEST_PASSPHRASE", &v.passphrase)
|
|
.env("RELICARIO_TEST_ITEM_SECRET", new_pw)
|
|
.args(["edit", query])
|
|
.stdin(Stdio::piped())
|
|
.stdout(Stdio::piped())
|
|
.stderr(Stdio::piped());
|
|
let mut child = cmd.spawn().unwrap();
|
|
{
|
|
let stdin = child.stdin.as_mut().unwrap();
|
|
// title, group, tags, username, url (keep defaults), then yes-to-change-pw.
|
|
for line in ["", "", "", "", "", "y"] {
|
|
writeln!(stdin, "{line}").unwrap();
|
|
}
|
|
}
|
|
child.wait_with_output().unwrap()
|
|
}
|