-
Notifications
You must be signed in to change notification settings - Fork 1
IBX-12028: Refactored composer audit ignore to rely on shared source of truth #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alongosz
wants to merge
5
commits into
main
Choose a base branch
from
ibx-12028-ci-advisories-patch-revamp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
54886cc
Extracted composer audit configuration for reusability
alongosz cd5fb61
Refactored composer audit ignore to rely on shared source of truth
alongosz 3e85545
[Tests] Added coverage for ./bin/_common/configure_composer_audit_ign…
alongosz 7ce7f62
Parametrized ci-scripts ref for nested script fetches
alongosz d5ed104
[Tests] Added coverage for CI_SCRIPTS_REF propagation
alongosz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| add_audit_ignores() { | ||
| local reason=$1 | ||
| shift | ||
|
|
||
| local advisory | ||
| for advisory in "$@"; do | ||
| composer config audit.ignore --json --merge "{\"${advisory}\":\"${reason}\"}" | ||
| done | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| PHP74_ADVISORIES=( | ||
| PKSA-xwpn-zs9j-6wy5 | ||
| PKSA-sf9j-1gs7-xzvx | ||
| PKSA-7h5p-prw9-w5nr | ||
| ) | ||
|
|
||
| PHP7X_PHP80_ADVISORIES=( | ||
| PKSA-5k7f-wvjj-jrgw | ||
| PKSA-sjvz-tbbr-vwth | ||
| PKSA-h8hf-ytnd-5t9q | ||
| PKSA-wwb1-81rc-pd65 | ||
| PKSA-hgmw-wn4d-hpcy | ||
| PKSA-kvv6-36cr-fkzb | ||
| PKSA-n14z-jjjg-g8vd | ||
| PKSA-3mcc-k66d-pydb | ||
| PKSA-gw7n-z4yx-7xjt | ||
| PKSA-dpx1-78wg-1kqs | ||
| PKSA-21g2-dzjv-sky5 | ||
| PKSA-v3kg-5xkr-pykw | ||
| PKSA-yhcn-xrg3-68b1 | ||
| PKSA-2wrf-1xmk-1pky | ||
| PKSA-6319-ffpf-gx66 | ||
| PKSA-n7sg-8f52-pqtf | ||
| PKSA-8kk8-h2xr-h5nx | ||
| PKSA-2rbx-bjdx-4d4d | ||
| PKSA-fs5b-x5k4-1h39 | ||
| PKSA-fbvq-z33h-r2np | ||
| PKSA-g9zw-qxh8-pq8w | ||
| PKSA-yd6k-t2gh-1m43 | ||
| PKSA-1tmc-rt7x-12w6 | ||
| PKSA-xx6c-6d96-db2w | ||
| PKSA-8zx5-v2nz-58pb | ||
| ) | ||
|
|
||
| PHP_VERSION_INPUT=${1:-$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')} | ||
| IFS=. read -r PHP_MAJOR_VERSION PHP_MINOR_VERSION _ <<< "$PHP_VERSION_INPUT" | ||
| PHP_VERSION=${PHP_MAJOR_VERSION}.${PHP_MINOR_VERSION} | ||
|
|
||
| if [[ "$PHP_VERSION" = "7.4" ]]; then | ||
| add_audit_ignores \ | ||
| "The affected version of 3rd party component is installed on PHP 7.4. There is no alternative supporting PHP 7.4. Consider upgrading to PHP 8.1+" \ | ||
| "${PHP74_ADVISORIES[@]}" | ||
| fi | ||
|
|
||
| if [[ "$PHP_VERSION" = "7.3" ]] || [[ "$PHP_VERSION" = "7.4" ]] || [[ "$PHP_VERSION" = "8.0" ]]; then | ||
| add_audit_ignores \ | ||
| "The affected version of 3rd party component is installed on PHP ${PHP_VERSION}. There is no alternative supporting PHP ${PHP_VERSION}. Consider upgrading to PHP 8.1+" \ | ||
| "${PHP7X_PHP80_ADVISORIES[@]}" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Verifies that add_composer_audit_ignore_config() fetches | ||
| # configure_composer_audit_ignores.sh from the ref given by CI_SCRIPTS_REF, | ||
| # defaulting to `main` when the variable is unset. | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) | ||
| SCRIPT=${ROOT_DIR}/bin/_common/composer_audit_ignore.sh | ||
| TEST_DIR=$(mktemp -d) | ||
| CURL_URLS_OUTPUT=${TEST_DIR}/curl-urls | ||
| export CURL_URLS_OUTPUT | ||
|
|
||
| cleanup() { | ||
| rm -rf "$TEST_DIR" | ||
| return 0 | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| # Fake `docker`: emulate `docker exec [-e VAR]... <container> bash -c <script>` | ||
| # by running the heredoc body locally. Env vars forwarded via -e are already | ||
| # inherited from this process, which is exactly the value CI_SCRIPTS_REF holds. | ||
| cat > "${TEST_DIR}/docker" <<'EOF' | ||
| #!/bin/bash | ||
| while [ "$#" -gt 0 ] && [ "$1" != "bash" ]; do | ||
| shift | ||
| done | ||
| # now: $1=bash $2=-c $3=<script> | ||
| shift 2 | ||
| # Neutralise the container-only `cd /var/www`; irrelevant to the URL under test. | ||
| exec bash -c "cd() { return 0; }; $1" | ||
| EOF | ||
| chmod +x "${TEST_DIR}/docker" | ||
|
|
||
| # Fake `curl`: record the requested URL and drop a no-op script at --output | ||
| # so the caller's subsequent `bash "$script"` succeeds. | ||
| cat > "${TEST_DIR}/curl" <<'EOF' | ||
| #!/bin/bash | ||
| url="" | ||
| out="" | ||
| while [ "$#" -gt 0 ]; do | ||
| case "$1" in | ||
| --output) out="$2"; shift 2 ;; | ||
| -*) shift ;; | ||
| *) url="$1"; shift ;; | ||
| esac | ||
| done | ||
| printf '%s\n' "$url" >> "$CURL_URLS_OUTPUT" | ||
| if [ -n "$out" ]; then | ||
| printf '#!/bin/bash\n' > "$out" | ||
| fi | ||
| EOF | ||
| chmod +x "${TEST_DIR}/curl" | ||
|
|
||
| run_with_ref() { | ||
| : > "$CURL_URLS_OUTPUT" | ||
| ( | ||
| PATH="${TEST_DIR}:${PATH}" | ||
| if [[ "$#" -eq 1 ]]; then | ||
| export CI_SCRIPTS_REF="$1" | ||
| else | ||
| unset CI_SCRIPTS_REF | ||
| fi | ||
| # shellcheck disable=SC1090 | ||
| source "$SCRIPT" | ||
| add_composer_audit_ignore_config | ||
| ) | ||
| return 0 | ||
| } | ||
|
|
||
| assert_url_contains() { | ||
| local needle=$1 | ||
| if ! grep -qF "$needle" "$CURL_URLS_OUTPUT"; then | ||
| echo "Expected fetched URL to contain '${needle}', got:" >&2 | ||
| cat "$CURL_URLS_OUTPUT" >&2 | ||
| exit 1 | ||
| fi | ||
| return 0 | ||
| } | ||
|
|
||
| # Explicit ref is honoured. | ||
| run_with_ref "my-feature-branch" | ||
| assert_url_contains "/ci-scripts/my-feature-branch/bin/_common/configure_composer_audit_ignores.sh" | ||
|
|
||
| # Unset ref falls back to main. | ||
| run_with_ref | ||
| assert_url_contains "/ci-scripts/main/bin/_common/configure_composer_audit_ignores.sh" | ||
|
|
||
| echo "composer_audit_ignore_ref_test.sh: OK" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
| set -o pipefail | ||
|
|
||
| ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) | ||
| SCRIPT=${ROOT_DIR}/bin/_common/configure_composer_audit_ignores.sh | ||
| TEST_DIR=$(mktemp -d) | ||
| OUTPUT=${TEST_DIR}/composer-calls | ||
|
|
||
| cleanup() { | ||
| rm -rf "$TEST_DIR" | ||
| return 0 | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| cat > "${TEST_DIR}/composer" <<'EOF' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >> "$COMPOSER_CALLS_OUTPUT" | ||
| if [ "${COMPOSER_FAILURE:-0}" = "1" ]; then | ||
| exit 1 | ||
| fi | ||
| EOF | ||
| chmod +x "${TEST_DIR}/composer" | ||
|
|
||
| run_for_version() { | ||
| local version=$1 | ||
| : > "$OUTPUT" | ||
| COMPOSER_CALLS_OUTPUT=$OUTPUT PATH="${TEST_DIR}:${PATH}" bash "$SCRIPT" "$version" | ||
| return 0 | ||
| } | ||
|
|
||
| assert_line_count() { | ||
| local expected=$1 | ||
| local actual | ||
| actual=$(wc -l < "$OUTPUT") | ||
|
|
||
| if [[ "$actual" -ne "$expected" ]]; then | ||
| echo "Expected ${expected} Composer calls, got ${actual}" >&2 | ||
| exit 1 | ||
| fi | ||
| return 0 | ||
| } | ||
|
|
||
| run_for_version 7.3 | ||
| assert_line_count 25 | ||
| ! grep -q PKSA-xwpn-zs9j-6wy5 "$OUTPUT" | ||
|
|
||
| run_for_version 7.4.33 | ||
| assert_line_count 28 | ||
| grep -q PKSA-xwpn-zs9j-6wy5 "$OUTPUT" | ||
| grep -q PKSA-8zx5-v2nz-58pb "$OUTPUT" | ||
|
|
||
| run_for_version 8.0 | ||
| assert_line_count 25 | ||
| ! grep -q PKSA-xwpn-zs9j-6wy5 "$OUTPUT" | ||
|
|
||
| run_for_version 8.1 | ||
| assert_line_count 0 | ||
|
|
||
| if COMPOSER_CALLS_OUTPUT=$OUTPUT PATH="${TEST_DIR}:${PATH}" COMPOSER_FAILURE=1 bash "$SCRIPT" 7.3; then | ||
| echo 'Expected a Composer failure to be propagated' >&2 | ||
| exit 1 | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
L52 looks a bit redundant, but it comes from script's optional input parameter
${1}, which is a PHP version passed by GHA as${{ inputs.php-version }}. Seems it can containmajor.minor.patch(depending on what produced that input).