Skip to content

Commit

Permalink
DAOS-14726 build: Handle corner case… (#13472)
Browse files Browse the repository at this point in the history
Of not erroneously matching commit pragmas that are part of the
patch description when they occur quoted at the start of a line. For
example:
 'Skip-checkpatch: true' should not be considered a commit pragma.
Unfortunately
 Skip-checkpatch: true would be considered a commit pragma because
the missing quotes around it (and it being at the beginning of the line)
eliminate the only means we have of trying to determine that it's not
really a commit pragma. Unfortunately we cannot use spaces in the
value as an indicator that it's a pragma because we have pragmas that
allow space separated values such as Test-tag.

Also limit the characters that can be in a commit pragma to prevent
command injection attempts such as:

 Hacking-attempt: true;evil_command

Add a step to show the found commit pragmas.

Add unit-testing for gha_functions.sh.

Signed-off-by: Brian J. Murrell <[email protected]>
  • Loading branch information
brianjmurrell authored Dec 14, 2023
1 parent 266f84a commit d53892d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/bash_unit_testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: bash Unit Testing

on:
push:
pull_request:

concurrency:
group: bash-unit-test-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

defaults:
run:
shell: bash --noprofile --norc -ueo pipefail {0}

jobs:
Test-gha-functions:
name: Tests in ci/gha_functions.sh
runs-on: [self-hosted, light]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout bash_unit project
uses: actions/checkout@v4
with:
repository: 'pgrange/bash_unit'
path: bash_unit
- name: Unit testing with bash_unit
run: FORCE_COLOR=true ./bash_unit/bash_unit ci/gha_functions.sh
3 changes: 3 additions & 0 deletions .github/workflows/rpm-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ jobs:
echo "text<<EOF" >> $GITHUB_OUTPUT;
git show -s --format=%B | escape_single_quotes >> $GITHUB_OUTPUT;
echo "EOF" >> $GITHUB_OUTPUT;
- name: Identify Commit Pragmas
run: . ci/gha_functions.sh;
echo '${{steps.dequoted_commit_message.outputs.text }}' | get_commit_pragmas

Import-commit-pragmas:
name: Make commit pragma variables
Expand Down
19 changes: 12 additions & 7 deletions ci/gha_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ get_test_tags() {


get_commit_pragmas() {
sed -ne '/^[^ ]*: */s/\([^:]*\): *\(.*\)/\1 \2/p' | while read -r a b; do
sed -Ene 's/^([-[:alnum:]]+): *([-\._ [:alnum:]]+)$/\1 \2/p' | while read -r a b; do
echo -n "${a//-/_}" | tr '[:lower:]' '[:upper:]'
# escape special characters in the value
echo "=$b" | sed -e 's/\([<> ]\)/\\\1/g'
Expand Down Expand Up @@ -240,7 +240,7 @@ Stage Name: $stage_name\" > /root/job_info


# This is run under the unit test framework at https://github.com/pgrange/bash_unit/
# I.e. ../bash_unit/bash_unit ci/gha_functions.sh ci/gha_functions.sh
# I.e. ../bash_unit/bash_unit ci/gha_functions.sh
test_test_tag_and_features() {
# Simple Test-tag: test
assert_equals "$(CP_TEST_TAG="always_passes always_fails" get_test_tags "-hw")" "always_passes,-hw always_fails,-hw"
Expand All @@ -257,7 +257,12 @@ test_test_tag_and_features() {
test_get_commit_pragmas() {
local msg='Escape spaces also
'"'"'Will-not-be-a-pragma: false'"'"' should not be considered a commit
pragma, but:
Should-not-be-a-pragma: bar will be because it was not quoted.
Skip-func-test-leap15: false
RPM-test-version: 2.5.100-13.10036.g65926e32
Skip-PR-comments: true
Test-tag: always_passes always_fails
EL8-VM9-label: all_vm9
Expand All @@ -270,21 +275,21 @@ Required-githooks: true
Signed-off-by: Brian J. Murrell <[email protected]>
'
assert_equals "$(echo "$msg" | get_commit_pragmas)" 'SKIP_FUNC_TEST_LEAP15=false
assert_equals "$(echo "$msg" | get_commit_pragmas)" 'SHOULD_NOT_BE_A_PRAGMA=bar\ will\ be\ because\ it\ was\ not\ quoted.
SKIP_FUNC_TEST_LEAP15=false
RPM_TEST_VERSION=2.5.100-13.10036.g65926e32
SKIP_PR_COMMENTS=true
TEST_TAG=always_passes\ always_fails
EL8_VM9_LABEL=all_vm9
EL9_VM9_LABEL=all_vm9
LEAP15_VM9_LABEL=all_vm9
HW_MEDIUM_LABEL=new_icx5
HW_LARGE_LABEL=new_icx9
REQUIRED_GITHOOKS=true
SIGNED_OFF_BY=Brian\ J.\ Murrell\ \<[email protected]\>'
REQUIRED_GITHOOKS=true'

}

test_jenkins_curl() {
JENKINS_URL="${JENKINS_URL:-https://build.hpdd.intel.com/}"
assert_equals "$(QUIET=true VERBOSE=false jenkins_curl -X POST "${JENKINS_URL}api/xml" 3>&1 >/dev/null | grep '^X-Content-Type-Options:')" "X-Content-Type-Options: nosniff
"
assert_equals "$(QUIET=true VERBOSE=false jenkins_curl -X POST "${JENKINS_URL}api/xml" 3>&1 >/dev/null | tr -d '\r' | grep '^X-Content-Type-Options:')" "X-Content-Type-Options: nosniff"
}

0 comments on commit d53892d

Please sign in to comment.