From aebdbb804b1dfc3e105b1ad3ebecad0eeb789d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 19 Oct 2026 17:23:02 -0300 Subject: [PATCH] test(fips): separate generated policy shell execution --- xCAT-test/bats/fips_policy_artifacts.bats | 39 +++++++++++++++++++++++ xCAT-test/unit/fips_policy_sources.t | 5 --- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 xCAT-test/bats/fips_policy_artifacts.bats diff --git a/xCAT-test/bats/fips_policy_artifacts.bats b/xCAT-test/bats/fips_policy_artifacts.bats new file mode 100644 index 0000000000..2c205a1eef --- /dev/null +++ b/xCAT-test/bats/fips_policy_artifacts.bats @@ -0,0 +1,39 @@ +#!/usr/bin/env bats + +load 'helpers/shell_source' + +setup() +{ + ROOT="$BATS_TEST_TMPDIR/source" + local relative + for relative in build-utils/sync-fips-policy build-utils/fips-policy.sh \ + xCAT-genesis-scripts/usr/lib/xcat/fips.sh xCAT/postscripts/xcatlib.sh; do + mkdir -p "$ROOT/$(dirname "$relative")" + cp "$(repo_path "$relative")" "$ROOT/$relative" + done + printf '\nxcat_policy_probe() { printf canonical; }\n' >>"$ROOT/build-utils/fips-policy.sh" + export RESULT="$BATS_TEST_TMPDIR/result" +} + +check_generated_policy() +{ + local shell="$1" library="$2" + run perl "$ROOT/build-utils/sync-fips-policy" --write + [ "$status" -eq 0 ] + run "$shell" -c ' + exec >"$RESULT" 2>&1 + . "$1" + xcat_policy_probe + ' fips-artifact-test "$ROOT/$library" + [ "$status" -eq 0 ] + printf canonical >"$BATS_TEST_TMPDIR/expected-result" + cmp "$BATS_TEST_TMPDIR/expected-result" "$RESULT" +} + +@test "generated Genesis policy runs in sh" { + check_generated_policy sh xCAT-genesis-scripts/usr/lib/xcat/fips.sh +} + +@test "generated Cumulus policy runs in bash" { + check_generated_policy bash xCAT/postscripts/xcatlib.sh +} diff --git a/xCAT-test/unit/fips_policy_sources.t b/xCAT-test/unit/fips_policy_sources.t index 9ffae71770..70fc141edb 100644 --- a/xCAT-test/unit/fips_policy_sources.t +++ b/xCAT-test/unit/fips_policy_sources.t @@ -44,11 +44,6 @@ is($rc, 0, 'write refreshes both artifacts') or diag($output); for my $relative (@libraries) { is((stat("$root/$relative"))[2] & oct('0777'), $modes{$relative}, "generation preserves the mode of $relative"); - my $shell = $relative eq $libraries[0] ? 'sh' : 'bash'; - ($rc, $output) = run_command($shell, '-c', '. "$1"; xcat_policy_probe', - 'fips-artifact-test', "$root/$relative"); - is($rc, 0, 'the generated artifact provides the updated policy'); - is($output, 'canonical', 'the generated artifact executes canonical content'); } my @rendered = map { scalar read_binary("$root/$_") } @libraries; ($rc, $output) = run_command($^X, "$root/$sync", '--write');