Fix pass Git config and lazy OTP commits
This commit is contained in:
@@ -832,16 +832,10 @@ fn execute_otp<B: SecretStoreBackend, P: CliPresentation, I: OtpInteraction, O:
|
||||
Ok(timestamp) => timestamp,
|
||||
Err(error) => return operation_error(stderr, error),
|
||||
};
|
||||
let mut committer =
|
||||
match automatic_committer(&repository, request.entry.trim_end_matches('/')) {
|
||||
Ok(committer) => committer,
|
||||
Err(error) => return operation_error(stderr, error),
|
||||
};
|
||||
let outcome =
|
||||
match service.code(&request.entry, timestamp, None, secrets, &mut committer) {
|
||||
Ok(outcome) => outcome,
|
||||
Err(error) => return operation_error(stderr, error),
|
||||
};
|
||||
let outcome = match service.code_automatic(&request.entry, timestamp, None, secrets) {
|
||||
Ok(outcome) => outcome,
|
||||
Err(error) => return operation_error(stderr, error),
|
||||
};
|
||||
if request.clipboard {
|
||||
match presentation.clipboard(
|
||||
outcome.code(),
|
||||
@@ -1488,6 +1482,7 @@ mod tests {
|
||||
error::Error,
|
||||
ffi::OsString,
|
||||
fs,
|
||||
io::Write as _,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
@@ -1502,7 +1497,7 @@ mod tests {
|
||||
},
|
||||
config::Config,
|
||||
crypto::KeyInfo,
|
||||
git::GitCredentialProvider as _,
|
||||
git::{GitCredentialProvider as _, GitIdentity, GitRepository},
|
||||
otp::OtpInput,
|
||||
presentation::{ClipboardTimeout, QrMatrix},
|
||||
repository::{EntryPath, Repository, SecretBytes},
|
||||
@@ -2097,12 +2092,28 @@ mod tests {
|
||||
let fixtures = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../crates/storage/tests/fixtures/compatibility");
|
||||
let temporary = tempfile::tempdir()?;
|
||||
let vault = temporary.path().join("vault");
|
||||
fs::create_dir_all(vault.join("otp"))?;
|
||||
for path in [".gpg-id", ".gpg-id.sig", "otp/totp.gpg"] {
|
||||
fs::copy(fixtures.join("stores/basic").join(path), vault.join(path))?;
|
||||
}
|
||||
let repository = Repository::open(&vault)?;
|
||||
let identity = GitIdentity::ironstorage();
|
||||
let git = GitRepository::init(&repository, identity.clone())?;
|
||||
let commits_before = git.log(None)?.len();
|
||||
drop(git);
|
||||
let git_config = vault.join(".git/config");
|
||||
let mut config_file = fs::OpenOptions::new().append(true).open(&git_config)?;
|
||||
config_file.write_all(&fs::read(fixtures.join("pass-git-config.ini"))?)?;
|
||||
drop(config_file);
|
||||
let config_before = fs::read(&git_config)?;
|
||||
let ciphertext_before = fs::read(vault.join("otp/totp.gpg"))?;
|
||||
let config_path = temporary.path().join("config.toml");
|
||||
fs::write(
|
||||
&config_path,
|
||||
format!(
|
||||
"vault = {:?}\ndefault_key = {:?}\nkey_material = {:?}\nclipboard_timeout_seconds = 1\n",
|
||||
fixtures.join("stores/basic"),
|
||||
vault,
|
||||
FINGERPRINT,
|
||||
fixtures.join("keys"),
|
||||
),
|
||||
@@ -2114,6 +2125,29 @@ mod tests {
|
||||
|
||||
let mut stdout = Vec::new();
|
||||
let mut stderr = Vec::new();
|
||||
assert_eq!(
|
||||
execute_secure_with_services(
|
||||
&config,
|
||||
&CommandRequest::Show(ShowRequest {
|
||||
entry: Some("otp/totp".to_owned()),
|
||||
presentation: Presentation::Terminal,
|
||||
}),
|
||||
&mut secrets,
|
||||
&mut presentation,
|
||||
&mut interaction,
|
||||
|| Ok(59),
|
||||
&mut stdout,
|
||||
&mut stderr,
|
||||
)
|
||||
.expect("memory output cannot fail"),
|
||||
EXIT_SUCCESS
|
||||
);
|
||||
assert!(
|
||||
stdout
|
||||
.windows(b"otpauth://totp".len())
|
||||
.any(|part| part == b"otpauth://totp")
|
||||
);
|
||||
stdout.clear();
|
||||
assert_eq!(
|
||||
execute_secure_with_services(
|
||||
&config,
|
||||
@@ -2136,6 +2170,10 @@ mod tests {
|
||||
assert!(code.iter().all(u8::is_ascii_digit));
|
||||
assert!(!stdout.windows(code.len()).any(|part| part == code));
|
||||
assert!(stderr.is_empty());
|
||||
assert_eq!(fs::read(vault.join("otp/totp.gpg"))?, ciphertext_before);
|
||||
assert_eq!(fs::read(&git_config)?, config_before);
|
||||
let git = GitRepository::open(&repository, identity)?;
|
||||
assert_eq!(git.log(None)?.len(), commits_before);
|
||||
|
||||
stdout.clear();
|
||||
let uri = fs::read(fixtures.join("expected/basic/otp/totp.txt"))?;
|
||||
|
||||
Reference in New Issue
Block a user