unlock-arbitrary-parameter 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash -ex
  2. # vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. TEST=$(basename "${0}")
  17. . tests-common-functions
  18. . clevis-luks-common-functions
  19. on_exit() {
  20. [ ! -d "${TMP}" ] && return 0
  21. tang_stop "${TMP}"
  22. rm -rf "${TMP}"
  23. }
  24. trap 'on_exit' EXIT
  25. trap 'on_exit' ERR
  26. TMP="$(mktemp -d)"
  27. port=$(tang_new_random_port)
  28. tang_run "${TMP}" "${port}"
  29. url="http://localhost:${port}"
  30. adv="${TMP}/adv"
  31. tang_get_adv "${port}" "${adv}"
  32. cfg=$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")
  33. DEV="${TMP}/luks1-device"
  34. new_device "luks1" "${DEV}"
  35. if ! clevis luks bind -f -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
  36. error "${TEST}: Bind should have succeeded."
  37. fi
  38. TESTPARAM="arbitrarytestparameter"
  39. #set up a "cryptsetup" function, to hijack the command
  40. cryptsetup () {
  41. #need to handle "cryptsetup isLuks" from clevis-luks-unlock, among others
  42. if [[ $1 == "isLuks" ]]; then
  43. exit 0;
  44. elif [[ $1 == "luksUUID" ]]; then
  45. echo "TESTINGLUKSUUID"
  46. exit 0;
  47. else
  48. echo "$*" | grep -q -- "${TESTPARAM}"
  49. exit $?
  50. fi
  51. }
  52. export -f cryptsetup
  53. if ! clevis-luks-unlock -o "$TESTPARAM" -d ${DEV} -n clevis_unlock_test; then
  54. error "${TEST}: clevis luks unlock did not match arbitrary test parameter \"$TESTPARAM\"."
  55. fi