getcap.sh 802 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. start_up
  4. out=out.yaml
  5. cleanup() {
  6. rm -f $out
  7. shut_down
  8. }
  9. trap cleanup EXIT
  10. function yaml_to_list() {
  11. python << pyscript
  12. from __future__ import print_function
  13. import sys
  14. import yaml
  15. with open("$1") as f:
  16. try:
  17. y = yaml.safe_load(f)
  18. print(' '.join(y))
  19. except yaml.YAMLError as exc:
  20. sys.exit(exc)
  21. pyscript
  22. }
  23. tpm2 getcap -l > $out
  24. caplist=$(yaml_to_list $out)
  25. for c in $caplist; do
  26. tpm2 getcap "$c" > $out
  27. yaml_verify $out
  28. done;
  29. # negative tests
  30. trap - ERR
  31. # Regression test, ensure that getcap -c never accepts prefix matches
  32. tpm2 getcap -Q --capability="comma" 2>/dev/null
  33. if [ $? -eq -1 ]; then
  34. echo "Expected \"tpm2 getcap -Q --capability=\"comma\"\" to fail."
  35. exit 1
  36. fi
  37. exit 0