tests: d-send and d-user printf conversion

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-02 16:39:33 +01:00
parent 7e1c1b51e1
commit f7b5c19cab
3 changed files with 52 additions and 27 deletions

View File

@ -5,12 +5,12 @@
# #
# USAGE: must run only from dev/all-tests.sh # USAGE: must run only from dev/all-tests.sh
# #
# DESCRIPTION: test sending messages # DESCRIPTION: test receiving messages
# #
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de # AUTHOR: KayM (gnadelwartz), kay@rrr.de
# #
#### $$VERSION$$ v1.21-pre-36-g0dfbf7b #### $$VERSION$$ v1.21-pre-37-g7e1c1b5
#=============================================================================== #===============================================================================
# include common functions and definitions # include common functions and definitions

View File

@ -1,5 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v1.21-dev-22-ga3efcd2 #===============================================================================
#
# FILE: d-send_message-test.sh
#
# USAGE: must run only from dev/all-tests.sh
#
# DESCRIPTION: test sending messages
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-pre-37-g7e1c1b5
#===============================================================================
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -16,7 +28,7 @@ source "${TESTDIR}/bashbot.sh" source
# shellcheck source=./bashbot.sh # shellcheck source=./bashbot.sh
source "${TESTDIR}/commands.sh" source source "${TESTDIR}/commands.sh" source
_is_function send_message || echo "Send Message not found!" _is_function send_message || printf "Send Message not found!\n"
# start writing your tests here ... # start writing your tests here ...
@ -35,7 +47,7 @@ sendUpload() {
# send text input to send_message # send text input to send_message
echo -n " Send line ..." printf " Send line ..."
# create dummy files for upload # create dummy files for upload
ALLOW='/tmp/allowed' ALLOW='/tmp/allowed'
@ -48,16 +60,17 @@ while read -r line ; do
set -x; set +e set -x; set +e
send_message "123456" "$line" >>"${OUTPUTFILE}" send_message "123456" "$line" >>"${OUTPUTFILE}"
set +x; set -e set +x; set -e
echo -n "." printf "."
done < "${INPUTFILE}" 2>>"${LOGFILE}" done < "${INPUTFILE}" 2>>"${LOGFILE}"
[ -d "$ALLOW" ] && rm -rf "$ALLOW" [ -d "$ALLOW" ] && rm -rf "$ALLOW"
echo " done." printf " done.\n"
{ compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v { compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v
rm -f "${REFFILE}.sort" rm -f "${REFFILE}.sort"
echo " ... all \"send_message\" functions seems to work as expected." printf " ... all \"send_message\" functions seems to work as expected.\n"
echo "${SUCCESS}"
printf "%s\n" "${SUCCESS}"

View File

@ -1,5 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v1.20-0-g2ab00a2 #===============================================================================
#
# FILE: d-user:is-test.sh
#
# 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
#
#### $$VERSION$$ v1.21-pre-37-g7e1c1b5
#===============================================================================
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -19,49 +31,49 @@ source "${TESTDIR}/commands.sh" source
# start writing your tests here ... # start writing your tests here ...
# first user asking for botadmin will botadmin # first user asking for botadmin will botadmin
echo "Check \"user_is_botadmin\" ..." printf "Check \"user_is_botadmin\" ...\n"
printf '["botadmin"] "?"\n' >>"${ADMINFILE}" # auto mode printf '["botadmin"] "?"\n' >>"${ADMINFILE}" # auto mode
echo "BOTADMIN ..." printf "BOTADMIN ...\n"
user_is_botadmin "BOTADMIN" || exit 1 # should never fail user_is_botadmin "BOTADMIN" || exit 1 # should never fail
echo "NOBOTADMIN ..." printf "NOBOTADMIN ...\n"
user_is_botadmin "NOBOTADMIN" && exit 1 # should fail user_is_botadmin "NOBOTADMIN" && exit 1 # should fail
echo "BOTADMIN ..." printf "BOTADMIN ...\n"
user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work
echo "Check config file ..." printf "Check config file ...\n"
if [ "$(getConfigKey "botadmin")" = "BOTADMIN" ]; then if [ "$(getConfigKey "botadmin")" = "BOTADMIN" ]; then
echo " ... \"user_is_botadmin\" seems to work as expected." printf " ... \"user_is_botadmin\" seems to work as expected.\n"
else else
exit 1 exit 1
fi fi
echo "${SUCCESS}" printf "%s\n" "${SUCCESS}"
# lets see If UAC works ... # lets see If UAC works ...
echo "Check \"user_is_allowed\" ..." printf "Check \"user_is_allowed\" ...\n"
echo " ... with not rules" printf " ... with not rules\n"
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because no rules exist user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because no rules exist
user_is_allowed "BOTADMIN" "ANYTHING" && exit 1 # should fail even is BOTADMIN user_is_allowed "BOTADMIN" "ANYTHING" && exit 1 # should fail even is BOTADMIN
echo "${SUCCESS}" printf "%s\n" "${SUCCESS}"
echo " ... with BOTADMIN:*:*" printf " ... with BOTADMIN:*:*\n"
echo 'BOTADMIN:*:*' >"${ACLFILE}" # RULE allow BOTADMIN everything printf 'BOTADMIN:*:*\n' >"${ACLFILE}" # RULE allow BOTADMIN everything
user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work now user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work now
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because user is not listed user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because user is not listed
echo "${SUCCESS}" printf "%s\n" "${SUCCESS}"
echo " ... with NOBOTAMIN:SOMETHING:*" printf " ... with NOBOTAMIN:SOMETHING:*\n"
echo 'NOBOTADMIN:SOMETHING:*' >>"${ACLFILE}" # RULE allow NOBOTADMIN something printf 'NOBOTADMIN:SOMETHING:*\n' >>"${ACLFILE}" # RULE allow NOBOTADMIN something
user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work
user_is_allowed "BOTADMIN" "SOMETHING" || exit 1 # should work user_is_allowed "BOTADMIN" "SOMETHING" || exit 1 # should work
user_is_allowed "NOBOTADMIN" "SOMETHING" || exit 1 # should work now user_is_allowed "NOBOTADMIN" "SOMETHING" || exit 1 # should work now
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because only SOMETHING is listed user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because only SOMETHING is listed
echo "${SUCCESS}" printf "%s\n" "${SUCCESS}"
echo " ... \"user_is_allowed\" seems to work as expected." printf " ... \"user_is_allowed\" seems to work as expected.\n"