Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests assume daemon is uid 1 #708

Open
oneElectron opened this issue Jul 22, 2023 · 4 comments
Open

Tests assume daemon is uid 1 #708

oneElectron opened this issue Jul 22, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@oneElectron
Copy link
Contributor

oneElectron commented Jul 22, 2023

---- system::tests::test_get_user_and_group_by_id stdout ----
thread 'system::tests::test_get_user_and_group_by_id' panicked at 'assertion failed: `(left == right)`
  left: `"bin"`,
 right: `"daemon"`', src/system/mod.rs:666:13

This is an error that I get when I run cargo test.
Is there any reason that sudo-rs requires the daemon user be uid 1?

Edit:
Here is the link to the relavent test:
https://github.com/memorysafety/sudo-rs/blob/8ef8e70f91df792713eebb59284158561b4b339f/src/system/mod.rs#L661-L673

System

Here is the top of my /etc/passwd:

root:x:0:0::/root:/usr/bin/fish
bin:x:1:1::/:/usr/bin/nologin
daemon:x:2:2::/:/usr/bin/nologin

Here is the /etc/group greped for daemon:

adm:x:999:daemon
bin:x:1:daemon
daemon:x:2:bin

I am currently running a 13 inch M1 Macbook pro running asahi linux (Arch linux ARM).

                   -`                    ___@___ 
                  .o+`                   ------------ 
                 `ooo/                   OS: Arch Linux ARM aarch64 
                `+oooo:                  Host: Apple MacBook Pro (13-inch, M1, 2020) 
               `+oooooo:                 Kernel: 6.3.0-asahi-13-1-edge-ARCH 
               -+oooooo+:                Uptime: 10 hours, 8 mins 
             `/:-:++oooo+:               Packages: 797 (pacman) 
            `/++++/+++++++:              Shell: bash 5.1.16 
           `/++++++++++++++:             Resolution: 2560x1600 
          `/+++ooooooooooooo/`           DE: GNOME 44.3 
         ./ooosssso++osssssso+`          WM: Mutter 
        .oossssso-````/ossssss+`         WM Theme: Adwaita 
       -osssssso.      :ssssssso.        Theme: Adwaita [GTK2/3] 
      :osssssss/        osssso+++.       Icons: Adwaita [GTK2/3] 
     /ossssssss/        +ssssooo/-       Terminal: kgx 
   `/ossssso+/:-        -:/+osssso+-     CPU: (8) @ 2.064GHz 
  `+sso+:-`                 `.-/+oso:    Memory: 3686MiB / 15708MiB 
 `++:.                           `-/+/
 .`                                 `/
@oneElectron oneElectron added the bug Something isn't working label Jul 22, 2023
@pvdrz
Copy link
Collaborator

pvdrz commented Jul 24, 2023

Oh, that's because those tests are run on CI only where uid 1 will be daemon. We could disable those for local runs using the env macro or something similar.

@oneElectron
Copy link
Contributor Author

Ok the env macro sounds nice. I would like to contribute to sudo-rs so maybe I could write fix this myself.
I like to env variable idea but the other option would be to add an #[ignore = "ci"] to the test.

@squell
Copy link
Member

squell commented Jul 26, 2023

Go ahead, if you want to discuss your solution before shooting it in as a PR feel free to do that here.

@oneElectron
Copy link
Contributor Author

oneElectron commented Jul 26, 2023

Currently my preferred solution is to mark any tests that might fail on a local system with #[ignore = "ci"]. In .github/workflows/ci.yaml there must be a -- --include-ignored to any runs of the tests like so:
https://github.com/oneElectron/sudo-rs/blob/4883a282c57f168bc024c7e5c25d9d4f1cc681af/.github/workflows/ci.yaml#L218-L222
and so:
https://github.com/oneElectron/sudo-rs/blob/4883a282c57f168bc024c7e5c25d9d4f1cc681af/.github/workflows/ci.yaml#L258-L262.

Here's an example run of cargo test:

Example run of cargo test
Finished test [unoptimized + debuginfo] target(s) in 2.26s
Running unittests src/lib.rs (target/debug/deps/sudo_rs-6b800e871e882de1)
running 141 tests
test cli::tests::conflicting_arguments ... ok
test cli::tests::chroot ... ok
test cli::tests::directory ... ok
test cli::tests::edit ... ok
test cli::tests::env_variable ... ok
test cli::tests::help ... ok
test cli::tests::login ... ok
test cli::tests::invalid_option ... ok
test cli::tests::first_trailing_env_var_is_not_an_external_arg ... ok
test cli::tests::group ... ok
test cli::tests::no_argument_provided ... ok
test cli::tests::host ... ok
test cli::tests::invalid_option_with_argument ... ok
test cli::tests::mix_env_variables_with_trailing_args_divided_by_hyphens ... ok
test cli::tests::preserve_env_with_var ... ok
test cli::tests::preserve_env_with_several_vars ... ok
test cli::tests::list ... ok
test cli::tests::preserve_groups ... ok
test cli::tests::non_interactive ... ok
test cli::tests::mix_env_variables_with_trailing_args_divided_by_known_flag ... ok
test cli::tests::shell ... ok
test cli::tests::other_user ... ok
test cli::tests::short_preserve_env_with_var_fails ... ok
test cli::tests::several_env_variables ... ok
test cli::tests::trailing_args_hyphens_known_flag ... ok
test cli::tests::shorthand_with_direct_argument ... ok
test cli::tests::stdin ... ok
test cli::tests::trailing_env_vars_are_external_args ... ok
test cli::tests::trailing_args_followed_by_known_flag ... ok
test cli::tests::version ... ok
test cli::tests::validate ... ok
test common::command::test::qualified_paths ... ok
test common::resolve::tests::test_name_or_id ... ok
test common::resolve::tests::test_resolve_path ... ignored, ci
test common::command::test::test_escaped ... ok
test cli::tests::shorthand_with_argument ... ok
test cutils::test::miri_test_str_to_ptr ... ok
test cutils::test::miri_test_os_str_to_ptr ... ok
test cli::tests::single_env_var_declaration ... ok
test cutils::test::test_tty ... ok
test env::environment::tests::test_filtering ... ok
test defaults::test::check ... ok
test cli::tests::shorthand_without_argument ... ok
test common::command::test::test_build_command_and_args ... ok
test env::tests::test_environment_variable_filtering ... ok
test log::simple_logger::tests::test_write_and_flush ... ok
test log::tests::can_construct_logger ... ok
test log::syslog::tests::can_write_to_syslog ... ok
test pam::rpassword::test::miri_test_longpwd ... ok
test pam::rpassword::test::miri_test_read ... ok
test pam::error::test::isomorphy ... ok
test log::simple_logger::tests::test_default_level ... ok
test common::context::tests::test_build_context ... ok
test pam::converse::test::miri_pam_gpt ... ok
test pam::rpassword::test::miri_test_write ... ok
test pam::sys::bindgen_test_layout_group ... ok
test pam::sys::bindgen_test_layout___va_list_tag ... ok
test env::environment::tests::test_tzinfo ... ok
test env::wildcard_match::tests::test_wildcard_match ... ok
test pam::securemem::test::miri_test_wipe ... ok
test pam::securemem::test::miri_test_leaky_cstring ... ok
test pam::sys::bindgen_test_layout_pam_conv ... ok
test pam::sys::bindgen_test_layout_pam_response ... ok
test pam::sys::bindgen_test_layout_pam_modutil_privs ... ok
test pam::sys::bindgen_test_layout_pam_message ... ok
test su::cli::tests::it_parses_arguments ... ok
test pam::sys::bindgen_test_layout_spwd ... ok
test su::cli::tests::it_parses_an_user ... ok
test su::cli::tests::it_parses_combined_options_and_arguments ... ok
test su::cli::tests::it_parses_login ... ok
test su::cli::tests::it_parses_help ... ok
test su::cli::tests::it_parses_command ... ok
test su::cli::tests::it_parses_combined_options ... ok
test su::cli::tests::it_parses_multiple_supplementary_groups ... ok
test pam::sys::bindgen_test_layout_passwd ... ok
test su::cli::tests::it_parses_group ... ok
test su::cli::tests::it_parses_pty ... ok
test su::cli::tests::it_parses_shell ... ok
test su::context::tests::group_as_non_root ... ignored, ci
test su::cli::tests::it_parses_shell_default ... ok
test su::cli::tests::it_parses_supplementary_group ... ok
test su::cli::tests::it_parses_whitelist ... ok
test su::cli::tests::it_parses_whitelist_environment ... ok
test common::resolve::tests::test_resolve_target_user_and_group ... ok
test sudoers::basic_parser::test::comment_test ... ok
test su::context::tests::invalid_shell ... ok
test sudoers::basic_parser::test::comment_test_fail - should panic ... ok
test sudoers::basic_parser::test::lines_test ... ok
test sudoers::basic_parser::test::whitespace_test ... ok
test su::cli::tests::it_parses_version ... ok
test su::context::tests::su_to_root ... ok
test sudoers::policy::test::authority_xlat_test ... ok
test sudoers::policy::test::chdir_test ... ok
test sudoers::test::alias_all_regression - should panic ... ok
test sudoers::test::ambiguous_spec ... ok
test sudoers::test::gh674_at_include_quoted_backslash ... ok
test sudoers::test::defaults_regression - should panic ... ok
test sudoers::test::fuzz_topo_sort7 ... ok
test sudoers::test::hashsign_error - should panic ... ok
test sudoers::test::hashsign_test ... ok
test sudoers::char_stream::test::test_iter ... ok
test sudoers::test::default_set_test ... ok
test sudoers::test::default_multi_test ... ok
test sudoers::test::directive_test ... ok
test sudoers::test::default_bool_test ... ok
test sudoers::test::invalid_directive - should panic ... ok
test sudoers::test::test_topo_fail0 - should panic ... ok
test sudoers::test::include_regression - should panic ... ok
test system::audit::test::secure_open_is_predictable ... ignored, ci
test system::audit::test::test_secure_open_cookie_file ... ignored, ci
test system::interface::test::test_default ... ok
test sudoers::test::test_topo_fail1 - should panic ... ok
test sudoers::test::useralias_underscore_regression ... ok
test system::interface::test::test_unix_group ... ignored, ci
test system::file::lock::tests::test_locking_of_tmp_file ... ok
test sudoers::test::test_topo_positive ... ok
test sudoers::test::test_topo_fail2 - should panic ... ok
test sudoers::test::test_topo_fail5 - should panic ... ok
test system::interface::test::test_unix_user ... ignored, ci
test system::term::tests::open_pty ... ok
test system::tests::killpg_test ... ok
test system::tests::close_the_universe ... ok
test system::term::tests::tcsetpgrp_and_tcgetpgrp_are_consistent ... ok
test system::tests::get_process_start_time ... ok
test system::tests::get_process_tty_device ... ok
test system::tests::except_stdio_is_fine ... ok
test system::tests::test_get_user_and_group_by_id ... ignored, ci
test system::tests::miri_test_group_impl ... ok
test system::tests::pgid_test ... ok
test system::tests::kill_test ... ok
test system::time::tests::test_new_durations_and_times ... ok
test system::time::tests::test_time_ops ... ok
test system::timestamp::tests::can_encode_and_decode ... ok
test system::timestamp::tests::timestamp_record_written_between_works ... ok
test system::timestamp::tests::timestamp_record_matches_works ... ok
test system::timestamp::tests::session_record_file_header_checks ... ok
test system::timestamp::tests::can_create_and_update_valid_file ... ok
test sudoers::test::permission_test ... ok
test system::wait::tests::signals ... ok
test system::wait::tests::no_hang ... ok
test system::wait::tests::exit_status ... ok

test result: ok. 134 passed; 0 failed; 7 ignored; 0 measured; 0 filtered out; finished in 0.15s

     Running unittests bin/su.rs (target/debug/deps/su-52f5efaf8ac1a250)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests bin/sudo.rs (target/debug/deps/sudo-311bf23f21153252)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests bin/visudo.rs (target/debug/deps/visudo-f170490ca1c566e0)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests sudo-rs

running 1 test
test src/sudoers/basic_parser.rs - sudoers::basic_parser (line 12) ... ignored

test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s

EDIT:
Here's a link to a workflow run:
https://github.com/oneElectron/sudo-rs/actions/runs/5673047090

And a link to a codecov report:
https://app.codecov.io/github/oneElectron/sudo-rs/tree/708-add-ci-only-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants