mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-19 17:02:15 +00:00
fa233e6d36
Preserve source modes when staging Debian package builds and accept a private source fixture. Build group-writable profiles under umasks 0022 and 0002, then check the extracted data, postscripts and directories. Verify that staging and packaging leave source permissions unchanged, including a world-writable data file. Reuse the payload checks for normal, reduced and permission-regression builds.
92 lines
4.3 KiB
Perl
92 lines
4.3 KiB
Perl
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
|
|
use FindBin;
|
|
use lib "$FindBin::Bin/../lib";
|
|
use File::Basename qw(dirname);
|
|
use File::Temp qw(tempdir);
|
|
use File::Slurper qw(read_binary);
|
|
use Fcntl qw(S_IMODE);
|
|
use Test::More;
|
|
use XCAT::Test::File qw(repo_path);
|
|
use XCAT::Test::Lifecycle;
|
|
use XCAT::Test::RPM;
|
|
use XCAT::Test::Process qw(run_command);
|
|
|
|
plan skip_all => 'requires Linux package tools' unless $^O eq 'linux';
|
|
die 'run package builds as an unprivileged user' unless $>;
|
|
my $root = tempdir(CLEANUP => 1);
|
|
if (-f '/etc/debian_version') {
|
|
my $deb = XCAT::Test::Lifecycle::build_deb('xCAT-server');
|
|
XCAT::Test::Lifecycle::checked('dpkg-deb', '-x', $deb, $root);
|
|
} else {
|
|
my $rpm = XCAT::Test::RPM->build('xCAT-server', 1);
|
|
XCAT::Test::Lifecycle::checked('bash', '-o', 'pipefail', '-c',
|
|
'cd "$1" && rpm2cpio "$2" | cpio -idm --quiet', 'bash', $root, $rpm);
|
|
}
|
|
my $share = repo_path('xCAT-server/share/xcat');
|
|
my @assets = grep { /riscv64\./ }
|
|
glob "$share/{install,netboot}/{rh,rocky}/*";
|
|
ok(@assets, 'finds the RISC-V profile assets');
|
|
my @ubuntu = glob "$share/{install,netboot}/ubuntu/*.pkglist";
|
|
ok(@ubuntu, 'finds the Ubuntu package lists');
|
|
push @assets, @ubuntu;
|
|
sub check_assets {
|
|
my ($payload, $label, @sources) = @_;
|
|
for my $source (@sources) {
|
|
my $relative = substr($source, length($share) + 1);
|
|
my $delivered = "$payload/opt/xcat/share/xcat/$relative";
|
|
ok(-r $delivered, "$label$relative is readable after extraction") or next;
|
|
is(read_binary($delivered), read_binary($source), "$label$relative retains its complete contents");
|
|
is(sprintf('%04o', S_IMODE((stat($delivered))[2])), $source =~ /\.postinstall$/ ? '0755' : '0644',
|
|
"$label$relative has the packaged permissions");
|
|
}
|
|
}
|
|
check_assets($root, '', @assets);
|
|
my ($status, $output) = run_command($^X,
|
|
repo_path('xCAT-test/unit/profile_customization.t'), "$root/opt/xcat");
|
|
is($status, 0, 'packaged profiles resolve and remain independently customizable') or diag($output);
|
|
|
|
if (!-f '/etc/debian_version') {
|
|
local $ENV{fsm} = 1;
|
|
my $reduced = tempdir(CLEANUP => 1);
|
|
my $rpm = XCAT::Test::RPM->build('xCAT-server', 1);
|
|
XCAT::Test::Lifecycle::checked('bash', '-o', 'pipefail', '-c',
|
|
'cd "$1" && rpm2cpio "$2" | cpio -idm --quiet', 'bash', $reduced, $rpm);
|
|
ok(!-e "$reduced/opt/xcat/share/xcat/install", 'the reduced RPM omits install profiles');
|
|
ok(!-e "$reduced/opt/xcat/share/xcat/netboot/rh", 'the reduced RPM omits RHEL netboot profiles');
|
|
check_assets($reduced, 'reduced RPM: ', glob "$share/netboot/rocky/*.riscv64.*");
|
|
} else {
|
|
my $fixture = tempdir(CLEANUP => 1);
|
|
XCAT::Test::Lifecycle::checked('cp', '-a', repo_path('xCAT-server'), "$fixture/xCAT-server");
|
|
my $profiles = "$fixture/xCAT-server/share/xcat";
|
|
XCAT::Test::Lifecycle::checked('chmod', '-R', 'g+w', "$profiles/install", "$profiles/netboot");
|
|
my $data = 'install/rh/compute.rhels10.riscv64.pkglist';
|
|
my $postinstall = 'netboot/rocky/compute.rocky10.riscv64.postinstall';
|
|
chmod(oct('0666'), "$profiles/$data") == 1 or die "chmod: $!";
|
|
for my $mask ('0022', '0002') {
|
|
subtest "Debian writable sources with umask $mask" => sub {
|
|
my $previous = umask oct($mask);
|
|
my $deb = XCAT::Test::Lifecycle::build_deb('xCAT-server', $fixture);
|
|
umask $previous;
|
|
my $staged = dirname($deb) . '/xCAT-server/share/xcat';
|
|
for my $input ($profiles, $staged) {
|
|
is(sprintf('%04o', S_IMODE((stat("$input/$data"))[2])), '0666',
|
|
'data source permissions survive staging and packaging');
|
|
is(sprintf('%04o', S_IMODE((stat("$input/$postinstall"))[2])), '0775',
|
|
'postinstall source permissions survive staging and packaging');
|
|
}
|
|
my $payload = tempdir(CLEANUP => 1);
|
|
XCAT::Test::Lifecycle::checked('dpkg-deb', '-x', $deb, $payload);
|
|
check_assets($payload, '', @assets);
|
|
for my $path (qw(install install/rh netboot netboot/rocky netboot/ubuntu/genimage)) {
|
|
is(sprintf('%04o', S_IMODE((stat("$payload/opt/xcat/share/xcat/$path"))[2])),
|
|
'0755', "$path remains executable without group or other write access");
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
done_testing();
|