Skip to content

Commit

Permalink
tests: Strengthen SELinux runtime check
Browse files Browse the repository at this point in the history
/sys/fs/selinux will also exist on e.g. Debian containers running on a
Fedora host. We don't see that in CI as that runs on Ubuntu, but it
breaks local runs.

So instead check if the `selinuxenabled` command is available.
  • Loading branch information
martinpitt committed Mar 9, 2024
1 parent 570b58e commit aae80c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions tests/test-umockdev-run.vala
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ A: size=1048576\n

#if HAVE_SELINUX
// we may run on a system without SELinux
if (FileUtils.test("/sys/fs/selinux", FileTest.EXISTS)) {
try {
Process.spawn_command_line_sync ("command -v selinuxenabled", null, null, out exit);
} catch (SpawnError e) {
exit = 1;
}
if (exit == 0) {
check_program_out("true", "-d " + umockdev_file + " -- stat -c %C /dev/loop23",
"system_u:object_r:fixed_disk_device_t:s0\n");
} else {
Expand Down Expand Up @@ -352,7 +357,12 @@ t_run_record_null ()

#if HAVE_SELINUX
// we may run on a system without SELinux
if (FileUtils.test("/sys/fs/selinux", FileTest.EXISTS)) {
try {
Process.spawn_command_line_sync ("command -v selinuxenabled", null, null, out exit);
} catch (SpawnError e) {
exit = 1;
}
if (exit == 0) {
string orig_context;
assert_cmpint (Selinux.lgetfilecon ("/dev/null", out orig_context), CompareOperator.GT, 0);
check_program_out("true", "-d " + umockdev_file + " -- stat -c %C /dev/null", orig_context + "\n");
Expand Down
8 changes: 7 additions & 1 deletion tests/test-umockdev-vala.vala
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ t_testbed_fs_ops ()
void
t_testbed_selinux ()
{
if (!FileUtils.test("/sys/fs/selinux", FileTest.EXISTS)) {
int exit;
try {
Process.spawn_command_line_sync ("command -v selinuxenabled", null, null, out exit);
} catch (SpawnError e) {
exit = 1;
}
if (exit != 0) {
stdout.printf ("[SKIP SELinux not active]\n");
return;
}
Expand Down

0 comments on commit aae80c2

Please sign in to comment.