Skip to content

Commit

Permalink
Only run tests as non root user
Browse files Browse the repository at this point in the history
root is able to always write to a file independent of its permissions.
Therefore the tests will fail as root.
  • Loading branch information
bjoernricks committed Feb 12, 2025
1 parent 48a8cf9 commit a07b965
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions base/logging_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ Ensure (logging, validate_check_log_file)
assert_that (g_remove ("some-dir/some-file.log"), is_equal_to (0));
assert_that (g_rmdir ("some-dir"), is_equal_to (0));

assert_that (g_mkdir_with_parents ("some-dir", 0700), is_equal_to (0));
assert_that (g_creat ("some-dir/some-file.log", 0400), is_not_equal_to (-1));
assert_that (check_log_file (log_domain_entry), is_equal_to (-1));
assert_that (g_chmod ("some-dir/some-file.log", 0700), is_equal_to (0));
assert_that (g_remove ("some-dir/some-file.log"), is_equal_to (0));
assert_that (g_rmdir ("some-dir"), is_equal_to (0));

if (getuid () != 0)
{
/* root can always write. therefore test writing to a non-writable file as
* non-root user only */
assert_that (g_mkdir_with_parents ("some-dir", 0700), is_equal_to (0));
assert_that (g_creat ("some-dir/some-file.log", 0400),

Check warning on line 55 in base/logging_tests.c

View check run for this annotation

Codecov / codecov/patch

base/logging_tests.c#L54-L55

Added lines #L54 - L55 were not covered by tests
is_not_equal_to (-1));
assert_that (check_log_file (log_domain_entry), is_equal_to (-1));
assert_that (g_chmod ("some-dir/some-file.log", 0700), is_equal_to (0));
assert_that (g_remove ("some-dir/some-file.log"), is_equal_to (0));
assert_that (g_rmdir ("some-dir"), is_equal_to (0));

Check warning on line 60 in base/logging_tests.c

View check run for this annotation

Codecov / codecov/patch

base/logging_tests.c#L57-L60

Added lines #L57 - L60 were not covered by tests
}
gvm_logging_domain_free (log_domain_entry);
}

Expand Down

0 comments on commit a07b965

Please sign in to comment.