From: Frantisek Sumsal Date: Wed, 25 Oct 2023 15:42:07 +0000 (+0200) Subject: test: add a couple more tests for systemd-pcrextend X-Git-Tag: v255-rc1~139^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=af70e2021ed228a6a001ed21f956d8870b7d9f0d;p=thirdparty%2Fsystemd.git test: add a couple more tests for systemd-pcrextend --- diff --git a/test/test-functions b/test/test-functions index 60db47c86aa..b659c98529c 100644 --- a/test/test-functions +++ b/test/test-functions @@ -169,6 +169,7 @@ BASICTOOLS=( echo env false + findmnt flock getconf getent @@ -188,6 +189,7 @@ BASICTOOLS=( login losetup lsattr + lsblk lz4cat mkfifo mknod diff --git a/test/units/testsuite-70.pcrextend.sh b/test/units/testsuite-70.pcrextend.sh index cae2d28fd99..318fce02a16 100755 --- a/test/units/testsuite-70.pcrextend.sh +++ b/test/units/testsuite-70.pcrextend.sh @@ -23,6 +23,41 @@ at_exit() { trap at_exit EXIT +# Temporarily override sd-pcrextend's sanity checks +export SYSTEMD_FORCE_MEASURE=1 + +"$SD_PCREXTEND" --help +"$SD_PCREXTEND" --version +"$SD_PCREXTEND" foo +"$SD_PCREXTEND" --machine-id +"$SD_PCREXTEND" --tpm2-device=list +"$SD_PCREXTEND" --tpm2-device=auto foo +"$SD_PCREXTEND" --tpm2-device=/dev/tpm0 foo +"$SD_PCREXTEND" --bank=sha256 foo +"$SD_PCREXTEND" --bank=sha256 --bank=sha256 foo +"$SD_PCREXTEND" --graceful foo +"$SD_PCREXTEND" --pcr=15 foo +"$SD_PCREXTEND" --file-system=/ +"$SD_PCREXTEND" --file-system=/tmp --file-system=/ +"$SD_PCREXTEND" --file-system=/tmp --file-system=/ --pcr=15 --pcr=11 + +if tpm_has_pcr sha1 11; then + "$SD_PCREXTEND" --bank=sha1 --pcr=11 foo +fi + +(! "$SD_PCREXTEND") +(! "$SD_PCREXTEND" "") +(! "$SD_PCREXTEND" foo bar) +(! "$SD_PCREXTEND" --bank= foo) +(! "$SD_PCREXTEND" --tpm2-device= foo) +(! "$SD_PCREXTEND" --tpm2-device=/dev/null foo) +(! "$SD_PCREXTEND" --pcr= foo) +(! "$SD_PCREXTEND" --pcr=-1 foo) +(! "$SD_PCREXTEND" --pcr=1024 foo) +(! "$SD_PCREXTEND" --foo=bar) + +unset SYSTEMD_FORCE_MEASURE + # Note: since we're reading the TPM event log as json-seq, the same rules apply to the output # as well, i.e. each record is prefixed by RS (0x1E, 036) and suffixed by LF (0x0A, 012). # LF is usually eaten by bash, but RS needs special handling. @@ -73,4 +108,17 @@ DIGEST_EXPECTED="$(echo -n "foobar" | openssl dgst -hex -sha256 -r)" DIGEST_CURRENT="$(jq --seq --slurp --raw-output ".[$RECORD_COUNT].digests[] | select(.hashAlg == \"sha256\").digest"