test 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. shellfu import preupg
  3. shellfu import preupg_fupath
  4. shellfu import xcase
  5. shellfu import jat_dump
  6. #shellcheck disable=SC2034
  7. PREUPG__RULE=xccdf_preupg_rule_api_logging_check
  8. assert_msg_like() {
  9. #
  10. # Assert log message matching $1 exists
  11. #
  12. preupg__get_messages > msgs
  13. jat__cmd grep "$1" msgs
  14. }
  15. xcase__enum() {
  16. #
  17. # Enumerate subtest ids
  18. #
  19. xcase__permute lang py sh \
  20. | xcase__per fn log_debug log_info log_warning log_error \
  21. | xcase__per debug true false
  22. }
  23. #shellcheck disable=SC2154
  24. xcase__setup() {
  25. #
  26. # Prepare for subtest
  27. #
  28. local maybe_debug=""
  29. $debug && maybe_debug="--debug"
  30. echo "message$(head -c 1000 /dev/urandom | md5sum | head -c 7)" >t_message
  31. {
  32. echo "[MODULE]"
  33. echo "GROUP = api"
  34. echo "NAME = logging"
  35. echo "LANG = $lang"
  36. case $lang in
  37. sh)
  38. echo "CODE = $fn $(<t_message)"
  39. echo "CODE = exit_informational"
  40. ;;
  41. py)
  42. echo "CODE = $fn('$(<t_message)')"
  43. echo "CODE = exit_informational()"
  44. ;;
  45. esac
  46. } > module.mdef
  47. preupg_fupath RHEL6_7 module.mdef
  48. PREUPG__UPATH="RHEL6_7/all-xccdf.xml" \
  49. preupg__run1 $maybe_debug --skip-common
  50. }
  51. xcase__test() {
  52. #
  53. # Do the work
  54. #
  55. # set oracles
  56. #
  57. local o_severity=""
  58. local o_msgnum=0
  59. local o_result=informational
  60. local o_not=""
  61. case $fn:$debug in
  62. log_debug:true) o_msgnum=1; o_severity=DEBUG ;;
  63. log_debug:false) o_msgnum=0; o_severity=DEBUG ;;
  64. log_info:*) o_msgnum=1; o_severity=INFO ;;
  65. log_warning:*) o_msgnum=1; o_severity=WARNING ;;
  66. log_error:*) o_msgnum=1; o_severity=ERROR ;;
  67. esac
  68. test "$o_msgnum" -eq 0 && o_not=-N
  69. # asserts
  70. #
  71. preupg__assert \
  72. result "$o_result" \
  73. msgn "$o_msgnum" \
  74. $o_not msg.$o_severity "$(<t_message)"
  75. }
  76. xcase__diag() {
  77. #
  78. # Burp up some diag
  79. #
  80. jat_dump__file module.mdef
  81. preupg__get_messages | jat_dump__pipe MESSAGES
  82. }
  83. xcase__cleanup() {
  84. #
  85. # Clean up after subtest
  86. #
  87. preupg__rmresult
  88. }
  89. PREUPG__UPATH=@pass \
  90. preupg__Run1
  91. xcase__run -v
  92. preupg__Cleanup