Skip to content

Commit 57be034

Browse files
committed
cli-tests: add helper functions to get protector descriptors
1 parent 6ec8ee0 commit 57be034

3 files changed

Lines changed: 38 additions & 9 deletions

File tree

cli-tests/common.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,40 @@ _get_enabled_fs_count()
7272
echo "$count"
7373
}
7474

75+
# Gets the descriptor of the given protector.
76+
_get_protector_descriptor()
77+
{
78+
local mnt=$1
79+
local source=$2
80+
81+
case $source in
82+
custom)
83+
local name=$3
84+
local description="custom protector \\\"$name\\\""
85+
;;
86+
login)
87+
local user=$3
88+
local description="login protector for $user"
89+
;;
90+
*)
91+
_fail "Unknown protector source $source"
92+
esac
93+
94+
local descriptor
95+
descriptor=$(fscrypt status "$mnt" |
96+
awk -F ' *' '{ if ($3 == "'"$description"'") print $1 }')
97+
if [ -z "$descriptor" ]; then
98+
_fail "Can't find $description on $mnt"
99+
fi
100+
echo "$descriptor"
101+
}
102+
103+
# Gets the descriptor of the login protector for $TEST_USER.
104+
_get_login_descriptor()
105+
{
106+
_get_protector_descriptor "$MNT_ROOT" login "$TEST_USER"
107+
}
108+
75109
# Prints the number of filesystems that have fscrypt metadata.
76110
_get_setup_fs_count()
77111
{

cli-tests/t_change_passphrase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ echo pass1 | fscrypt encrypt --quiet --name=prot --skip-unlock "$dir"
1414
_print_header "Try to unlock with wrong passphrase"
1515
_expect_failure "echo pass2 | fscrypt unlock --quiet '$dir'"
1616
_expect_failure "mkdir '$dir/subdir'"
17-
protector=$(fscrypt status "$dir" | awk '/custom protector/{print $1}')
17+
protector=$(_get_protector_descriptor "$dir" custom prot)
1818

1919
_print_header "Change passphrase"
2020
echo $'pass1\npass2' | \

cli-tests/t_encrypt_login.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@ show_status()
2727
fi
2828
}
2929

30-
get_login_protector()
31-
{
32-
fscrypt status "$dir" | awk '/login protector/{print $1}'
33-
}
34-
3530
begin "Encrypt with login protector"
3631
chown "$TEST_USER" "$dir"
3732
_user_do "echo TEST_USER_PASS | fscrypt encrypt --quiet --source=pam_passphrase '$dir'"
3833
show_status true
3934
recovery_passphrase=$(grep -E '^ +[a-z]{20}$' "$dir/fscrypt_recovery_readme.txt" | sed 's/^ +//')
40-
recovery_protector=$(fscrypt status "$dir" | awk '/Recovery passphrase/{print $1}')
41-
login_protector=$(get_login_protector)
35+
recovery_protector=$(_get_protector_descriptor "$MNT" custom 'Recovery passphrase for dir')
36+
login_protector=$(_get_login_descriptor)
4237
_print_header "=> Lock, then unlock with login passphrase"
4338
_user_do "fscrypt lock '$dir'"
4439
# FIXME: should we be able to use $MNT:$login_protector here?
@@ -63,7 +58,7 @@ begin "Encrypt with login protector as root"
6358
echo TEST_USER_PASS | fscrypt encrypt --quiet --source=pam_passphrase --user="$TEST_USER" "$dir"
6459
show_status true
6560
# The newly-created login protector should be owned by the user, not root.
66-
login_protector=$(get_login_protector)
61+
login_protector=$(_get_login_descriptor)
6762
owner=$(stat -c "%U:%G" "$MNT_ROOT/.fscrypt/protectors/$login_protector")
6863
echo -e "\nProtector is owned by $owner"
6964

0 commit comments

Comments
 (0)