From e83b92b1c3d8a5a0d7443452c0f5162396752ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Mart=C3=ADn?= Date: Wed, 28 Feb 2024 19:19:09 +0100 Subject: [PATCH] fix: do not run tests that require root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not run tests that require root. The tests requiring superuser privileges are marked as ignored and will display a message on how to actually run those tests, this is with: ``` [root@localhost]# cargo test -- --ignored ``` An additional test is added to check the effective user is actually root before trying to run the commands. Signed-off-by: Miguel Martín --- .github/workflows/ci.yml | 6 +++--- client-linuxapp/src/serviceinfo.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 265104c38..2040fbc7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -193,9 +193,9 @@ jobs: run: | docker run -d -v `pwd`:/code:z --workdir /code --user root -e SQLITE_MANUFACTURER_DATABASE_URL='../ci-manufacturer-db.sqlite' -e SQLITE_OWNER_DATABASE_URL='../ci-owner-db.sqlite' -e SQLITE_RENDEZVOUS_DATABASE_URL='../ci-rendezvous-db.sqlite' --name tests devcontainer-fdo-rs sleep infinity docker exec --user root tests cargo build --lib --bins --workspace --verbose - docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_manufacturing_server_sqlite --database-url ./ci-manufacturer-db.sqlite - docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_owner_onboarding_server_sqlite --database-url ./ci-owner-db.sqlite + docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_manufacturing_server_sqlite --database-url ./ci-manufacturer-db.sqlite + docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_owner_onboarding_server_sqlite --database-url ./ci-owner-db.sqlite docker exec --user root tests diesel migration run --migration-dir ./migrations/migrations_rendezvous_server_sqlite --database-url ./ci-rendezvous-db.sqlite - docker exec --user root tests cargo test + docker exec --user root tests cargo test -- --ignored docker stop tests docker rm tests diff --git a/client-linuxapp/src/serviceinfo.rs b/client-linuxapp/src/serviceinfo.rs index c26df0289..893d5f917 100644 --- a/client-linuxapp/src/serviceinfo.rs +++ b/client-linuxapp/src/serviceinfo.rs @@ -838,6 +838,7 @@ mod test { use super::BinaryFileInProgress; use crate::serviceinfo::*; + use fdo_util::system_info::{get_current_user_id, get_root_user_id}; #[test] fn test_binaryfileinprogress_destination_path() { @@ -870,7 +871,11 @@ mod test { } #[test] + #[ignore = "to run this test you must be root and run `cargo test -- --ignored`"] fn test_user_creation_no_pw() { + let current_user_id = get_current_user_id(); + let root_user_id = get_root_user_id(); + assert_eq!(current_user_id, root_user_id); let test_user = "test"; assert!(create_user(test_user).is_ok()); let empty_user = ""; @@ -884,7 +889,11 @@ mod test { } #[test] + #[ignore = "to run this test you must be root and run `cargo test -- --ignored`"] fn test_user_creation_with_pw() { + let current_user_id = get_current_user_id(); + let root_user_id = get_root_user_id(); + assert_eq!(current_user_id, root_user_id); let test_user = "testb"; let test_password = "password"; assert!(create_user_with_password(test_user, test_password).is_ok());