|
3 | 3 | load helpers |
4 | 4 |
|
5 | 5 | function setup() { |
6 | | - teardown_busybox |
7 | | - setup_busybox |
| 6 | + teardown_busybox |
| 7 | + setup_busybox |
| 8 | + |
| 9 | + # Create fake rootfs. |
| 10 | + mkdir rootfs/testdir |
| 11 | + echo "Forbidden information!" > rootfs/testfile |
| 12 | + |
| 13 | + # add extra masked paths |
| 14 | + sed -i 's;"maskedPaths": \[;"maskedPaths": \["/testdir","/testfile",;g' config.json |
8 | 15 | } |
9 | 16 |
|
10 | 17 | function teardown() { |
11 | | - teardown_busybox |
| 18 | + teardown_busybox |
12 | 19 | } |
13 | 20 |
|
14 | | -@test "MaskPaths(file)" { |
15 | | - # run busybox detached |
16 | | - runc run -d --console /dev/pts/ptmx test_busybox |
17 | | - [ "$status" -eq 0 ] |
| 21 | +@test "mask paths [file]" { |
| 22 | + # run busybox detached |
| 23 | + runc run -d --console /dev/pts/ptmx test_busybox |
| 24 | + [ "$status" -eq 0 ] |
18 | 25 |
|
19 | | - wait_for_container 15 1 test_busybox |
| 26 | + wait_for_container 15 1 test_busybox |
20 | 27 |
|
21 | | - runc exec test_busybox cat /proc/kcore |
22 | | - [ "$status" -eq 0 ] |
23 | | - [[ "${output}" == "" ]] |
| 28 | + runc exec test_busybox cat /testfile |
| 29 | + [ "$status" -eq 0 ] |
| 30 | + [[ "${output}" == "" ]] |
24 | 31 |
|
25 | | - runc exec test_busybox rm -f /proc/kcore |
26 | | - [ "$status" -eq 1 ] |
27 | | - [[ "${output}" == *"Permission denied"* ]] |
| 32 | + runc exec test_busybox rm -f /testfile |
| 33 | + [ "$status" -eq 1 ] |
| 34 | + [[ "${output}" == *"Read-only file system"* ]] |
28 | 35 |
|
29 | | - runc exec test_busybox umount /proc/kcore |
30 | | - [ "$status" -eq 1 ] |
31 | | - [[ "${output}" == *"Operation not permitted"* ]] |
| 36 | + runc exec test_busybox umount /testfile |
| 37 | + [ "$status" -eq 1 ] |
| 38 | + [[ "${output}" == *"Operation not permitted"* ]] |
32 | 39 | } |
33 | 40 |
|
34 | | -@test "MaskPaths(directory)" { |
35 | | - # run busybox detached |
36 | | - runc run -d --console /dev/pts/ptmx test_busybox |
37 | | - [ "$status" -eq 0 ] |
| 41 | +@test "mask paths [directory]" { |
| 42 | + # run busybox detached |
| 43 | + runc run -d --console /dev/pts/ptmx test_busybox |
| 44 | + [ "$status" -eq 0 ] |
38 | 45 |
|
39 | | - wait_for_container 15 1 test_busybox |
| 46 | + wait_for_container 15 1 test_busybox |
40 | 47 |
|
41 | | - runc exec test_busybox ls /sys/firmware |
42 | | - [ "$status" -eq 0 ] |
43 | | - [[ "${output}" == "" ]] |
| 48 | + runc exec test_busybox ls /testdir |
| 49 | + [ "$status" -eq 0 ] |
| 50 | + [[ "${output}" == "" ]] |
44 | 51 |
|
45 | | - runc exec test_busybox touch /sys/firmware/foo |
46 | | - [ "$status" -eq 1 ] |
47 | | - [[ "${output}" == *"Read-only file system"* ]] |
| 52 | + runc exec test_busybox touch /testdir/foo |
| 53 | + [ "$status" -eq 1 ] |
| 54 | + [[ "${output}" == *"Read-only file system"* ]] |
48 | 55 |
|
49 | | - runc exec test_busybox rm -rf /sys/firmware |
50 | | - [ "$status" -eq 1 ] |
51 | | - [[ "${output}" == *"Read-only file system"* ]] |
| 56 | + runc exec test_busybox rm -rf /testdir |
| 57 | + [ "$status" -eq 1 ] |
| 58 | + [[ "${output}" == *"Read-only file system"* ]] |
52 | 59 |
|
53 | | - runc exec test_busybox umount /sys/firmware |
54 | | - [ "$status" -eq 1 ] |
55 | | - [[ "${output}" == *"Operation not permitted"* ]] |
| 60 | + runc exec test_busybox umount /testdir |
| 61 | + [ "$status" -eq 1 ] |
| 62 | + [[ "${output}" == *"Operation not permitted"* ]] |
56 | 63 | } |
0 commit comments