Debian Codegraph @

cli-tests/t_single_user.sh

raw
1 #!/bin/bash
2
3 # Test 'fscrypt setup' without --all-users.
4
5 cd "$(dirname "$0")"
6 . common.sh
7
8 _rm_metadata "$MNT_ROOT"
9 _rm_metadata "$MNT"
10 rm "$FSCRYPT_CONF"
11 fscrypt setup --time=1ms --quiet
12 fscrypt setup --time=1ms --quiet "$MNT"
13 fscrypt status "$MNT"
14 _user_do "fscrypt status \"$MNT\""
15
16 dir=$MNT/dir
17
18 begin()
19 {
20 _reset_filesystems
21 mkdir "$dir"
22 _print_header "$1"
23 }
24
25 begin "Encrypt, lock, and unlock as root"
26 echo hunter2 | fscrypt encrypt --quiet --name=dir --skip-unlock "$dir"
27 echo hunter2 | fscrypt unlock --quiet "$dir"
28 fscrypt lock "$dir"
29
30 begin "Encrypt as root with user's login protector"
31 echo TEST_USER_PASS | fscrypt encrypt --quiet --source=pam_passphrase --user="$TEST_USER" "$dir"
32 # The user should be able to update the policy and protectors created by the
33 # above command themselves. The easiest way to test this is by updating the
34 # policy to remove the auto-generated recovery protector. This verifies that
35 # (a) the policy was made owned by the user, and that (b) policy updates fall
36 # back to overwrites when the process cannot write to the containing directory.
37 # (It would be better to test updating the protectors too, but this is the
38 # easiest test to do here.)
39 policy=$(fscrypt status "$dir" | awk '/Policy/{print $2}')
40 recovery_protector=$(_get_protector_descriptor "$MNT" custom 'Recovery passphrase for dir')
41 _user_do "fscrypt metadata remove-protector-from-policy --force --protector=$MNT:$recovery_protector --policy=$MNT:$policy"
42 chown "$TEST_USER" "$dir"
43 _user_do "fscrypt lock $dir"
44 _user_do "echo TEST_USER_PASS | fscrypt unlock $dir"
45
46 begin "Encrypt as user (should fail)"
47 chown "$TEST_USER" "$dir"
48 _user_do_and_expect_failure "echo hunter2 | fscrypt encrypt --quiet --name=dir --skip-unlock \"$dir\""
49
50 begin "Encrypt as user if they set up filesystem (should succeed)"
51 _rm_metadata "$MNT"
52 chown "$TEST_USER" "$MNT"
53 chown "$TEST_USER" "$dir"
54 _user_do "fscrypt setup --time=1ms --quiet $MNT"
55 _user_do "echo hunter2 | fscrypt encrypt --quiet --name=dir3 --skip-unlock \"$dir\""