2019-04-23 13:48:58 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-05-10 16:50:30 +00:00
|
|
|
#### $$VERSION$$ v0.72-0-ge899420
|
2019-04-23 13:48:58 +00:00
|
|
|
|
|
|
|
# include common functions and definitions
|
|
|
|
# shellcheck source=test/ALL-tests.inc.sh
|
|
|
|
source "./ALL-tests.inc.sh"
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd "${TESTDIR}" || exit 1
|
|
|
|
|
|
|
|
# source bashbot.sh function, uncomment if you want to test functions
|
|
|
|
# shellcheck source=./bashbot.sh
|
|
|
|
source "${TESTDIR}/bashbot.sh" source
|
|
|
|
|
|
|
|
# start writing your tests here ...
|
|
|
|
|
|
|
|
# first user asking for botadmin will botadmin
|
2019-04-23 16:11:24 +00:00
|
|
|
echo "Check \"user_is_botadmin\" ..."
|
2019-04-23 13:57:19 +00:00
|
|
|
|
2019-04-23 13:48:58 +00:00
|
|
|
echo '?' >"${ADMINFILE}" # auto mode
|
|
|
|
|
2019-04-23 13:57:19 +00:00
|
|
|
user_is_botadmin "BOTADMIN" || exit 1 # should never fail
|
2019-04-23 13:48:58 +00:00
|
|
|
user_is_botadmin "NOBOTADMIN" && exit 1 # should fail
|
|
|
|
user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work
|
|
|
|
|
|
|
|
if [ "$(cat "${ADMINFILE}")" = "BOTADMIN" ]; then
|
|
|
|
echo " ... \"user_is_botadmin\" seems to work as expected."
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "${SUCCESS}"
|
|
|
|
|
|
|
|
# lets see If UAC works ...
|
2019-04-23 16:11:24 +00:00
|
|
|
echo "Check \"user_is_allowed\" ..."
|
2019-04-23 13:57:19 +00:00
|
|
|
|
2019-04-23 13:48:58 +00:00
|
|
|
echo " ... with not rules"
|
2019-04-23 13:57:19 +00:00
|
|
|
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because no rules exist
|
2019-04-23 13:48:58 +00:00
|
|
|
user_is_allowed "BOTADMIN" "ANYTHING" && exit 1 # should fail even is BOTADMIN
|
|
|
|
echo "${SUCCESS}"
|
|
|
|
|
|
|
|
echo " ... with BOTADMIN:*:*"
|
|
|
|
echo 'BOTADMIN:*:*' >"${ACLFILE}" # RULE allow BOTADMIN everything
|
|
|
|
|
2019-04-23 13:57:19 +00:00
|
|
|
user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work now
|
2019-04-23 13:48:58 +00:00
|
|
|
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because user is not listed
|
|
|
|
echo "${SUCCESS}"
|
|
|
|
|
|
|
|
echo " ... with NOBOTAMIN:SOMETHING:*"
|
|
|
|
echo 'NOBOTADMIN:SOMETHING:*' >>"${ACLFILE}" # RULE allow NOBOTADMIN something
|
|
|
|
|
2019-04-23 13:57:19 +00:00
|
|
|
user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work
|
|
|
|
user_is_allowed "BOTADMIN" "SOMETHING" || exit 1 # should work
|
|
|
|
user_is_allowed "NOBOTADMIN" "SOMETHING" || exit 1 # should work now
|
2019-04-23 13:48:58 +00:00
|
|
|
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because only SOMETHING is listed
|
|
|
|
|
|
|
|
echo "${SUCCESS}"
|
|
|
|
|
|
|
|
echo " ... \"user_is_allowed\" seems to work as expected."
|
|
|
|
|