2019-04-23 13:48:58 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-01-02 15:39:33 +00:00
|
|
|
#===============================================================================
|
|
|
|
#
|
2021-01-02 16:21:28 +00:00
|
|
|
# FILE: d-user_is-test.sh
|
2021-01-02 15:39:33 +00:00
|
|
|
#
|
|
|
|
# USAGE: must run only from dev/all-tests.sh
|
|
|
|
#
|
|
|
|
# DESCRIPTION: test user ACLs
|
|
|
|
#
|
|
|
|
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
|
|
|
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
|
|
|
#
|
2021-02-04 17:13:32 +00:00
|
|
|
#### $$VERSION$$ v1.40-0-gf9dab50
|
2021-01-02 15:39:33 +00:00
|
|
|
#===============================================================================
|
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
|
2019-05-13 09:24:42 +00:00
|
|
|
set +f
|
2019-04-23 13:48:58 +00:00
|
|
|
|
|
|
|
cd "${TESTDIR}" || exit 1
|
|
|
|
|
|
|
|
# source bashbot.sh function, uncomment if you want to test functions
|
|
|
|
# shellcheck source=./bashbot.sh
|
|
|
|
source "${TESTDIR}/bashbot.sh" source
|
2019-05-13 09:24:42 +00:00
|
|
|
# shellcheck source=./bashbot.sh
|
|
|
|
source "${TESTDIR}/commands.sh" source
|
2019-04-23 13:48:58 +00:00
|
|
|
|
|
|
|
# start writing your tests here ...
|
|
|
|
|
|
|
|
# first user asking for botadmin will botadmin
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "Check \"user_is_botadmin\" ...\n"
|
2019-04-23 13:57:19 +00:00
|
|
|
|
2020-06-27 16:31:35 +00:00
|
|
|
printf '["botadmin"] "?"\n' >>"${ADMINFILE}" # auto mode
|
2019-04-23 13:48:58 +00:00
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "BOTADMIN ...\n"
|
2019-04-23 13:57:19 +00:00
|
|
|
user_is_botadmin "BOTADMIN" || exit 1 # should never fail
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "NOBOTADMIN ...\n"
|
2019-04-23 13:48:58 +00:00
|
|
|
user_is_botadmin "NOBOTADMIN" && exit 1 # should fail
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "BOTADMIN ...\n"
|
2019-04-23 13:48:58 +00:00
|
|
|
user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work
|
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "Check config file ...\n"
|
2020-06-27 16:31:35 +00:00
|
|
|
if [ "$(getConfigKey "botadmin")" = "BOTADMIN" ]; then
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " ... \"user_is_botadmin\" seems to work as expected.\n"
|
2019-04-23 13:48:58 +00:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "%s\n" "${SUCCESS}"
|
2019-04-23 13:48:58 +00:00
|
|
|
|
|
|
|
# lets see If UAC works ...
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "Check \"user_is_allowed\" ...\n"
|
2019-04-23 13:57:19 +00:00
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " ... with not rules\n"
|
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
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "%s\n" "${SUCCESS}"
|
2019-04-23 13:48:58 +00:00
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " ... with BOTADMIN:*:*\n"
|
|
|
|
printf 'BOTADMIN:*:*\n' >"${ACLFILE}" # RULE allow BOTADMIN everything
|
2019-04-23 13:48:58 +00:00
|
|
|
|
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
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "%s\n" "${SUCCESS}"
|
2019-04-23 13:48:58 +00:00
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " ... with NOBOTAMIN:SOMETHING:*\n"
|
|
|
|
printf 'NOBOTADMIN:SOMETHING:*\n' >>"${ACLFILE}" # RULE allow NOBOTADMIN something
|
2019-04-23 13:48:58 +00:00
|
|
|
|
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
|
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "%s\n" "${SUCCESS}"
|
2019-04-23 13:48:58 +00:00
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " ... \"user_is_allowed\" seems to work as expected.\n"
|
2019-04-23 13:48:58 +00:00
|
|
|
|