mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-01-14 18:09:48 +00:00
tests: d-send and d-user printf conversion
This commit is contained in:
parent
7e1c1b51e1
commit
f7b5c19cab
@ -5,12 +5,12 @@
|
||||
#
|
||||
# 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/
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
#
|
||||
#### $$VERSION$$ v1.21-pre-36-g0dfbf7b
|
||||
#### $$VERSION$$ v1.21-pre-37-g7e1c1b5
|
||||
#===============================================================================
|
||||
|
||||
# include common functions and definitions
|
||||
|
@ -1,5 +1,17 @@
|
||||
#!/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
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -16,7 +28,7 @@ source "${TESTDIR}/bashbot.sh" source
|
||||
# shellcheck source=./bashbot.sh
|
||||
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 ...
|
||||
|
||||
@ -35,7 +47,7 @@ sendUpload() {
|
||||
|
||||
# send text input to send_message
|
||||
|
||||
echo -n " Send line ..."
|
||||
printf " Send line ..."
|
||||
|
||||
# create dummy files for upload
|
||||
ALLOW='/tmp/allowed'
|
||||
@ -48,16 +60,17 @@ while read -r line ; do
|
||||
set -x; set +e
|
||||
send_message "123456" "$line" >>"${OUTPUTFILE}"
|
||||
set +x; set -e
|
||||
echo -n "."
|
||||
printf "."
|
||||
done < "${INPUTFILE}" 2>>"${LOGFILE}"
|
||||
[ -d "$ALLOW" ] && rm -rf "$ALLOW"
|
||||
|
||||
echo " done."
|
||||
printf " done.\n"
|
||||
|
||||
{ compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v
|
||||
rm -f "${REFFILE}.sort"
|
||||
|
||||
echo " ... all \"send_message\" functions seems to work as expected."
|
||||
echo "${SUCCESS}"
|
||||
printf " ... all \"send_message\" functions seems to work as expected.\n"
|
||||
|
||||
printf "%s\n" "${SUCCESS}"
|
||||
|
||||
|
||||
|
@ -1,5 +1,17 @@
|
||||
#!/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
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -19,49 +31,49 @@ source "${TESTDIR}/commands.sh" source
|
||||
# start writing your tests here ...
|
||||
|
||||
# first user asking for botadmin will botadmin
|
||||
echo "Check \"user_is_botadmin\" ..."
|
||||
printf "Check \"user_is_botadmin\" ...\n"
|
||||
|
||||
printf '["botadmin"] "?"\n' >>"${ADMINFILE}" # auto mode
|
||||
|
||||
echo "BOTADMIN ..."
|
||||
printf "BOTADMIN ...\n"
|
||||
user_is_botadmin "BOTADMIN" || exit 1 # should never fail
|
||||
echo "NOBOTADMIN ..."
|
||||
printf "NOBOTADMIN ...\n"
|
||||
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
|
||||
|
||||
echo "Check config file ..."
|
||||
printf "Check config file ...\n"
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
echo "${SUCCESS}"
|
||||
printf "%s\n" "${SUCCESS}"
|
||||
|
||||
# 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 "BOTADMIN" "ANYTHING" && exit 1 # should fail even is BOTADMIN
|
||||
echo "${SUCCESS}"
|
||||
printf "%s\n" "${SUCCESS}"
|
||||
|
||||
echo " ... with BOTADMIN:*:*"
|
||||
echo 'BOTADMIN:*:*' >"${ACLFILE}" # RULE allow BOTADMIN everything
|
||||
printf " ... with BOTADMIN:*:*\n"
|
||||
printf 'BOTADMIN:*:*\n' >"${ACLFILE}" # RULE allow BOTADMIN everything
|
||||
|
||||
user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should work now
|
||||
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should fail because user is not listed
|
||||
echo "${SUCCESS}"
|
||||
printf "%s\n" "${SUCCESS}"
|
||||
|
||||
echo " ... with NOBOTAMIN:SOMETHING:*"
|
||||
echo 'NOBOTADMIN:SOMETHING:*' >>"${ACLFILE}" # RULE allow NOBOTADMIN something
|
||||
printf " ... with NOBOTAMIN:SOMETHING:*\n"
|
||||
printf 'NOBOTADMIN:SOMETHING:*\n' >>"${ACLFILE}" # RULE allow NOBOTADMIN something
|
||||
|
||||
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
|
||||
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"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user