diff --git a/Cargo.lock b/Cargo.lock index 350fbb9..7c04d21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,7 +103,16 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" dependencies = [ - "term", + "term 0.7.0", +] + +[[package]] +name = "ascii-canvas" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1e3e699d84ab1b0911a1010c5c106aa34ae89aeac103be5ce0c3859db1e891" +dependencies = [ + "term 1.0.1", ] [[package]] @@ -188,7 +197,16 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" dependencies = [ - "bit-vec", + "bit-vec 0.6.3", +] + +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec 0.8.0", ] [[package]] @@ -197,6 +215,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + [[package]] name = "bitflags" version = "1.3.2" @@ -375,9 +399,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.8" +version = "1.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0cf6e91fde44c773c6ee7ec6bba798504641a8bc2eb7e37a04ffbf4dfaa55a" +checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" dependencies = [ "jobserver", "libc", @@ -1806,6 +1830,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "http" version = "1.2.0" @@ -2144,6 +2177,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.14" @@ -2186,27 +2228,57 @@ dependencies = [ "serde", ] +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + [[package]] name = "lalrpop" version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55cb077ad656299f160924eb2912aa147d7339ea7d69e1b5517326fdcec3c1ca" dependencies = [ - "ascii-canvas", - "bit-set", + "ascii-canvas 3.0.0", + "bit-set 0.5.3", "ena", "itertools 0.11.0", - "lalrpop-util", + "lalrpop-util 0.20.2", "petgraph", "regex", "regex-syntax", "string_cache", - "term", + "term 0.7.0", "tiny-keccak", "unicode-xid", "walkdir", ] +[[package]] +name = "lalrpop" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06093b57658c723a21da679530e061a8c25340fa5a6f98e313b542268c7e2a1f" +dependencies = [ + "ascii-canvas 4.0.0", + "bit-set 0.8.0", + "ena", + "itertools 0.13.0", + "lalrpop-util 0.22.0", + "petgraph", + "regex", + "regex-syntax", + "sha3", + "string_cache", + "term 1.0.1", + "unicode-xid", + "walkdir", +] + [[package]] name = "lalrpop-util" version = "0.20.2" @@ -2216,6 +2288,16 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "lalrpop-util" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feee752d43abd0f4807a921958ab4131f692a44d4d599733d4419c5d586176ce" +dependencies = [ + "regex-automata", + "rustversion", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -2374,9 +2456,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.24" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6ea2a48c204030ee31a7d7fc72c93294c92fe87ecb1789881c9543516e1a0d" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "malloc_buf" @@ -3468,15 +3550,15 @@ checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" [[package]] name = "sequoia-gpg-agent" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4db5fdd92efb296d42b194e2114f21ba737d5d2905b5e8063a8207eb953685" +checksum = "cc2511f47e9d5fbf7f509a73e13227e3f8ccc7ba8115e8c10e4a353e7fff1bb9" dependencies = [ "anyhow", "chrono", "futures", - "lalrpop", - "lalrpop-util", + "lalrpop 0.22.0", + "lalrpop-util 0.22.0", "libc", "sequoia-ipc", "sequoia-openpgp", @@ -3498,8 +3580,8 @@ dependencies = [ "ctor", "dirs", "fs2", - "lalrpop", - "lalrpop-util", + "lalrpop 0.20.2", + "lalrpop-util 0.20.2", "lazy_static", "libc", "memsec", @@ -3528,8 +3610,8 @@ dependencies = [ "flate2", "getrandom", "idna", - "lalrpop", - "lalrpop-util", + "lalrpop 0.20.2", + "lalrpop-util 0.20.2", "lazy_static", "libc", "memsec", @@ -3627,6 +3709,16 @@ dependencies = [ "digest", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "shlex" version = "1.3.0" @@ -3863,14 +3955,24 @@ dependencies = [ "winapi", ] +[[package]] +name = "term" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3bb6001afcea98122260987f8b7b5da969ecad46dbf0b5453702f776b491a41" +dependencies = [ + "home", + "windows-sys 0.52.0", +] + [[package]] name = "terminal_size" -version = "0.3.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +checksum = "5352447f921fda68cf61b4101566c0bdb5104eff6804d0678e5227580ab6a4e9" dependencies = [ "rustix", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 44e748c..b801282 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,32 +9,32 @@ license = "GPL-3.0-only" edition = '2021' [dependencies] -arboard = "3.4.0" -glob = "0.3.1" -gpgme = "0.11.0" +arboard = "3" +glob = "0.3" +gpgme = "0.11" chrono = { version = "0.4", default-features = false, features = ["clock"] } -git2 = "0.20.0" -rand = "0.8.5" -whoami = "1.4.1" -toml = "0.8.10" +git2 = "0.20" +rand = "0.8" +whoami = "1" +toml = "0.8" reqwest = { version = "0.12", features = ["blocking"] } -hex = "0.4.3" -totp-rs = { version = "5.5.1", features = ["otpauth"] } -sequoia-openpgp = "1.21.0" -anyhow = "1.0.80" -sequoia-gpg-agent = "0.4.0" -zeroize = { version = "1.8.0", features = ["zeroize_derive", "alloc"] } +hex = "0.4" +totp-rs = { version = "5", features = ["otpauth"] } +sequoia-openpgp = "1" +anyhow = "1" +sequoia-gpg-agent = "0.5" +zeroize = { version = "1", features = ["zeroize_derive", "alloc"] } [dependencies.config] -version = "0.15.4" +version = "0.15" default-features = false features = ["toml"] [dev-dependencies] -tempfile = "3.12.0" -flate2 = "1.0.28" -tar = "0.4.40" -criterion = "0.5.1" +tempfile = "3" +flate2 = "1" +tar = "0.4" +criterion = "0.5" [workspace] diff --git a/cursive/Cargo.toml b/cursive/Cargo.toml index acedb7c..fba5205 100644 --- a/cursive/Cargo.toml +++ b/cursive/Cargo.toml @@ -11,19 +11,19 @@ edition = '2021' build = "build.rs" [dependencies] -cursive = { version = "0.21.0", default-features = false, features = ["toml", "crossterm-backend"]} -arboard = { version = "3.3.0", features = ["wayland-data-control"]} +cursive = { version = "0.21", default-features = false, features = ["toml", "crossterm-backend"]} +arboard = { version = "3", features = ["wayland-data-control"]} ripasso = { path = "../", version = "0.7.0-alpha" } -locale_config = "0.3.0" -unic-langid = "0.9.4" -gettext = "0.4.0" -lazy_static = "1.4.0" -terminal_size = "0.3.0" -hex = "0.4.3" -zeroize = { version = "1.7.0", features = ["zeroize_derive", "alloc"] } +locale_config = "0.3" +unic-langid = "0.9" +gettext = "0.4" +lazy_static = "1" +terminal_size = "0.4" +hex = "0.4" +zeroize = { version = "1", features = ["zeroize_derive", "alloc"] } [dependencies.config] -version = "0.15.5" +version = "0.15" default-features = false features = ["toml"] @@ -32,5 +32,5 @@ tempfile = "3.10.1" chrono = { version = "0.4", default-features = false, features = ["clock"] } [build-dependencies] -glob = "0.3.1" -man = "0.3.0" +glob = "0.3" +man = "0.3" diff --git a/cursive/src/helpers.rs b/cursive/src/helpers.rs index 76f3fc1..1137863 100644 --- a/cursive/src/helpers.rs +++ b/cursive/src/helpers.rs @@ -24,6 +24,7 @@ use cursive::{ }; use lazy_static::lazy_static; use pass::Result; +use ripasso::pass::Recipient; use ripasso::{crypto::CryptoImpl, pass}; lazy_static! { @@ -81,6 +82,20 @@ pub fn is_radio_button_selected(s: &mut Cursive, button_name: &str) -> bool { selected } +pub fn recipients_widths(recipients: &[Recipient]) -> (usize, usize) { + let mut max_width_key = 0; + let mut max_width_name = 0; + for recipient in recipients { + if recipient.key_id.len() > max_width_key { + max_width_key = recipient.key_id.len(); + } + if recipient.name.len() > max_width_name { + max_width_name = recipient.name.len(); + } + } + (max_width_key, max_width_name) +} + #[cfg(test)] #[path = "tests/helpers.rs"] mod helpers_tests; diff --git a/cursive/src/main.rs b/cursive/src/main.rs index 9c2544f..5bc0485 100644 --- a/cursive/src/main.rs +++ b/cursive/src/main.rs @@ -51,7 +51,9 @@ mod wizard; use lazy_static::lazy_static; use zeroize::Zeroize; -use crate::helpers::{get_value_from_input, is_checkbox_checked, is_radio_button_selected}; +use crate::helpers::{ + get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths, +}; /// The 'pointer' to the current PasswordStore is of this convoluted type. type PasswordStoreType = Arc>>>; @@ -783,16 +785,7 @@ fn add_recipient(ui: &mut Cursive, store: PasswordStoreType, config_path: &Path) match all_recipients_res { Err(err) => helpers::errorbox(ui, &err), Ok(recipients) => { - let mut max_width_key = 0; - let mut max_width_name = 0; - for recipient in &recipients { - if recipient.key_id.len() > max_width_key { - max_width_key = recipient.key_id.len(); - } - if recipient.name.len() > max_width_name { - max_width_name = recipient.name.len(); - } - } + let (max_width_key, max_width_name) = recipients_widths(&recipients); let mut recipients_view = ui .find_name::>>("recipients") @@ -977,16 +970,7 @@ fn view_recipients_for_many_dirs( recipients_view .get_mut() .add_item(path.to_string_lossy(), None); - let mut max_width_key = 0; - let mut max_width_name = 0; - for recipient in recipients { - if recipient.key_id.len() > max_width_key { - max_width_key = recipient.key_id.len(); - } - if recipient.name.len() > max_width_name { - max_width_name = recipient.name.len(); - } - } + let (max_width_key, max_width_name) = recipients_widths(recipients); for recipient in recipients { recipients_view.get_mut().add_item( render_recipient_label(recipient, max_width_key, max_width_name), @@ -1052,16 +1036,7 @@ fn view_recipients_for_dir( .h_align(cursive::align::HAlign::Left) .with_name("recipients"); - let mut max_width_key = 0; - let mut max_width_name = 0; - for recipient in &recipients { - if recipient.key_id.len() > max_width_key { - max_width_key = recipient.key_id.len(); - } - if recipient.name.len() > max_width_name { - max_width_name = recipient.name.len(); - } - } + let (max_width_key, max_width_name) = recipients_widths(&recipients); for recipient in recipients { recipients_view.get_mut().add_item( render_recipient_label(&recipient, max_width_key, max_width_name), diff --git a/cursive/src/tests/helpers.rs b/cursive/src/tests/helpers.rs index 568d18c..03dc1b2 100644 --- a/cursive/src/tests/helpers.rs +++ b/cursive/src/tests/helpers.rs @@ -1,12 +1,15 @@ use std::sync::Arc; +use crate::helpers::{ + get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths, +}; use cursive::{ view::Nameable, views::{Checkbox, EditView, LinearLayout, RadioButton, RadioGroup}, }; +use hex::FromHex; use ripasso::crypto::CryptoImpl; - -use crate::helpers::{get_value_from_input, is_checkbox_checked, is_radio_button_selected}; +use ripasso::pass::{Comment, KeyRingStatus, OwnerTrustLevel, Recipient}; #[test] fn test_get_value_from_input() { @@ -81,3 +84,34 @@ fn is_radio_button_selected_true() { assert!(is_radio_button_selected(&mut siv, "button2_name")); } + +#[test] +fn recipients_widths_empty() { + let (max_width_key, max_width_name) = recipients_widths(&[]); + assert_eq!(0, max_width_key); + assert_eq!(0, max_width_name); +} + +pub fn recipient_alex() -> Recipient { + Recipient { + name: "Alexander Kjäll ".to_owned(), + comment: Comment { + pre_comment: None, + post_comment: None, + }, + key_id: "1D108E6C07CBC406".to_owned(), + fingerprint: Some( + <[u8; 20]>::from_hex("7E068070D5EF794B00C8A9D91D108E6C07CBC406").unwrap(), + ), + key_ring_status: KeyRingStatus::InKeyRing, + trust_level: OwnerTrustLevel::Ultimate, + not_usable: false, + } +} + +#[test] +fn recipients_widths_basic() { + let (max_width_key, max_width_name) = recipients_widths(&[recipient_alex()]); + assert_eq!(16, max_width_key); + assert_eq!(44, max_width_name); +} diff --git a/cursive/src/tests/main.rs b/cursive/src/tests/main.rs index 907158e..1c38f10 100644 --- a/cursive/src/tests/main.rs +++ b/cursive/src/tests/main.rs @@ -10,7 +10,7 @@ use super::*; fn copy_name_none() { let mut siv = cursive::default(); - let entries = SelectView::::new(); + let entries = SelectView::::new(); siv.add_layer(entries.with_name("results")); @@ -49,7 +49,7 @@ fn do_delete_normal() { )); let store: PasswordStoreType = Arc::new(Mutex::new(Arc::new(Mutex::new(store)))); - let mut entries = SelectView::::new(); + let mut entries = SelectView::::new(); entries.add_all( store .lock() @@ -65,12 +65,12 @@ fn do_delete_normal() { siv.add_layer(entries.with_name("results")); - siv.call_on_name("results", |l: &mut SelectView| { + siv.call_on_name("results", |l: &mut SelectView| { assert_eq!(1, l.len()); }); do_delete(&mut siv, store); - siv.call_on_name("results", |l: &mut SelectView| { + siv.call_on_name("results", |l: &mut SelectView| { assert_eq!(0, l.len()); }); } @@ -88,11 +88,11 @@ fn get_selected_password_entry_none() { fn get_selected_password_entry_some() { let mut siv = cursive::default(); - let mut sv = SelectView::::new(); + let mut sv = SelectView::::new(); sv.add_item( "Item 1", - pass::PasswordEntry::new( + PasswordEntry::new( &PathBuf::from("/tmp/"), &PathBuf::from("file.gpg"), Ok(Local::now()), @@ -112,7 +112,7 @@ fn get_selected_password_entry_some() { #[test] fn do_delete_one_entry() { - let dir = tempfile::tempdir().unwrap(); + let dir = tempdir().unwrap(); std::fs::create_dir_all(dir.path().join(".password-store")).unwrap(); let mut pass_file = File::create(dir.path().join(".password-store").join("file.gpg")).unwrap(); pass_file.flush().unwrap(); @@ -138,7 +138,7 @@ fn do_delete_one_entry() { let mut siv = cursive::default(); - let mut sv = SelectView::::new(); + let mut sv = SelectView::::new(); for (i, item) in store.all_passwords().unwrap().into_iter().enumerate() { sv.add_item(format!("Item {}", i), item); @@ -147,12 +147,12 @@ fn do_delete_one_entry() { assert_eq!(1, sv.len()); siv.add_layer(sv.with_name("results")); - siv.add_layer(SelectView::::new().with_name("just to be popped")); + siv.add_layer(SelectView::::new().with_name("just to be popped")); let store: PasswordStoreType = Arc::new(Mutex::new(Arc::new(Mutex::new(store)))); do_delete(&mut siv, store); - let cbr = siv.call_on_name("results", |l: &mut SelectView| { + let cbr = siv.call_on_name("results", |l: &mut SelectView| { assert_eq!(0, l.len()); }); @@ -163,7 +163,7 @@ fn do_delete_one_entry() { fn render_recipient_label_ultimate() { let r = Recipient { name: "Alexander Kjäll ".to_owned(), - comment: ripasso::pass::Comment { + comment: pass::Comment { pre_comment: None, post_comment: None, }, @@ -171,7 +171,7 @@ fn render_recipient_label_ultimate() { fingerprint: Some( <[u8; 20]>::from_hex("7E068070D5EF794B00C8A9D91D108E6C07CBC406").unwrap(), ), - key_ring_status: ripasso::pass::KeyRingStatus::InKeyRing, + key_ring_status: pass::KeyRingStatus::InKeyRing, trust_level: OwnerTrustLevel::Ultimate, not_usable: false, }; @@ -195,7 +195,7 @@ fn substr_overlong() { fn create_label_basic() { // TODO: Fix this test so that time zones don't mess with it. - let p = pass::PasswordEntry::new( + let p = PasswordEntry::new( &PathBuf::from("/tmp/"), &PathBuf::from("file.gpg"), Ok(chrono::DateTime::::from( @@ -214,7 +214,7 @@ fn create_label_basic() { #[test] fn get_sub_dirs_empty() { - let dir = tempfile::tempdir().unwrap(); + let dir = tempdir().unwrap(); let dirs = get_sub_dirs(&dir.path().to_path_buf()).unwrap(); @@ -224,7 +224,7 @@ fn get_sub_dirs_empty() { #[test] fn get_sub_dirs_one_dir() { - let dir = tempfile::tempdir().unwrap(); + let dir = tempdir().unwrap(); std::fs::create_dir(dir.path().join("one_dir")).unwrap(); let dirs = get_sub_dirs(&dir.path().to_path_buf()).unwrap(); @@ -235,9 +235,9 @@ fn get_sub_dirs_one_dir() { #[test] fn get_sub_dirs_one_dir_with_pgpid() { - let dir = tempfile::tempdir().unwrap(); + let dir = tempdir().unwrap(); std::fs::create_dir(dir.path().join("one_dir")).unwrap(); - std::fs::File::create(dir.path().join("one_dir").join(".gpg-id")).unwrap(); + File::create(dir.path().join("one_dir").join(".gpg-id")).unwrap(); let dirs = get_sub_dirs(&dir.path().to_path_buf()).unwrap(); diff --git a/gtk/Cargo.toml b/gtk/Cargo.toml index df60145..2bac8f2 100644 --- a/gtk/Cargo.toml +++ b/gtk/Cargo.toml @@ -7,13 +7,13 @@ edition = "2021" [dependencies] ripasso = { path = "../", version = "0.7.0-alpha" } -gtk = { version = "0.9.5", package = "gtk4", features = ["v4_6"] } -adw = { version = "0.7.1", package = "libadwaita" } -glib = "0.20.7" -once_cell = "1.19.0" -hex = "0.4.3" -config = "0.15.4" +gtk = { version = "0.9", package = "gtk4", features = ["v4_6"] } +adw = { version = "0.7", package = "libadwaita" } +glib = "0.20" +once_cell = "1" +hex = "0.4" +config = "0.15" chrono = { version = "0.4", default-features = false, features = ["clock"] } [build-dependencies] -glib-build-tools = "0.20.0" +glib-build-tools = "0.20" diff --git a/gtk/src/window/mod.rs b/gtk/src/window/mod.rs index c015f0e..fb1266b 100644 --- a/gtk/src/window/mod.rs +++ b/gtk/src/window/mod.rs @@ -494,7 +494,7 @@ impl Window { // Destroy dialog dialog.destroy(); - // Return if the user chose a response different than `Accept` + // Return if the user chose a response different from `Accept` if response != ResponseType::Accept { return; } diff --git a/src/crypto.rs b/src/crypto.rs index 45600f2..9bf043c 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -523,7 +523,7 @@ impl DecryptionHelper for Helper<'_> { for pkesk in pkesks { if let Ok(cert) = find(self.key_ring, pkesk.recipient()) { let key = cert.primary_key(); - let mut pair = sequoia_gpg_agent::gnupg::KeyPair::new( + let mut pair = sequoia_gpg_agent::KeyPair::new_for_gnupg_context( self.ctx .as_ref() .ok_or_else(|| anyhow::anyhow!("no context configured"))?, diff --git a/src/tests/git.rs b/src/tests/git.rs index da3a22c..6dcb4bd 100644 --- a/src/tests/git.rs +++ b/src/tests/git.rs @@ -4,7 +4,7 @@ use crate::{error::Result, git::should_sign, test_helpers::UnpackedDir}; fn test_should_sign_true() -> Result<()> { let dir = UnpackedDir::new("test_should_sign_true")?; - let repo = git2::Repository::open(dir.dir()).unwrap(); + let repo = git2::Repository::open(dir.path())?; let result = should_sign(&repo); @@ -17,7 +17,7 @@ fn test_should_sign_true() -> Result<()> { fn test_should_sign_false() -> Result<()> { let dir = UnpackedDir::new("test_should_sign_false")?; - let repo = git2::Repository::open(dir.dir()).unwrap(); + let repo = git2::Repository::open(dir.path())?; let result = should_sign(&repo); diff --git a/src/tests/pass.rs b/src/tests/pass.rs index 87fd119..3cd3fbf 100644 --- a/src/tests/pass.rs +++ b/src/tests/pass.rs @@ -107,14 +107,14 @@ fn populate_password_list_small_repo() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; assert_eq!(results.len(), 1); assert_eq!(results[0].name, "test"); @@ -129,14 +129,14 @@ fn populate_password_list_repo_with_deleted_files() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; assert_eq!(results.len(), 1); assert_eq!(results[0].name, "10"); @@ -151,14 +151,14 @@ fn populate_password_list_directory_without_git() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; assert_eq!(results.len(), 3); assert_eq!(results[0].name, "first"); @@ -184,14 +184,14 @@ fn password_store_with_files_in_initial_commit() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; let expected = ["3", "A/1", "B/2"]; @@ -211,9 +211,9 @@ fn password_store_with_relative_path() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, @@ -243,14 +243,14 @@ fn password_store_with_shallow_checkout() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; assert_eq!(results.len(), 1); assert_eq!(results[0].name, "1"); @@ -266,14 +266,14 @@ fn password_store_with_sparse_checkout() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; assert_eq!(results.len(), 3); assert_eq!(results[0].name, "3/1"); @@ -295,11 +295,11 @@ fn password_store_with_sparse_checkout() -> Result<()> { fn password_store_with_symlink() -> Result<()> { let dir = UnpackedDir::new("password_store_with_symlink")?; let link_dir = dir - .dir() + .path() .parent() .unwrap() .join("password_store_with_symlink_link"); - std::os::unix::fs::symlink(dir.dir(), link_dir.clone())?; + std::os::unix::fs::symlink(dir.path(), link_dir.clone())?; let store = PasswordStore::new( "default", @@ -310,7 +310,7 @@ fn password_store_with_symlink() -> Result<()> { &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; fs::remove_file(link_dir)?; @@ -344,7 +344,7 @@ fn home_exists_home_dir_without_config_dir() { #[test] fn home_exists_home_dir_with_file_instead_of_dir() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; File::create(dir.path().join(".password-store"))?; let result = home_exists(&Some(dir.into_path()), &Config::default()); @@ -355,7 +355,7 @@ fn home_exists_home_dir_with_file_instead_of_dir() -> Result<()> { #[test] fn home_exists_home_dir_with_config_dir() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; fs::create_dir(dir.path().join(".password-store"))?; let result = home_exists(&Some(dir.into_path()), &Config::default()); @@ -405,10 +405,10 @@ fn home_settings_missing() { #[test] fn home_settings_dir_exists() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; fs::create_dir(dir.path().join(".password-store"))?; - let settings = home_settings(&Some(PathBuf::from(dir.path()))).unwrap(); + let settings = home_settings(&Some(PathBuf::from(dir.path())))?; let stores = settings.get_table("stores")?; let work = stores["default"].clone().into_table()?; @@ -429,9 +429,9 @@ fn home_settings_dir_exists() -> Result<()> { /// this works due to that it's the function `home_exists` that checks if it exists #[test] fn home_settings_dir_doesnt_exists() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; - let settings = home_settings(&Some(PathBuf::from(dir.path()))).unwrap(); + let settings = home_settings(&Some(PathBuf::from(dir.path())))?; let stores = settings.get_table("stores")?; let work = stores["default"].clone().into_table()?; @@ -472,7 +472,7 @@ fn var_settings_test() -> Result<()> { #[test] fn file_settings_simple_file() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".config").join("ripasso"))?; let mut file = File::create( dir.path() @@ -490,7 +490,7 @@ fn file_settings_simple_file() -> Result<()> { let mut settings = ConfigBuilder::default(); settings = config::ConfigBuilder::::add_source( settings, - file_settings(&xdg_config_file_location(&Some(dir.into_path()), &None).unwrap()), + file_settings(&xdg_config_file_location(&Some(dir.into_path()), &None)?), ); let settings = settings.build()?; @@ -505,8 +505,8 @@ fn file_settings_simple_file() -> Result<()> { #[test] fn file_settings_file_in_xdg_config_home() -> Result<()> { - let dir = tempdir().unwrap(); - let dir2 = tempdir().unwrap(); + let dir = tempdir()?; + let dir2 = tempdir()?; create_dir_all(dir2.path().join(".random_config").join("ripasso"))?; let mut file = File::create( dir2.path() @@ -542,7 +542,7 @@ fn file_settings_file_in_xdg_config_home() -> Result<()> { #[test] fn read_config_empty_config_file() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".config").join("ripasso"))?; create_dir_all(dir.path().join(".password-store"))?; File::create( @@ -572,7 +572,7 @@ fn read_config_empty_config_file() -> Result<()> { #[test] fn read_config_empty_config_file_with_keys_env() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let (settings, _) = read_config( @@ -605,7 +605,7 @@ fn read_config_empty_config_file_with_keys_env() -> Result<()> { #[test] fn read_config_env_vars() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join("env_var").join(".password-store"))?; let (settings, _) = read_config( @@ -646,7 +646,7 @@ fn read_config_env_vars() -> Result<()> { #[test] fn read_config_home_and_env_vars() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; create_dir_all(dir.path().join("env_var").join(".password-store"))?; @@ -688,7 +688,7 @@ fn read_config_home_and_env_vars() -> Result<()> { #[test] fn read_config_default_path_in_config_file() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -723,7 +723,7 @@ fn read_config_default_path_in_config_file() -> Result<()> { #[test] fn read_config_default_path_in_env_var() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -765,7 +765,7 @@ fn read_config_default_path_in_env_var() -> Result<()> { #[test] fn read_config_default_path_in_env_var_with_pgp_setting() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -913,7 +913,7 @@ fn append_extension_with_dot() { fn rename_file() -> Result<()> { let dir = UnpackedDir::new("rename_file")?; - let mut config_location = dir.dir().to_path_buf(); + let mut config_location = dir.dir(); config_location.push(".git"); config_location.push("config"); let mut config = git2::Config::open(&config_location)?; @@ -923,7 +923,7 @@ fn rename_file() -> Result<()> { let mut store = PasswordStore { name: "default".to_owned(), - root: dir.dir().to_path_buf(), + root: dir.dir(), valid_gpg_signing_keys: vec![], passwords: vec![], style_file: None, @@ -953,9 +953,9 @@ fn rename_file_absolute_path() -> Result<()> { let mut store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, @@ -971,7 +971,7 @@ fn rename_file_absolute_path() -> Result<()> { fn rename_file_git_index_clean() -> Result<()> { let dir = UnpackedDir::new("rename_file_git_index_clean")?; - let mut config_location = dir.dir().to_path_buf(); + let mut config_location = dir.dir(); config_location.push(".git"); config_location.push("config"); let mut config = git2::Config::open(&config_location)?; @@ -981,7 +981,7 @@ fn rename_file_git_index_clean() -> Result<()> { let mut store = PasswordStore { name: "default".to_owned(), - root: dir.dir().to_path_buf(), + root: dir.dir(), valid_gpg_signing_keys: vec![], passwords: vec![], style_file: None, @@ -991,7 +991,7 @@ fn rename_file_git_index_clean() -> Result<()> { store.reload_password_list()?; store.rename_file("1/test", "2/test")?; - let repo = Repository::open(dir.dir())?; + let repo = Repository::open(dir.path())?; assert!(repo.statuses(None)?.is_empty()); @@ -1000,7 +1000,7 @@ fn rename_file_git_index_clean() -> Result<()> { #[test] fn decrypt_secret_empty_file() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -1038,7 +1038,7 @@ fn decrypt_secret_empty_file() -> Result<()> { #[test] fn decrypt_secret_missing_file() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -1076,14 +1076,14 @@ fn decrypt_secret_missing_file() -> Result<()> { #[test] fn decrypt_secret() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; gpg_file.flush()?; let mut pass_file = File::create(dir.path().join(".password-store").join("file.gpg"))?; - pass_file.write_all("dummy data".as_bytes()).unwrap(); + pass_file.write_all("dummy data".as_bytes())?; pass_file.flush()?; let pe = PasswordEntry::new( @@ -1108,7 +1108,7 @@ fn decrypt_secret() -> Result<()> { user_home: None, }; - let res = pe.secret(&store).unwrap(); + let res = pe.secret(&store)?; assert_eq!("decrypt_secret unit test", res); @@ -1117,7 +1117,7 @@ fn decrypt_secret() -> Result<()> { #[test] fn decrypt_password_empty_file() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -1155,14 +1155,14 @@ fn decrypt_password_empty_file() -> Result<()> { #[test] fn decrypt_password_multiline() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; gpg_file.flush()?; let mut pass_file = File::create(dir.path().join(".password-store").join("file.gpg"))?; - pass_file.write_all("dummy data".as_bytes()).unwrap(); + pass_file.write_all("dummy data".as_bytes())?; pass_file.flush()?; let pe = PasswordEntry::new( @@ -1187,7 +1187,7 @@ fn decrypt_password_multiline() -> Result<()> { user_home: None, }; - let mut res = pe.password(&store).unwrap(); + let mut res = pe.password(&store)?; assert_eq!("row one", res); res.zeroize(); @@ -1196,14 +1196,14 @@ fn decrypt_password_multiline() -> Result<()> { } fn mfa_setup(payload: String) -> Result<(tempfile::TempDir, PasswordEntry, PasswordStore)> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; gpg_file.flush()?; let mut pass_file = File::create(dir.path().join(".password-store").join("file.gpg"))?; - pass_file.write_all("dummy data".as_bytes()).unwrap(); + pass_file.write_all("dummy data".as_bytes())?; pass_file.flush()?; let pe = PasswordEntry::new( @@ -1234,7 +1234,7 @@ fn mfa_setup(payload: String) -> Result<(tempfile::TempDir, PasswordEntry, Passw fn mfa_example1() -> Result<()> { let (_dir, pe, store) = mfa_setup("otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXPAAAAAAAAAAAA&issuer=Example".to_owned())?; - let res = pe.mfa(&store).unwrap(); + let res = pe.mfa(&store)?; assert_eq!(6, res.len()); assert_eq!(6, res.chars().filter(|c| c.is_ascii_digit()).count()); @@ -1246,7 +1246,7 @@ fn mfa_example1() -> Result<()> { fn mfa_example2() -> Result<()> { let (_dir, pe, store) = mfa_setup("some text\n otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXPAAAAAAAAAAAA&issuer=Example\nmore txt\n\n".to_owned())?; - let res = pe.mfa(&store).unwrap(); + let res = pe.mfa(&store)?; assert_eq!(6, res.len()); assert_eq!(6, res.chars().filter(|c| c.is_ascii_digit()).count()); @@ -1258,7 +1258,7 @@ fn mfa_example2() -> Result<()> { fn mfa_example3() -> Result<()> { let (_dir, pe, store) = mfa_setup("lots and lots and lots and lots and lots and lots and lots and lots and lots and lots of text\n otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXPAAAAAAAAAAAA&issuer=Example\nmore txt\n\n".to_owned())?; - let res = pe.mfa(&store).unwrap(); + let res = pe.mfa(&store)?; assert_eq!(6, res.len()); assert_eq!(6, res.chars().filter(|c| c.is_ascii_digit()).count()); @@ -1279,14 +1279,14 @@ fn mfa_no_otpauth_url() -> Result<()> { #[test] fn update() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; gpg_file.flush()?; let mut pass_file = File::create(dir.path().join(".password-store").join("file.gpg"))?; - pass_file.write_all("dummy data".as_bytes()).unwrap(); + pass_file.write_all("dummy data".as_bytes())?; pass_file.flush()?; let pe = PasswordEntry::new( @@ -1325,7 +1325,7 @@ fn update() -> Result<()> { #[test] fn delete_file() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -1364,7 +1364,7 @@ fn delete_file() -> Result<()> { #[test] fn get_history_no_repo() -> Result<()> { - let dir = tempdir().unwrap(); + let dir = tempdir()?; create_dir_all(dir.path().join(".password-store"))?; let mut gpg_file = File::create(dir.path().join(".password-store").join(".gpg-id"))?; writeln!(&gpg_file, "0xDF0C3D316B7312D5\n")?; @@ -1405,14 +1405,14 @@ fn get_history_with_repo() -> Result<()> { let store = PasswordStore::new( "default", - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, - &Some(dir.dir().to_path_buf()), + &Some(dir.dir()), &None, &CryptoImpl::GpgMe, &None, )?; - let results = store.all_passwords().unwrap(); + let results = store.all_passwords()?; assert_eq!(results.len(), 1); assert_eq!(results[0].name, "test"); @@ -1524,7 +1524,7 @@ fn test_commit_unsigned() -> Result<()> { assert!(!(*crypto.sign_called.borrow())); - assert_eq!("test", repo.find_commit(c_oid).unwrap().message().unwrap()); + assert_eq!("test", repo.find_commit(c_oid)?.message().unwrap()); Ok(()) } @@ -1556,7 +1556,7 @@ fn test_commit_signed() -> Result<()> { assert!(*crypto.sign_called.borrow()); - assert_eq!("test", repo.find_commit(c_oid).unwrap().message().unwrap()); + assert_eq!("test", repo.find_commit(c_oid)?.message().unwrap()); Ok(()) } @@ -1565,7 +1565,7 @@ fn test_commit_signed() -> Result<()> { fn test_move_and_commit_signed() -> Result<()> { let dir = UnpackedDir::new("test_move_and_commit_signed")?; - let repo = Repository::init(dir.dir())?; + let repo = Repository::init(dir.path())?; let mut config = repo.config()?; config.set_bool("commit.gpgsign", true)?; @@ -1573,13 +1573,13 @@ fn test_move_and_commit_signed() -> Result<()> { config.set_str("user.email", "default@example.com")?; fs::rename( - dir.dir().join("first_pass.gpg"), - dir.dir().join("second_pass.gpg"), + dir.path().join("first_pass.gpg"), + dir.path().join("second_pass.gpg"), )?; let store = PasswordStore { name: "store_name".to_owned(), - root: dir.dir().to_path_buf(), + root: dir.dir(), valid_gpg_signing_keys: vec![], passwords: vec![], style_file: None, @@ -1593,10 +1593,7 @@ fn test_move_and_commit_signed() -> Result<()> { "unit test", )?; - assert_eq!( - "unit test", - repo.find_commit(c_oid).unwrap().message().unwrap() - ); + assert_eq!("unit test", repo.find_commit(c_oid)?.message().unwrap()); Ok(()) } @@ -1651,12 +1648,12 @@ fn test_search() -> Result<()> { fn test_verify_git_signature() -> Result<()> { let dir = UnpackedDir::new("test_verify_git_signature")?; - let repo = Repository::open(dir.dir()).unwrap(); + let repo = Repository::open(dir.path())?; let oid = repo.head()?.target().unwrap(); let store = PasswordStore { name: "store_name".to_owned(), - root: dir.dir().to_path_buf(), + root: dir.dir(), valid_gpg_signing_keys: vec![<[u8; 20]>::from_hex( "7E068070D5EF794B00C8A9D91D108E6C07CBC406", )?], @@ -1678,7 +1675,7 @@ fn test_verify_git_signature() -> Result<()> { fn test_add_and_commit_internal() -> Result<()> { let dir = UnpackedDir::new("test_add_and_commit_internal")?; - let repo = Repository::init(dir.dir())?; + let repo = Repository::init(dir.path())?; let mut config = repo.config()?; config.set_bool("commit.gpgsign", true)?; @@ -1687,24 +1684,17 @@ fn test_add_and_commit_internal() -> Result<()> { let crypto = MockCrypto::new(); - let new_password = dir.dir().join("new_password"); - File::create(new_password) - .unwrap() - .write_all("swordfish".as_bytes()) - .unwrap(); + let new_password = dir.path().join("new_password"); + File::create(new_password)?.write_all("swordfish".as_bytes())?; let c_oid = add_and_commit_internal( &repo, &[PathBuf::from("new_password")], "unit test", &crypto, - ) - .unwrap(); + )?; - assert_eq!( - "unit test", - repo.find_commit(c_oid).unwrap().message().unwrap() - ); + assert_eq!("unit test", repo.find_commit(c_oid)?.message().unwrap()); Ok(()) } @@ -1715,7 +1705,7 @@ fn test_remove_and_commit() -> Result<()> { let store = PasswordStore { name: "store_name".to_owned(), - root: dir.dir().to_path_buf(), + root: dir.dir(), valid_gpg_signing_keys: vec![<[u8; 20]>::from_hex( "7E068070D5EF794B00C8A9D91D108E6C07CBC406", )?], @@ -1725,22 +1715,18 @@ fn test_remove_and_commit() -> Result<()> { user_home: None, }; - let repo = Repository::open(dir.dir()).unwrap(); + let repo = Repository::open(dir.path())?; let mut config = repo.config()?; config.set_bool("commit.gpgsign", true)?; config.set_str("user.name", "default")?; config.set_str("user.email", "default@example.com")?; - let c_oid = - remove_and_commit(&store, &[PathBuf::from("pass_to_be_deleted")], "unit test").unwrap(); + let c_oid = remove_and_commit(&store, &[PathBuf::from("pass_to_be_deleted")], "unit test")?; - assert_eq!( - "unit test", - repo.find_commit(c_oid).unwrap().message().unwrap() - ); + assert_eq!("unit test", repo.find_commit(c_oid)?.message().unwrap()); - assert!(!dir.dir().join("pass_to_be_deleted").is_file()); + assert!(!dir.path().join("pass_to_be_deleted").is_file()); Ok(()) } @@ -1943,7 +1929,7 @@ fn test_new_password_file() -> Result<()> { assert_eq!(0, store.passwords.len()); - let result = store.new_password_file("test/file", "password").unwrap(); + let result = store.new_password_file("test/file", "password")?; assert_eq!(1, store.passwords.len()); assert_eq!("test/file", store.passwords[0].name); @@ -1984,7 +1970,7 @@ fn test_new_password_file_in_git_repo() -> Result<()> { assert_eq!(0, store.passwords.len()); - let result = store.new_password_file("test/file", "password").unwrap(); + let result = store.new_password_file("test/file", "password")?; assert_eq!(1, store.passwords.len()); assert_eq!("test/file", store.passwords[0].name); @@ -2061,7 +2047,7 @@ fn test_new_password_file_twice() -> Result<()> { assert_eq!(0, store.passwords.len()); - let result = store.new_password_file("test/file", "password").unwrap(); + let result = store.new_password_file("test/file", "password")?; assert_eq!(1, store.passwords.len()); assert_eq!("test/file", store.passwords[0].name); @@ -2128,7 +2114,7 @@ fn test_new_password_file_different_sub_permissions() -> Result<()> { + "\n", )?; - fs::create_dir(td.path().join("dir")).unwrap(); + fs::create_dir(td.path().join("dir"))?; fs::write( td.path().join("dir").join(".gpg-id"), hex::encode(users[1].fingerprint().as_bytes()), @@ -2161,7 +2147,7 @@ fn test_rename_file_different_sub_permissions() -> Result<()> { + "\n", )?; - fs::create_dir(td.path().join("dir")).unwrap(); + fs::create_dir(td.path().join("dir"))?; fs::write( td.path().join("dir").join(".gpg-id"), hex::encode(users[0].fingerprint().as_bytes()), @@ -2197,7 +2183,7 @@ fn test_add_recipient_different_sub_permissions() -> Result<()> { + "\n", )?; - fs::create_dir(td.path().join("dir")).unwrap(); + fs::create_dir(td.path().join("dir"))?; fs::write( td.path().join("dir").join(".gpg-id"), hex::encode(users[0].fingerprint().as_bytes()) + "\n", @@ -2208,20 +2194,18 @@ fn test_add_recipient_different_sub_permissions() -> Result<()> { store.new_password_file("file", "password")?; store.new_password_file("dir/file", "password")?; - store - .add_recipient( - &crate::test_helpers::recipient_from_cert(&users[2]), - &PathBuf::from("./"), - config_path.path(), - ) - .unwrap(); + store.add_recipient( + &crate::test_helpers::recipient_from_cert(&users[2]), + &PathBuf::from("./"), + config_path.path(), + )?; assert_eq!(2, store.passwords.len()); - let content = fs::read(td.path().join("file.gpg")).unwrap(); + let content = fs::read(td.path().join("file.gpg"))?; assert_eq!(3, count_recipients(&content)); - let content = fs::read(td.path().join("dir/file.gpg")).unwrap(); + let content = fs::read(td.path().join("dir/file.gpg"))?; assert_eq!(1, count_recipients(&content)); Ok(()) @@ -2243,7 +2227,7 @@ fn test_add_recipient_to_sub_dir() -> Result<()> { + "\n", )?; - fs::create_dir(td.path().join("dir")).unwrap(); + fs::create_dir(td.path().join("dir"))?; assert_eq!(0, store.passwords.len()); @@ -2258,10 +2242,10 @@ fn test_add_recipient_to_sub_dir() -> Result<()> { assert_eq!(2, store.passwords.len()); - let content = fs::read(td.path().join("file.gpg")).unwrap(); + let content = fs::read(td.path().join("file.gpg"))?; assert_eq!(2, count_recipients(&content)); - let content = fs::read(td.path().join("dir/file.gpg")).unwrap(); + let content = fs::read(td.path().join("dir/file.gpg"))?; assert_eq!(1, count_recipients(&content)); Ok(()) @@ -2453,7 +2437,7 @@ fn test_remove_recipient_root() -> Result<()> { + "\n", )?; - fs::create_dir(td.path().join("dir")).unwrap(); + fs::create_dir(td.path().join("dir"))?; fs::write( td.path().join("dir").join(".gpg-id"), hex::encode(users[0].fingerprint().as_bytes()) + "\n", @@ -2464,19 +2448,17 @@ fn test_remove_recipient_root() -> Result<()> { store.new_password_file("file", "password")?; store.new_password_file("dir/file", "password")?; - store - .remove_recipient( - &crate::test_helpers::recipient_from_cert(&users[1]), - &PathBuf::from("./"), - ) - .unwrap(); + store.remove_recipient( + &crate::test_helpers::recipient_from_cert(&users[1]), + &PathBuf::from("./"), + )?; assert_eq!(2, store.passwords.len()); - let content = fs::read(td.path().join("file.gpg")).unwrap(); + let content = fs::read(td.path().join("file.gpg"))?; assert_eq!(1, count_recipients(&content)); - let content = fs::read(td.path().join("dir/file.gpg")).unwrap(); + let content = fs::read(td.path().join("dir/file.gpg"))?; assert_eq!(1, count_recipients(&content)); Ok(()) @@ -2513,7 +2495,7 @@ fn test_recipient_files() -> Result<()> { + "\n", )?; - fs::create_dir(td.path().join("dir")).unwrap(); + fs::create_dir(td.path().join("dir"))?; fs::write( td.path().join("dir").join(".gpg-id"), hex::encode(users[0].fingerprint().as_bytes()), diff --git a/src/tests/signature.rs b/src/tests/signature.rs index a1f0044..c8a3316 100644 --- a/src/tests/signature.rs +++ b/src/tests/signature.rs @@ -126,7 +126,7 @@ fn all_recipients() { result[0].name ); assert_eq!("0x1D108E6C07CBC406", result[0].key_id); - assert!(KeyRingStatus::InKeyRing == result[0].key_ring_status); + assert_eq!(KeyRingStatus::InKeyRing, result[0].key_ring_status); } #[test] @@ -158,7 +158,7 @@ fn all_recipients_with_one_comment_line() { ); assert_eq!(None, result[0].comment.post_comment); assert_eq!("0x1D108E6C07CBC406", result[0].key_id); - assert!(KeyRingStatus::InKeyRing == result[0].key_ring_status); + assert_eq!(KeyRingStatus::InKeyRing, result[0].key_ring_status); } #[test] @@ -194,7 +194,7 @@ fn all_recipients_with_multiple_comment_lines() { ); assert_eq!(None, result[0].comment.post_comment); assert_eq!("0x1D108E6C07CBC406", result[0].key_id); - assert!(KeyRingStatus::InKeyRing == result[0].key_ring_status); + assert_eq!(KeyRingStatus::InKeyRing, result[0].key_ring_status); } #[test] @@ -229,7 +229,7 @@ fn all_recipients_with_comment_lines_pre_and_post() { result[0].comment.pre_comment.as_ref().unwrap() ); assert_eq!("0x1D108E6C07CBC406", result[0].key_id); - assert!(KeyRingStatus::InKeyRing == result[0].key_ring_status); + assert_eq!(KeyRingStatus::InKeyRing, result[0].key_ring_status); } #[test] @@ -247,7 +247,7 @@ fn all_recipients_error() { assert_eq!(1, result.len()); assert_eq!("key id not in keyring", result[0].name); assert_eq!("0x1D108E6C07CBC406", result[0].key_id); - assert!(KeyRingStatus::NotInKeyRing == result[0].key_ring_status); + assert_eq!(KeyRingStatus::NotInKeyRing, result[0].key_ring_status); } #[test] @@ -757,8 +757,8 @@ fn recipient_both_none() { not_usable: false, }; - assert!(r1 != r2); - assert!(r2 != r1); + assert_ne!(r1, r2); + assert_ne!(r2, r1); } #[test] @@ -790,8 +790,8 @@ fn recipient_one_none() { not_usable: false, }; - assert!(r1 != r2); - assert!(r2 != r1); + assert_ne!(r1, r2); + assert_ne!(r2, r1); } #[test] @@ -825,6 +825,6 @@ fn recipient_same_fingerprint_different_key_id() { not_usable: false, }; - assert!(r1 == r2); - assert!(r2 == r1); + assert_eq!(r1, r2); + assert_eq!(r2, r1); } diff --git a/src/tests/test_helpers.rs b/src/tests/test_helpers.rs index 633d748..b22d059 100644 --- a/src/tests/test_helpers.rs +++ b/src/tests/test_helpers.rs @@ -51,9 +51,13 @@ impl UnpackedDir { }) } - pub fn dir(&self) -> &Path { + pub fn path(&self) -> &Path { self.dir.as_path() } + + pub fn dir(&self) -> PathBuf { + self.dir.clone() + } } fn get_testres_path() -> PathBuf { @@ -295,7 +299,7 @@ pub fn recipient_alex_old() -> Recipient { not_usable: false, } } -pub fn recipient_from_cert(cert: &sequoia_openpgp::Cert) -> Recipient { +pub fn recipient_from_cert(cert: &Cert) -> Recipient { Recipient { name: String::from_utf8(cert.userids().next().unwrap().value().to_vec()).unwrap(), comment: Comment { @@ -317,7 +321,7 @@ pub fn append_file_name(file: &Path) -> PathBuf { sig.into() } -pub fn generate_sequoia_cert(email: &str) -> sequoia_openpgp::Cert { +pub fn generate_sequoia_cert(email: &str) -> Cert { let (cert, _) = CertBuilder::general_purpose(None, Some(email)) .generate() .unwrap(); @@ -325,7 +329,7 @@ pub fn generate_sequoia_cert(email: &str) -> sequoia_openpgp::Cert { cert } -pub fn generate_sequoia_cert_without_private_key(email: &str) -> sequoia_openpgp::Cert { +pub fn generate_sequoia_cert_without_private_key(email: &str) -> Cert { let (cert, _) = CertBuilder::general_purpose(None, Some(email)) .generate() .unwrap();