| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# General tests for 'fscrypt encrypt'. For protector-specific tests, see |
| 4 |
# t_encrypt_custom, t_encrypt_login, and t_encrypt_raw_key. |
| 5 |
|
| 6 |
cd "$(dirname "$0")" |
| 7 |
. common.sh |
| 8 |
|
| 9 |
dir="$MNT/dir" |
| 10 |
|
| 11 |
begin() |
| 12 |
{ |
| 13 |
_reset_filesystems |
| 14 |
mkdir "$dir" |
| 15 |
_print_header "$@" |
| 16 |
} |
| 17 |
|
| 18 |
show_status() |
| 19 |
{ |
| 20 |
local encrypted=$1 |
| 21 |
|
| 22 |
fscrypt status "$MNT" |
| 23 |
if $encrypted; then |
| 24 |
fscrypt status "$dir" |
| 25 |
else |
| 26 |
_expect_failure "fscrypt status '$dir'" |
| 27 |
fi |
| 28 |
} |
| 29 |
|
| 30 |
begin "Try to encrypt a nonexistent directory" |
| 31 |
_expect_failure "echo hunter2 | fscrypt encrypt --quiet '$MNT/nonexistent'" |
| 32 |
show_status false |
| 33 |
|
| 34 |
begin "Try to encrypt a nonempty directory" |
| 35 |
touch "$dir/file" |
| 36 |
_expect_failure "echo hunter2 | fscrypt encrypt --quiet '$dir'" |
| 37 |
show_status false |
| 38 |
_print_header "=> with trailing slash" |
| 39 |
_expect_failure "echo hunter2 | fscrypt encrypt --quiet '$dir/'" |
| 40 |
show_status false |
| 41 |
|
| 42 |
begin "Encrypt a directory as non-root user" |
| 43 |
chown "$TEST_USER" "$dir" |
| 44 |
_user_do "echo hunter2 | fscrypt encrypt --quiet --name=prot '$dir'" |
| 45 |
show_status true |
| 46 |
_user_do "fscrypt status '$MNT'" |
| 47 |
_user_do "fscrypt status '$dir'" |
| 48 |
|
| 49 |
_print_header "Try to encrypt an already-encrypted directory" |
| 50 |
_user_do_and_expect_failure "echo hunter2 | fscrypt encrypt --quiet --name=prot '$dir'" |
| 51 |
|
| 52 |
begin "Try to encrypt another user's directory as a non-root user" |
| 53 |
_user_do_and_expect_failure "echo hunter2 | fscrypt encrypt --quiet --name=prot '$dir'" |
| 54 |
show_status false |