diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9758d035..ff8890dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.58.0 # MSRV steps: - name: Checkout diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2cabe8a0..e2e21b2d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: rust: - - 1.57.0 # MSRV + - 1.58.0 # MSRV steps: - name: Checkout diff --git a/Makefile b/Makefile index 4b50cf33..978f151a 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,9 @@ release : src gresource: glib-compile-resources data/uk.co.grumlimited.authenticator-rs.xml +test: + cargo test + run: gresource cargo run diff --git a/src/ui/edit_account_window.rs b/src/ui/edit_account_window.rs index c97179f9..5cad1a05 100644 --- a/src/ui/edit_account_window.rs +++ b/src/ui/edit_account_window.rs @@ -7,6 +7,7 @@ use glib::Sender; use gtk::prelude::*; use gtk::{Builder, EntryIconPosition, StateFlags}; use log::{debug, warn}; +use regex::Regex; use rqrr::PreparedImage; use rusqlite::Connection; @@ -87,8 +88,9 @@ impl EditAccountWindow { style_context.set_state(StateFlags::INCONSISTENT); result = Err(ValidationError::FieldError("secret".to_owned())); } else { - match Account::generate_time_based_password(secret_value.as_str()) { - Ok(_) => {} + let stripped = Self::strip_secret(&secret_value); + match Account::generate_time_based_password(stripped.as_str()) { + Ok(_) => buffer.set_text(&stripped), Err(_) => { let style_context = input_secret_frame.style_context(); style_context.set_state(StateFlags::INCONSISTENT); @@ -302,4 +304,28 @@ impl EditAccountWindow { .and_then(|account_id| Keyring::upsert(name.as_str(), account_id, secret.as_str())) .unwrap(); } + + /** + * Strips spaces out of string. + */ + fn strip_secret(secret: &str) -> String { + let re = Regex::new(r"\s").unwrap(); + re.replace_all(secret, "").as_ref().to_owned() + } +} + +#[cfg(test)] +mod tests { + use crate::ui::EditAccountWindow; + + #[test] + fn should_strip_non_alphanum() { + assert_eq!("abcd", EditAccountWindow::strip_secret("a b c d")); + assert_eq!("b", EditAccountWindow::strip_secret(" b")); + assert_eq!("c", EditAccountWindow::strip_secret("c ")); + assert_eq!( + "kfai5qjfvbz7u6uu3iqd4n2iajdvtzvg", + EditAccountWindow::strip_secret("kfai 5qjf vbz7 u6uu 3iqd 4n2i ajdv tzvg") + ); + } }