diff --git a/.github/scripts/tests/apply-code-quality-ruleset.bats b/.github/scripts/tests/apply-code-quality-ruleset.bats index 7b64b2b8..5c3e117e 100644 --- a/.github/scripts/tests/apply-code-quality-ruleset.bats +++ b/.github/scripts/tests/apply-code-quality-ruleset.bats @@ -101,6 +101,7 @@ assert_required_check() { # bypass while de-duplicating the pre-existing OrganizationAdmin (the removal # branch of the merge), so the result is exactly the two required actors. @test "update adds the dependabot bypass when an existing ruleset has OrganizationAdmin but is missing it" { + export GH_TOKEN="mock-token" gh() { if [ "$1" = "api" ]; then if [ "$2" = "repos/petry-projects/markets/rulesets" ]; then @@ -110,7 +111,7 @@ assert_required_check() { echo '[{"actor_type":"OrganizationAdmin","bypass_mode":"always"}]' return 0 elif [ "$2" = "-X" ] && [ "$3" = "PUT" ]; then - cat > "$TEST_TMPDIR/payload.json" + cat > "$BATS_TEST_TMPDIR/payload.json" echo '{}' return 0 fi @@ -122,5 +123,5 @@ assert_required_check() { run bash "$SCRIPT" [ "$status" -eq 0 ] - jq -e '.bypass_actors == [{"actor_type":"OrganizationAdmin","bypass_mode":"always"},{"actor_id":3167543,"actor_type":"Integration","bypass_mode":"always"}]' "$TEST_TMPDIR/payload.json" + jq -e '.bypass_actors == [{"actor_type":"OrganizationAdmin","bypass_mode":"always"},{"actor_id":3167543,"actor_type":"Integration","bypass_mode":"always"}]' "$BATS_TEST_TMPDIR/payload.json" } diff --git a/.github/scripts/tests/shell-tests-workflow.bats b/.github/scripts/tests/shell-tests-workflow.bats new file mode 100644 index 00000000..d231b8e4 --- /dev/null +++ b/.github/scripts/tests/shell-tests-workflow.bats @@ -0,0 +1,50 @@ +#!/usr/bin/env bats +# Tests for .github/workflows/shell-tests.yml — static YAML assertions, +# no live API calls. +# +# Regression guard for issue #447 (unpinned-actions-shell-tests.yml): the +# action-pinning standard requires every third-party action `uses:` ref to be +# pinned to a full commit SHA, not a moving `@vN` tag. shell-tests.yml checked +# out with `actions/checkout@v7`. These tests pin that the checkout step stays +# on a 40-char commit SHA so a future edit reverting to a floating tag is caught. + +WORKFLOW="$(cd "$(dirname "$BATS_TEST_FILENAME")/../../.." && pwd)/.github/workflows/shell-tests.yml" + +@test "workflow file exists" { + [ -f "$WORKFLOW" ] +} + +@test "workflow is valid YAML" { + yq '.' "$WORKFLOW" >/dev/null +} + +@test "every action uses: ref is pinned to a full commit SHA (issue #447)" { + # Every third-party `uses` — step-level and job-level reusable-workflow refs — + # must be owner/repo@<40-hex-sha>; a floating @vN tag fails this. Local actions + # (starting with `./`) need no SHA pin and are skipped. Failures are accumulated + # so a later valid ref can't mask an earlier invalid one. + run yq -r '.jobs[] | ( (.steps[]? | select(has("uses")) | .uses) , (select(has("uses")) | .uses) )' "$WORKFLOW" + [ "$status" -eq 0 ] + [ -n "$output" ] + local failed=0 + while IFS= read -r ref; do + [ -n "$ref" ] || continue + [[ "$ref" =~ ^\./ ]] && continue + [[ "$ref" =~ @[0-9a-f]{40}$ ]] || failed=1 + done <<< "$output" + [ "$failed" -eq 0 ] +} + +@test "checkout step is pinned to a SHA, not a moving tag (issue #447)" { + # Validate every matching checkout step so multiple checkouts can't let one + # unpinned ref slip through; accumulate failures across all output lines. + run yq -r '.jobs.bats.steps[] | select((.uses // "") | test("^actions/checkout@")) | .uses' "$WORKFLOW" + [ "$status" -eq 0 ] + [ -n "$output" ] + local failed=0 + while IFS= read -r ref; do + [ -n "$ref" ] || continue + [[ "$ref" =~ ^actions/checkout@[0-9a-f]{40}$ ]] || failed=1 + done <<< "$output" + [ "$failed" -eq 0 ] +} diff --git a/.github/workflows/shell-tests.yml b/.github/workflows/shell-tests.yml index 105248e5..2c64dced 100644 --- a/.github/workflows/shell-tests.yml +++ b/.github/workflows/shell-tests.yml @@ -29,7 +29,9 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install bats run: sudo npm install -g bats@1.11.1 --ignore-scripts