Added testing script

Added the `test/test.bash` script that simulates user input with zenity.
Depends on `xdotool` (couldn't make `ydotool` to work)
This commit is contained in:
BritishTeapot 2025-03-17 11:59:59 +01:00
parent 3b69fd43e3
commit a65d37f3bc

68
test/test.bash Executable file
View File

@ -0,0 +1,68 @@
#!/bin/bash
# clean what was left from previous tests
rm ./protected/first ./protected/second
touch ./protected/this-only ./protected/do-not-remove ./protected/should-be-removed
# mount the filesystem
echo "Run $(date -u +%Y-%m-%dT%H:%M:%S) "
valgrind -s ../build/icfs -o default_permissions ./protected &
sleep 1
# set up the fake-zenity
#export PATH="$(realpath ./mock/):$PATH"
# Try to touch files in the directory
#echo \"manual\" >./protected/manual
#export FAKE_ZENITY_RESPONSE="0"
parallel ::: "echo \"first\" >./protected/first 2> /dev/null \
&& echo \"[ICFS-TEST]: echo can create protected/first despite access being denied!\" \
|| echo \"[ICFS-TEST]: OK\"" \
"sleep 0.7 && xdotool key Escape" # EACCESS
parallel ::: "echo \"second\" >./protected/second 2> /dev/null \
&& echo \"[ICFS-TEST]: OK\" \
|| echo \"[ICFS-TEST]: echo cannot create protected/second despite access being permitted!\"" \
"sleep 0.7 && xdotool key KP_Enter" # OK
# Test whether permissons work
parallel ::: "cat ./protected/first > /dev/null 2> /dev/null \
&& echo \"[ICFS-TEST]: cat can read a non-existant file ./protected/first!\" \
|| echo \"[ICFS-TEST]: OK\"" # ENOENT
parallel ::: "cat ./protected/second > /dev/null 2> /dev/null \
&& echo \"[ICFS-TEST]: OK\" \
|| echo \"[ICFS-TEST]: cat cannot open protected/second despite access being permitted!\"" \
"sleep 0.7 && xdotool key KP_Enter" # "second"
parallel ::: "cat ./protected/this-only > /dev/null 2> /dev/null \
&& echo \"[ICFS-TEST]: OK\" \
|| echo \"[ICFS-TEST]: echo cannot create protected/second despite access being permitted!\"" \
"sleep 0.7 && xdotool key KP_Enter" # "Free code, free world."
#parallel ::: "cat ./protected/sudo-only > /dev/null 2> /dev/null \
# && echo \"[ICFS-TEST]: cat can access files owned by root!\" \
# || echo \"[ICFS-TEST]: OK\"" # EACCESS
# test the removal
parallel ::: "rm ./protected/do-not-remove > /dev/null 2> /dev/null \
&& echo \"[ICFS-TEST]: rm can unlink protected/do-not-remove despite access being denied!\" \
|| echo \"[ICFS-TEST]: OK\"" \
"sleep 0.7 && xdotool key Escape" # EACCESS
parallel ::: "rm ./protected/should-be-removed > /dev/null 2> /dev/null \
&& echo \"[ICFS-TEST]: OK\" \
|| echo \"[ICFS-TEST]: rm cannot unlink protected/should-be-removed despite access being permitted!\"" \
"sleep 0.7 && xdotool key KP_Enter" # OK
# unmount
umount $(realpath ./protected)