From da0d44062d5187fd738a6468e828892fcc10e452 Mon Sep 17 00:00:00 2001 From: Anton Ekblad Date: Tue, 10 Sep 2024 00:10:28 +0200 Subject: [PATCH] Run clippy and unit tests on push. --- .github/workflows/unit-tests.yml | 23 +++++++++++++++++++++++ src/commands/init.rs | 4 ++-- src/presence_verification/fprintd.rs | 14 +++++++------- 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..125b0fa --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,23 @@ +name: Run unit tests +on: [push] +jobs: + unit-tests: + runs-on: self-hosted + steps: + - run: curl https://sh.rustup.rs -sSf | sh -s -- -y + - name: Check out repo + uses: actions/checkout@v4 + - run: | + . "$HOME/.cargo/env" + cargo test + dbus-run-session cargo test --features=install,dbus-tests + clippy: + runs-on: self-hosted + steps: + - run: curl https://sh.rustup.rs -sSf | sh -s -- -y + - name: Check out repo + uses: actions/checkout@v4 + - run: | + . "$HOME/.cargo/env" + cargo clippy + cargo clippy --features=install,dbus-tests diff --git a/src/commands/init.rs b/src/commands/init.rs index 7121a8f..c19601c 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -177,7 +177,7 @@ mod tests { use super::*; #[test] - fn init_creates_all_necessary_and_files_with_correct_permissions() { + fn init_creates_all_necessary_secrets_and_files_with_correct_permissions() { let swtpm = SwTpm::new(); let dir = tempdir().unwrap(); let cfg_path = dir.path().join("totpm.conf"); @@ -298,6 +298,6 @@ mod tests { } fn get_user_name() -> String { - std::env::var("USER").unwrap_or("root".to_string()) + String::from_utf8(Command::new("whoami").output().unwrap().stdout).unwrap().trim().to_string() } } diff --git a/src/presence_verification/fprintd.rs b/src/presence_verification/fprintd.rs index f1e3805..19c099a 100644 --- a/src/presence_verification/fprintd.rs +++ b/src/presence_verification/fprintd.rs @@ -114,7 +114,7 @@ impl <'a> FprintDevice<'a> { true }).or(fail("fprintd: unable to listen for signal"))?; - self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStart", ("any",)) + self.proxy.method_call::<(), _, _, _>(FPRINTD_DEVICE_IFACE, "VerifyStart", ("any",)) .or(fail("fprintd: unable to start fingerprint verification"))?; eprintln!("place your finger on the fingerprint reader"); @@ -129,15 +129,15 @@ impl <'a> FprintDevice<'a> { if let Some(status) = *scan_status_clone.lock().unwrap() { match status { Status::Match => { - self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) + self.proxy.method_call::<(), _, _, _>(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) .or(fail("fprintd: unable to stop fingerprint verification"))?; return Ok(true) }, Status::NoMatch => { eprintln!("fingerprint not recognized, try again"); - self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) + self.proxy.method_call::<(), _, _, _>(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) .or(fail("fprintd: unable to stop fingerprint verification"))?; - self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStart", ("any",)) + self.proxy.method_call::<(), _, _, _>(FPRINTD_DEVICE_IFACE, "VerifyStart", ("any",)) .or(fail("fprintd: unable to restart fingerprint verification"))?; }, Status::RetryScan | Status::SwipeTooShort | Status::FingerNotCentered | Status::RemoveAndRetry => { @@ -148,7 +148,7 @@ impl <'a> FprintDevice<'a> { return fail("fprintd: fingerprint reader disconnected") }, Status::UnknownError => { - self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) + self.proxy.method_call::<(), _, _, _>(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) .or(fail("fprintd: unable to stop fingerprint verification"))?; return fail("fprintd: fingerprint scan failed with unknown error") }, @@ -156,7 +156,7 @@ impl <'a> FprintDevice<'a> { } } - self.proxy.method_call(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) + self.proxy.method_call::<(), _, _, _>(FPRINTD_DEVICE_IFACE, "VerifyStop", ()) .or(fail("fprintd: unable to stop fingerprint verification"))?; Ok(false) } @@ -175,7 +175,7 @@ impl <'a> FprintDevice<'a> { device_path, Duration::from_secs(10), ); - proxy.method_call(FPRINTD_DEVICE_IFACE, "Claim", ("",)) + proxy.method_call::<(), _, _, _>(FPRINTD_DEVICE_IFACE, "Claim", ("",)) .or(Err(super::Error::ImplementationSpecificError("fprintd: unable to claim device".to_owned())))?; Ok(FprintDevice { proxy, connection: conn }) }