Skip to content

Commit

Permalink
fix: do not run tests that require root
Browse files Browse the repository at this point in the history
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 <mmartinv@redhat.com>
  • Loading branch information
mmartinv committed Feb 29, 2024
1 parent de91f63 commit 1450941
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions client-linuxapp/src/serviceinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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());
Expand Down

0 comments on commit 1450941

Please sign in to comment.