Debian Codegraph @

cli-tests/t_lock.sh

raw
1 #!/bin/bash
2
3 # Test locking a directory.
4
5 cd "$(dirname "$0")"
6 . common.sh
7
8 dir="$MNT/dir"
9 mkdir "$dir"
10
11 _print_header "Encrypt directory"
12 echo hunter2 | fscrypt encrypt --quiet --name=prot "$dir"
13 fscrypt status "$dir"
14 echo contents > "$dir/file"
15
16 _print_header "Lock directory"
17 fscrypt lock "$dir"
18 _print_header "=> filenames should be in encrypted form"
19 _expect_failure "cat '$dir/file'"
20 _print_header "=> shouldn't be able to create a subdirectory"
21 _expect_failure "mkdir '$dir/subdir'"
22
23 _print_header "Unlock directory"
24 echo hunter2 | fscrypt unlock "$dir"
25 fscrypt status "$dir"
26 cat "$dir/file"
27
28 _print_header "Try to lock directory while files busy"
29 exec 3<"$dir/file"
30 _expect_failure "fscrypt lock '$dir'"
31 _print_header "=> status should be incompletely locked"
32 fscrypt status "$dir"
33 _print_header "=> open file should still be readable"
34 cat "$dir/file"
35 _print_header "=> shouldn't be able to create a new file"
36 _expect_failure "bash -c \"echo contents > '$dir/file2'\""
37
38 _print_header "Finish locking directory"
39 exec 3<&-
40 fscrypt lock "$dir"
41 fscrypt status "$dir"
42 _expect_failure "cat '$dir/file'"
43 _expect_failure "mkdir '$dir/subdir'"
44
45 _print_header "Try to lock directory while other user has unlocked"
46 rm -rf "$dir"
47 mkdir "$dir"
48 chown "$TEST_USER" "$dir"
49 _user_do "echo hunter2 | fscrypt encrypt --quiet --name=prot '$dir'"
50 _user_do "echo contents > $dir/file"
51 _expect_failure "fscrypt lock '$dir'"
52 cat "$dir/file"
53 fscrypt lock --all-users "$dir"
54 _expect_failure "cat '$dir/file'"
55
56 _print_header "Try to operate on locked regular file"
57 _reset_filesystems
58 rm -rf "$dir"
59 mkdir "$dir"
60 echo hunter2 | fscrypt encrypt --quiet --name=prot "$dir"
61 echo contents > "$dir/file"
62 mv "$dir/file" "$MNT/file" # Make it a loose encrypted file.
63 fscrypt lock "$dir"
64 _expect_failure "fscrypt status '$MNT/file'"
65 _expect_failure "fscrypt unlock '$MNT/file'"