2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-20 09:22:17 +00:00

test(xcat-core): capture the labels the erase of xCAT-selinux leaves behind

Removing the package removes the module, so xcatd_exec_t and
xcat_client_exec_t leave the policy and each file that carried one becomes
unlabeled_t. Measured on xcat162-mn-tmp-286 after dnf remove:

    system_u:object_r:unlabeled_t:s0 /opt/xcat/sbin/xcatd
    system_u:object_r:unlabeled_t:s0 /opt/xcat/bin/xcatclient
    system_u:object_r:unlabeled_t:s0 /opt/xcat/bin/xcatclientnnr

restorecon -n reported all three as pending, and /install kept
public_content_t, which the stock policy does not define for it.

xcat_selinux_package.t asserts the %preun snapshot and the %postun relabel
that an erase needs, guarded for the erase only. 3 of its 64 checks fail on
this commit.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-14 17:33:39 -03:00
parent 8858c2f636
commit d3739aa512
+12 -1
View File
@@ -91,11 +91,22 @@ like(join("\n", @{ $spec->{post} || [] }),
'%post installs the module');
like(join("\n", @{ $spec->{postun} || [] }), qr/^%selinux_modules_uninstall -s targeted xcat$/m,
'%postun removes the module');
# On an erase the module leaves the policy, so each file labelled with one of
# its types becomes unlabeled_t. %preun takes the snapshot that %postun needs
# to relabel them, because %pre does not run on an erase.
like(join("\n", @{ $spec->{preun} || [] }), qr/^%selinux_relabel_pre -s targeted$/m,
'%preun saves the file contexts before the module leaves the policy');
my $postun = join("\n", @{ $spec->{postun} || [] });
like($postun, qr/^%selinux_relabel_post -s targeted$/m,
'%postun relabels the files the removed module had labelled');
like($postun, qr/\[ \$1 -eq 0 \]/,
'... on an erase only, so an upgrade keeps the labels');
my $posttrans = join("\n", @{ $spec->{posttrans} || [] });
like($posttrans, qr/^%selinux_relabel_post -s targeted$/m,
'%posttrans relabels the files whose context changed');
like($posttrans, qr{\brestorecon -R /install\b}, '... and relabels /install');
foreach my $section (qw(pre post postun posttrans)) {
foreach my $section (qw(pre preun post postun posttrans)) {
unlike(join("\n", @{ $spec->{$section} || [] }), qr/\bsetenforce\b|\/etc\/selinux\/config/,
"%$section does not change the SELinux mode");
}