Debian Codegraph @

src/luks/tests/unlock-arbitrary-parameter

raw
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
17 TEST=$(basename "${0}")
18 . luks-common-test-functions
19
20 . clevis-luks-common-functions
21
22 on_exit() {
23 [ ! -d "${TMP}" ] && return 0
24 tang_stop "${TMP}"
25 rm -rf "${TMP}"
26 }
27
28 trap 'on_exit' EXIT
29 trap 'on_exit' ERR
30
31 TMP="$(mktemp -d)"
32
33 tang_run "${TMP}"
34 port=$(tang_get_port "${TMP}")
35
36 url="http://localhost:${port}"
37 adv="${TMP}/adv"
38 tang_get_adv "${port}" "${adv}"
39
40 cfg=$(printf '{"url":"%s","adv":"%s"}' "$url" "$adv")
41
42 DEV="${TMP}/luks1-device"
43 new_device "luks1" "${DEV}"
44
45 if ! clevis luks bind -f -d "${DEV}" tang "${cfg}" <<< "${DEFAULT_PASS}"; then
46 error "${TEST}: Bind should have succeeded."
47 fi
48
49 TESTPARAM="arbitrarytestparameter"
50
51 #set up a "cryptsetup" function, to hijack the command
52 cryptsetup () {
53 #need to handle "cryptsetup isLuks" from clevis-luks-unlock, among others
54 if [[ $1 == "isLuks" ]]; then
55 exit 0;
56 elif [[ $1 == "luksUUID" ]]; then
57 echo "TESTINGLUKSUUID"
58 exit 0;
59 else
60 echo "$*" | grep -q -- "${TESTPARAM}"
61 exit $?
62 fi
63 }
64 export -f cryptsetup
65
66 if ! clevis-luks-unlock -o "$TESTPARAM" -d ${DEV} -n clevis_unlock_test; then
67 error "${TEST}: clevis luks unlock did not match arbitrary test parameter \"$TESTPARAM\"."
68 fi