From 75f2c0c7b80f9b12314ce9b7cdc4efea4be59c05 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Wed, 9 Oct 2024 22:26:11 +0100 Subject: [PATCH] tests: ensure vim syntax and abi are set on all profile/abs. --- tests/check.sh | 51 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/check.sh b/tests/check.sh index 5704ebfb..a46d38e3 100644 --- a/tests/check.sh +++ b/tests/check.sh @@ -10,12 +10,38 @@ set -eu -o pipefail readonly APPARMORD="apparmor.d" +_ensure_include() { + local file="$1" + local include="$2" + if ! grep -q "^ *${include}$" "$file"; then + echo "$file does not contain '$include'" + exit 1 + fi +} + +_ensure_abi() { + local file="$1" + if ! grep -q "^ *abi ," "$file"; then + echo "$file does not contain 'abi ,'" + exit 1 + fi +} + +_ensure_vim() { + local file="$1" + if ! grep -q "^# vim:syntax=apparmor" "$file"; then + echo "$file does not contain '# vim:syntax=apparmor'" + exit 1 + fi +} + check_profiles() { echo "⋅ Checking if all profiles contain:" echo " - 'abi ,'" - echo " - 'profile *profile_name* {'" + echo " - 'profile '" echo " - 'include if exists '" echo " - include if exists local for subprofiles" + echo " - vim:syntax=apparmor" directories=("$APPARMORD/groups/*" "$APPARMORD/profiles-*-*") # shellcheck disable=SC2068 for dir in ${directories[@]}; do @@ -24,14 +50,9 @@ check_profiles() { name="$(basename "$file")" name="${name/.apparmor.d/}" include="include if exists " - if ! grep -q "^ *${include}$" "$file"; then - echo "$name does not contain '$include'" - exit 1 - fi - if ! grep -q "^ *abi ," "$file"; then - echo "$name does not contain 'abi ,'" - exit 1 - fi + _ensure_include "$file" "$include" + _ensure_abi "$file" + _ensure_vim "$file" if ! grep -q "^profile $name" "$file"; then echo "$name does not contain 'profile $name'" exit 1 @@ -52,6 +73,7 @@ check_abstractions() { echo "⋅ Checking if all abstractions contain:" echo " - 'abi ,'" echo " - 'include if exists '" + echo " - vim:syntax=apparmor" directories=( "$APPARMORD/abstractions/" "$APPARMORD/abstractions/app/" "$APPARMORD/abstractions/bus/" "$APPARMORD/abstractions/common/" @@ -61,14 +83,9 @@ check_abstractions() { name="$(basename "$file")" root="${dir/${APPARMORD}\/abstractions\//}" include="include if exists " - if ! grep -q "^ *${include}$" "$file"; then - echo "$file does not contain '$include'" - exit 1 - fi - # if ! grep -q "^ *abi ," "$file"; then - # echo "$file does not contain 'abi ,'" - # exit 1 - # fi + _ensure_include "$file" "$include" + _ensure_abi "$file" + _ensure_vim "$file" done done