diff options
author | a1346054 <36859588+a1346054@users.noreply.github.com> | 2022-09-13 18:42:15 +0000 |
---|---|---|
committer | a1346054 <36859588+a1346054@users.noreply.github.com> | 2022-09-13 22:37:18 +0000 |
commit | e04d6b7bf58a95105a8fc79fcde7c0e98875e72a (patch) | |
tree | 6e20913ed5d4af3e1b0ef5a31ef80ee42f651376 /test | |
parent | tests: fix unintentional overwriting of array value (diff) | |
download | firejail-e04d6b7bf58a95105a8fc79fcde7c0e98875e72a.tar.gz firejail-e04d6b7bf58a95105a8fc79fcde7c0e98875e72a.tar.zst firejail-e04d6b7bf58a95105a8fc79fcde7c0e98875e72a.zip |
tests: directly test for presence of command
Test directly for presence of command instead of indirectly testing
the return code.
Additionally:
* uses a shell builtin `command -v` instead of external `which`
* `command -v` is the standardized version of `which`
Diffstat (limited to 'test')
-rwxr-xr-x | test/apps-x11-xorg/apps-x11-xorg.sh | 12 | ||||
-rwxr-xr-x | test/apps-x11/apps-x11.sh | 27 | ||||
-rwxr-xr-x | test/apps/apps.sh | 3 | ||||
-rwxr-xr-x | test/environment/environment.sh | 9 | ||||
-rwxr-xr-x | test/filters/filters.sh | 3 | ||||
-rwxr-xr-x | test/overlay/overlay.sh | 15 | ||||
-rwxr-xr-x | test/private-lib/private-lib.sh | 3 | ||||
-rwxr-xr-x | test/root/root.sh | 3 | ||||
-rwxr-xr-x | test/sysutils/sysutils.sh | 27 | ||||
-rwxr-xr-x | test/utils/utils.sh | 3 |
10 files changed, 35 insertions, 70 deletions
diff --git a/test/apps-x11-xorg/apps-x11-xorg.sh b/test/apps-x11-xorg/apps-x11-xorg.sh index 9ed123979..9dcee7aff 100755 --- a/test/apps-x11-xorg/apps-x11-xorg.sh +++ b/test/apps-x11-xorg/apps-x11-xorg.sh | |||
@@ -7,8 +7,7 @@ export MALLOC_CHECK_=3 | |||
7 | export MALLOC_PERTURB_=$(($RANDOM % 255 + 1)) | 7 | export MALLOC_PERTURB_=$(($RANDOM % 255 + 1)) |
8 | export LC_ALL=C | 8 | export LC_ALL=C |
9 | 9 | ||
10 | which firefox 2>/dev/null | 10 | if command -v firefox |
11 | if [ "$?" -eq 0 ]; | ||
12 | then | 11 | then |
13 | echo "TESTING: firefox x11 xorg" | 12 | echo "TESTING: firefox x11 xorg" |
14 | ./firefox.exp | 13 | ./firefox.exp |
@@ -16,8 +15,7 @@ else | |||
16 | echo "TESTING SKIP: firefox not found" | 15 | echo "TESTING SKIP: firefox not found" |
17 | fi | 16 | fi |
18 | 17 | ||
19 | which transmission-gtk 2>/dev/null | 18 | if command -v transmission-gtk |
20 | if [ "$?" -eq 0 ]; | ||
21 | then | 19 | then |
22 | echo "TESTING: transmission-gtk x11 xorg" | 20 | echo "TESTING: transmission-gtk x11 xorg" |
23 | ./transmission-gtk.exp | 21 | ./transmission-gtk.exp |
@@ -25,8 +23,7 @@ else | |||
25 | echo "TESTING SKIP: transmission-gtk not found" | 23 | echo "TESTING SKIP: transmission-gtk not found" |
26 | fi | 24 | fi |
27 | 25 | ||
28 | which transmission-qt 2>/dev/null | 26 | if command -v transmission-qt |
29 | if [ "$?" -eq 0 ]; | ||
30 | then | 27 | then |
31 | echo "TESTING: transmission-qt x11 xorg" | 28 | echo "TESTING: transmission-qt x11 xorg" |
32 | ./transmission-qt.exp | 29 | ./transmission-qt.exp |
@@ -34,8 +31,7 @@ else | |||
34 | echo "TESTING SKIP: transmission-qt not found" | 31 | echo "TESTING SKIP: transmission-qt not found" |
35 | fi | 32 | fi |
36 | 33 | ||
37 | which thunderbird 2>/dev/null | 34 | if command -v thunderbird |
38 | if [ "$?" -eq 0 ]; | ||
39 | then | 35 | then |
40 | echo "TESTING: thunderbird x11 xorg" | 36 | echo "TESTING: thunderbird x11 xorg" |
41 | ./thunderbird.exp | 37 | ./thunderbird.exp |
diff --git a/test/apps-x11/apps-x11.sh b/test/apps-x11/apps-x11.sh index a3c946ca4..9f8102738 100755 --- a/test/apps-x11/apps-x11.sh +++ b/test/apps-x11/apps-x11.sh | |||
@@ -11,21 +11,18 @@ echo "TESTING: no x11 (test/apps-x11/x11-none.exp)" | |||
11 | ./x11-none.exp | 11 | ./x11-none.exp |
12 | 12 | ||
13 | 13 | ||
14 | which xterm 2>/dev/null | 14 | if command -v xterm |
15 | if [ "$?" -eq 0 ]; | ||
16 | then | 15 | then |
17 | echo "TESTING: xterm x11 xorg" | 16 | echo "TESTING: xterm x11 xorg" |
18 | ./xterm-xorg.exp | 17 | ./xterm-xorg.exp |
19 | 18 | ||
20 | which xpra 2>/dev/null | 19 | if command -v xpra |
21 | if [ "$?" -eq 0 ]; | ||
22 | then | 20 | then |
23 | echo "TESTING: xterm x11 xpra" | 21 | echo "TESTING: xterm x11 xpra" |
24 | ./xterm-xpra.exp | 22 | ./xterm-xpra.exp |
25 | fi | 23 | fi |
26 | 24 | ||
27 | which Xephyr 2>/dev/null | 25 | if command -v Xephyr |
28 | if [ "$?" -eq 0 ]; | ||
29 | then | 26 | then |
30 | echo "TESTING: xterm x11 xephyr" | 27 | echo "TESTING: xterm x11 xephyr" |
31 | ./xterm-xephyr.exp | 28 | ./xterm-xephyr.exp |
@@ -35,14 +32,12 @@ else | |||
35 | fi | 32 | fi |
36 | 33 | ||
37 | # check xpra/xephyr | 34 | # check xpra/xephyr |
38 | which xpra 2>/dev/null | 35 | if command -v xpra |
39 | if [ "$?" -eq 0 ]; | ||
40 | then | 36 | then |
41 | echo "xpra found" | 37 | echo "xpra found" |
42 | else | 38 | else |
43 | echo "xpra not found" | 39 | echo "xpra not found" |
44 | which Xephyr 2>/dev/null | 40 | if command -v Xephyr |
45 | if [ "$?" -eq 0 ]; | ||
46 | then | 41 | then |
47 | echo "Xephyr found" | 42 | echo "Xephyr found" |
48 | else | 43 | else |
@@ -51,8 +46,7 @@ else | |||
51 | fi | 46 | fi |
52 | fi | 47 | fi |
53 | 48 | ||
54 | which firefox 2>/dev/null | 49 | if command -v firefox |
55 | if [ "$?" -eq 0 ]; | ||
56 | then | 50 | then |
57 | echo "TESTING: firefox x11" | 51 | echo "TESTING: firefox x11" |
58 | ./firefox.exp | 52 | ./firefox.exp |
@@ -60,8 +54,7 @@ else | |||
60 | echo "TESTING SKIP: firefox not found" | 54 | echo "TESTING SKIP: firefox not found" |
61 | fi | 55 | fi |
62 | 56 | ||
63 | which chromium 2>/dev/null | 57 | if command -v chromium |
64 | if [ "$?" -eq 0 ]; | ||
65 | then | 58 | then |
66 | echo "TESTING: chromium x11" | 59 | echo "TESTING: chromium x11" |
67 | ./chromium.exp | 60 | ./chromium.exp |
@@ -69,8 +62,7 @@ else | |||
69 | echo "TESTING SKIP: chromium not found" | 62 | echo "TESTING SKIP: chromium not found" |
70 | fi | 63 | fi |
71 | 64 | ||
72 | which transmission-gtk 2>/dev/null | 65 | if command -v transmission-gtk |
73 | if [ "$?" -eq 0 ]; | ||
74 | then | 66 | then |
75 | echo "TESTING: transmission-gtk x11" | 67 | echo "TESTING: transmission-gtk x11" |
76 | ./transmission-gtk.exp | 68 | ./transmission-gtk.exp |
@@ -78,8 +70,7 @@ else | |||
78 | echo "TESTING SKIP: transmission-gtk not found" | 70 | echo "TESTING SKIP: transmission-gtk not found" |
79 | fi | 71 | fi |
80 | 72 | ||
81 | which thunderbird 2>/dev/null | 73 | if command -v thunderbird |
82 | if [ "$?" -eq 0 ]; | ||
83 | then | 74 | then |
84 | echo "TESTING: thunderbird x11" | 75 | echo "TESTING: thunderbird x11" |
85 | ./thunderbird.exp | 76 | ./thunderbird.exp |
diff --git a/test/apps/apps.sh b/test/apps/apps.sh index 83e977ba0..ed4b7604a 100755 --- a/test/apps/apps.sh +++ b/test/apps/apps.sh | |||
@@ -11,8 +11,7 @@ LIST="firefox midori chromium opera transmission-qt qbittorrent uget-gtk filezil | |||
11 | LIST+="vlc fbreader deluge gnome-mplayer xchat wine kcalc ktorrent hexchat" | 11 | LIST+="vlc fbreader deluge gnome-mplayer xchat wine kcalc ktorrent hexchat" |
12 | 12 | ||
13 | for app in $LIST; do | 13 | for app in $LIST; do |
14 | which $app 2>/dev/null | 14 | if command -v "$app" |
15 | if [ "$?" -eq 0 ]; | ||
16 | then | 15 | then |
17 | echo "TESTING: $app" | 16 | echo "TESTING: $app" |
18 | ./$app.exp | 17 | ./$app.exp |
diff --git a/test/environment/environment.sh b/test/environment/environment.sh index da9c170b9..f6acada73 100755 --- a/test/environment/environment.sh +++ b/test/environment/environment.sh | |||
@@ -39,8 +39,7 @@ echo "TESTING: environment variables (test/environment/env.exp)" | |||
39 | echo "TESTING: firejail in firejail - single sandbox (test/environment/firejail-in-firejail.exp)" | 39 | echo "TESTING: firejail in firejail - single sandbox (test/environment/firejail-in-firejail.exp)" |
40 | ./firejail-in-firejail.exp | 40 | ./firejail-in-firejail.exp |
41 | 41 | ||
42 | which aplay 2>/dev/null | 42 | if command -v aplay && [ "$(aplay -l | grep -c "List of PLAYBACK")" -gt 0 ]; |
43 | if [ "$?" -eq 0 ] && [ "$(aplay -l | grep -c "List of PLAYBACK")" -gt 0 ]; | ||
44 | then | 43 | then |
45 | echo "TESTING: sound (test/environment/sound.exp)" | 44 | echo "TESTING: sound (test/environment/sound.exp)" |
46 | ./sound.exp | 45 | ./sound.exp |
@@ -54,8 +53,7 @@ echo "TESTING: nice (test/environment/nice.exp)" | |||
54 | echo "TESTING: quiet (test/environment/quiet.exp)" | 53 | echo "TESTING: quiet (test/environment/quiet.exp)" |
55 | ./quiet.exp | 54 | ./quiet.exp |
56 | 55 | ||
57 | which strace 2>/dev/null | 56 | if command -v strace |
58 | if [ "$?" -eq 0 ]; | ||
59 | then | 57 | then |
60 | echo "TESTING: --allow-debuggers (test/environment/allow-debuggers.exp)" | 58 | echo "TESTING: --allow-debuggers (test/environment/allow-debuggers.exp)" |
61 | ./allow-debuggers.exp | 59 | ./allow-debuggers.exp |
@@ -67,8 +65,7 @@ fi | |||
67 | # $ sudo apt-get install ibus-table-array30 | 65 | # $ sudo apt-get install ibus-table-array30 |
68 | # $ ibus-setup | 66 | # $ ibus-setup |
69 | 67 | ||
70 | find ~/.config/ibus/bus | grep unix-0 | 68 | if find ~/.config/ibus/bus | grep unix-0 |
71 | if [ "$?" -eq 0 ]; | ||
72 | then | 69 | then |
73 | echo "TESTING: ibus (test/environment/ibus.exp)" | 70 | echo "TESTING: ibus (test/environment/ibus.exp)" |
74 | ./ibus.exp | 71 | ./ibus.exp |
diff --git a/test/filters/filters.sh b/test/filters/filters.sh index 04d7080d6..1c6b812ff 100755 --- a/test/filters/filters.sh +++ b/test/filters/filters.sh | |||
@@ -96,8 +96,7 @@ echo "TESTING: seccomp errno (test/filters/seccomp-errno.exp)" | |||
96 | echo "TESTING: seccomp su (test/filters/seccomp-su.exp)" | 96 | echo "TESTING: seccomp su (test/filters/seccomp-su.exp)" |
97 | ./seccomp-su.exp | 97 | ./seccomp-su.exp |
98 | 98 | ||
99 | which strace 2>/dev/null | 99 | if command -v strace; then |
100 | if [ $? -eq 0 ]; then | ||
101 | echo "TESTING: seccomp ptrace (test/filters/seccomp-ptrace.exp)" | 100 | echo "TESTING: seccomp ptrace (test/filters/seccomp-ptrace.exp)" |
102 | ./seccomp-ptrace.exp | 101 | ./seccomp-ptrace.exp |
103 | else | 102 | else |
diff --git a/test/overlay/overlay.sh b/test/overlay/overlay.sh index 490b180e1..9bc458f50 100755 --- a/test/overlay/overlay.sh +++ b/test/overlay/overlay.sh | |||
@@ -22,8 +22,7 @@ rm -fr ~/_firejail_test_* | |||
22 | ./fs-tmpfs.exp | 22 | ./fs-tmpfs.exp |
23 | rm -fr ~/_firejail_test_* | 23 | rm -fr ~/_firejail_test_* |
24 | 24 | ||
25 | which firefox 2>/dev/null | 25 | if command -v firefox |
26 | if [ "$?" -eq 0 ]; | ||
27 | then | 26 | then |
28 | echo "TESTING: overlay firefox" | 27 | echo "TESTING: overlay firefox" |
29 | ./firefox.exp | 28 | ./firefox.exp |
@@ -31,8 +30,7 @@ else | |||
31 | echo "TESTING SKIP: firefox not found" | 30 | echo "TESTING SKIP: firefox not found" |
32 | fi | 31 | fi |
33 | 32 | ||
34 | which firefox 2>/dev/null | 33 | if command -v firefox |
35 | if [ "$?" -eq 0 ]; | ||
36 | then | 34 | then |
37 | echo "TESTING: overlay firefox x11 xorg" | 35 | echo "TESTING: overlay firefox x11 xorg" |
38 | ./firefox.exp | 36 | ./firefox.exp |
@@ -42,14 +40,12 @@ fi | |||
42 | 40 | ||
43 | 41 | ||
44 | # check xpra/xephyr | 42 | # check xpra/xephyr |
45 | which xpra 2>/dev/null | 43 | if command -v xpra |
46 | if [ "$?" -eq 0 ]; | ||
47 | then | 44 | then |
48 | echo "xpra found" | 45 | echo "xpra found" |
49 | else | 46 | else |
50 | echo "xpra not found" | 47 | echo "xpra not found" |
51 | which Xephyr 2>/dev/null | 48 | if command -v Xephyr |
52 | if [ "$?" -eq 0 ]; | ||
53 | then | 49 | then |
54 | echo "Xephyr found" | 50 | echo "Xephyr found" |
55 | else | 51 | else |
@@ -58,8 +54,7 @@ else | |||
58 | fi | 54 | fi |
59 | fi | 55 | fi |
60 | 56 | ||
61 | which firefox 2>/dev/null | 57 | if command -v firefox |
62 | if [ "$?" -eq 0 ]; | ||
63 | then | 58 | then |
64 | echo "TESTING: overlay firefox x11" | 59 | echo "TESTING: overlay firefox x11" |
65 | ./firefox-x11.exp | 60 | ./firefox-x11.exp |
diff --git a/test/private-lib/private-lib.sh b/test/private-lib/private-lib.sh index d168c2b1b..86ed7b06d 100755 --- a/test/private-lib/private-lib.sh +++ b/test/private-lib/private-lib.sh | |||
@@ -11,8 +11,7 @@ LIST="gnome-logs gnome-system-log gnome-nettool pavucontrol dig evince whois gal | |||
11 | 11 | ||
12 | 12 | ||
13 | for app in $LIST; do | 13 | for app in $LIST; do |
14 | which $app 2>/dev/null | 14 | if command -v "$app" |
15 | if [ "$?" -eq 0 ]; | ||
16 | then | 15 | then |
17 | echo "TESTING: private-lib $app" | 16 | echo "TESTING: private-lib $app" |
18 | ./$app.exp | 17 | ./$app.exp |
diff --git a/test/root/root.sh b/test/root/root.sh index e8c0ec1ac..e3b48d15b 100755 --- a/test/root/root.sh +++ b/test/root/root.sh | |||
@@ -11,8 +11,7 @@ export LC_ALL=C | |||
11 | #******************************** | 11 | #******************************** |
12 | # firecfg | 12 | # firecfg |
13 | #******************************** | 13 | #******************************** |
14 | which less 2>/dev/null | 14 | if command -v less |
15 | if [ "$?" -eq 0 ]; | ||
16 | then | 15 | then |
17 | echo "TESTING: firecfg (test/root/firecfg.exp)" | 16 | echo "TESTING: firecfg (test/root/firecfg.exp)" |
18 | mv /home/netblue/.local/share/applications /home/netblue/.local/share/applications-store | 17 | mv /home/netblue/.local/share/applications /home/netblue/.local/share/applications-store |
diff --git a/test/sysutils/sysutils.sh b/test/sysutils/sysutils.sh index a903c7c6b..bfe723047 100755 --- a/test/sysutils/sysutils.sh +++ b/test/sysutils/sysutils.sh | |||
@@ -7,8 +7,7 @@ export MALLOC_CHECK_=3 | |||
7 | export MALLOC_PERTURB_=$(($RANDOM % 255 + 1)) | 7 | export MALLOC_PERTURB_=$(($RANDOM % 255 + 1)) |
8 | export LC_ALL=C | 8 | export LC_ALL=C |
9 | 9 | ||
10 | which cpio 2>/dev/null | 10 | if command -v cpio |
11 | if [ "$?" -eq 0 ]; | ||
12 | then | 11 | then |
13 | echo "TESTING: cpio" | 12 | echo "TESTING: cpio" |
14 | ./cpio.exp | 13 | ./cpio.exp |
@@ -16,8 +15,7 @@ else | |||
16 | echo "TESTING SKIP: cpio not found" | 15 | echo "TESTING SKIP: cpio not found" |
17 | fi | 16 | fi |
18 | 17 | ||
19 | #which strings | 18 | #if command -v strings |
20 | #if [ "$?" -eq 0 ]; | ||
21 | #then | 19 | #then |
22 | # echo "TESTING: strings" | 20 | # echo "TESTING: strings" |
23 | # ./strings.exp | 21 | # ./strings.exp |
@@ -25,8 +23,7 @@ fi | |||
25 | # echo "TESTING SKIP: strings not found" | 23 | # echo "TESTING SKIP: strings not found" |
26 | #fi | 24 | #fi |
27 | 25 | ||
28 | which gzip 2>/dev/null | 26 | if command -v gzip |
29 | if [ "$?" -eq 0 ]; | ||
30 | then | 27 | then |
31 | echo "TESTING: gzip" | 28 | echo "TESTING: gzip" |
32 | ./gzip.exp | 29 | ./gzip.exp |
@@ -34,8 +31,7 @@ else | |||
34 | echo "TESTING SKIP: gzip not found" | 31 | echo "TESTING SKIP: gzip not found" |
35 | fi | 32 | fi |
36 | 33 | ||
37 | which xzdec 2>/dev/null | 34 | if command -v xzdec |
38 | if [ "$?" -eq 0 ]; | ||
39 | then | 35 | then |
40 | echo "TESTING: xzdec" | 36 | echo "TESTING: xzdec" |
41 | ./xzdec.exp | 37 | ./xzdec.exp |
@@ -43,8 +39,7 @@ else | |||
43 | echo "TESTING SKIP: xzdec not found" | 39 | echo "TESTING SKIP: xzdec not found" |
44 | fi | 40 | fi |
45 | 41 | ||
46 | which xz 2>/dev/null | 42 | if command -v xz |
47 | if [ "$?" -eq 0 ]; | ||
48 | then | 43 | then |
49 | echo "TESTING: xz" | 44 | echo "TESTING: xz" |
50 | ./xz.exp | 45 | ./xz.exp |
@@ -52,8 +47,7 @@ else | |||
52 | echo "TESTING SKIP: xz not found" | 47 | echo "TESTING SKIP: xz not found" |
53 | fi | 48 | fi |
54 | 49 | ||
55 | which less 2>/dev/null | 50 | if command -v less |
56 | if [ "$?" -eq 0 ]; | ||
57 | then | 51 | then |
58 | echo "TESTING: less" | 52 | echo "TESTING: less" |
59 | ./less.exp | 53 | ./less.exp |
@@ -61,8 +55,7 @@ else | |||
61 | echo "TESTING SKIP: less not found" | 55 | echo "TESTING SKIP: less not found" |
62 | fi | 56 | fi |
63 | 57 | ||
64 | which file 2>/dev/null | 58 | if command -v file |
65 | if [ "$?" -eq 0 ]; | ||
66 | then | 59 | then |
67 | echo "TESTING: file" | 60 | echo "TESTING: file" |
68 | ./file.exp | 61 | ./file.exp |
@@ -70,8 +63,7 @@ else | |||
70 | echo "TESTING SKIP: file not found" | 63 | echo "TESTING SKIP: file not found" |
71 | fi | 64 | fi |
72 | 65 | ||
73 | which tar 2>/dev/null | 66 | if command -v tar |
74 | if [ "$?" -eq 0 ]; | ||
75 | then | 67 | then |
76 | echo "TESTING: tar" | 68 | echo "TESTING: tar" |
77 | ./tar.exp | 69 | ./tar.exp |
@@ -79,8 +71,7 @@ else | |||
79 | echo "TESTING SKIP: tar not found" | 71 | echo "TESTING SKIP: tar not found" |
80 | fi | 72 | fi |
81 | 73 | ||
82 | which ping 2>/dev/null | 74 | if command -v ping |
83 | if [ "$?" -eq 0 ]; | ||
84 | then | 75 | then |
85 | echo "TESTING: ping" | 76 | echo "TESTING: ping" |
86 | ./ping.exp | 77 | ./ping.exp |
diff --git a/test/utils/utils.sh b/test/utils/utils.sh index 102c8df17..ad36d7053 100755 --- a/test/utils/utils.sh +++ b/test/utils/utils.sh | |||
@@ -33,8 +33,7 @@ echo "TESTING: version (test/utils/version.exp)" | |||
33 | echo "TESTING: help (test/utils/help.exp)" | 33 | echo "TESTING: help (test/utils/help.exp)" |
34 | ./help.exp | 34 | ./help.exp |
35 | 35 | ||
36 | which man 2>/dev/null | 36 | if command -v man |
37 | if [ "$?" -eq 0 ]; | ||
38 | then | 37 | then |
39 | echo "TESTING: man (test/utils/man.exp)" | 38 | echo "TESTING: man (test/utils/man.exp)" |
40 | ./man.exp | 39 | ./man.exp |