mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-06-03 19:00:50 +00:00
user_is tests addded
This commit is contained in:
parent
fa9e879e6a
commit
8549727aad
|
@ -104,4 +104,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w
|
|||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
|
|
@ -34,7 +34,8 @@ Install bashbot
|
|||
latest release zip from github] and extract all files.
|
||||
+
|
||||
As an alternative you can clone the github repository to get the latest
|
||||
improvements, run All-tests.sh to be shure.
|
||||
improvements/fixes, run bashbot test suite `All-tests.sh` afterwards to
|
||||
see if code looks OK.
|
||||
+
|
||||
....
|
||||
git clone https://github.com/topkecleon/telegram-bot-bash; test/ALL-tests.sh
|
||||
|
@ -76,6 +77,7 @@ Documentation
|
|||
** Test your Bot with shellcheck
|
||||
* link:doc/6_reference.md[Bashbot function reference]
|
||||
* link:doc/7_develop.md[Notes for bashbot developers]
|
||||
* link:doc/8_customize.md[Customize bashbot environment]
|
||||
|
||||
Note on Keyboards
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
@ -166,5 +168,5 @@ That's it!
|
|||
If you feel that there's something missing or if you found a bug, feel
|
||||
free to submit a pull request!
|
||||
|
||||
latexmath:[\[VERSION\]] v0.70-dev2-0-g4fff4c3
|
||||
+++++++++++++++++++++++++++++++++++++++++++++
|
||||
latexmath:[\[VERSION\]] v0.70-dev2-10-gfa9e879
|
||||
++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
# description: Start or stop telegram-bash-bot
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-8-gf412a29
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-2-g7ed47dd
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# list of additional files to check from shellcheck
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
bashbot.rc
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
# shellcheck disable=SC2016
|
||||
#
|
||||
# Easy Versioning in git:
|
||||
|
|
|
@ -61,5 +61,5 @@ group. This step is up to you actually.
|
|||
|
||||
#### [Next Getting started](2_usage.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -159,5 +159,5 @@ send_action "${CHAT[ID]}" "action"
|
|||
#### [Prev Create Bot](1_firstbot.md)
|
||||
#### [Next Advanced Usage](3_advanced.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
|
|||
#### [Prev Advanced Usage](3_advanced.md)
|
||||
#### [Next Expert Use](4_expert.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```.
|
|||
#### [Prev Expert Use](4_expert.md)
|
||||
#### [Next Best Practice](5_practice.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam
|
|||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Functions Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -163,6 +163,20 @@ fi
|
|||
```
|
||||
|
||||
----
|
||||
### User Access Control
|
||||
|
||||
##### user_is_botadmin
|
||||
Return true (0) if user is owner / admin of bot.
|
||||
Name or ID botadmin must be placed in './botadmin' file.
|
||||
|
||||
*usage:* user_is_botadmin "${USER[ID]}"
|
||||
|
||||
*alias:* _is_botadmin
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
_is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
|
||||
```
|
||||
|
||||
##### user_is_creator
|
||||
Return true (0) if user is creator of given chat or chat is a private chat.
|
||||
|
@ -186,19 +200,6 @@ if _is_admin ; then
|
|||
fi
|
||||
```
|
||||
|
||||
##### user_is_botadmin
|
||||
Return true (0) if user is owner / admin of bot.
|
||||
Name or ID botadmin must be placed in './botadmin' file.
|
||||
|
||||
*usage:* user_is_botadmin "${CHAT[ID]}" "${USER[ID]}"
|
||||
|
||||
*alias:* _is_botadmin
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
_is_botadmin && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
|
||||
```
|
||||
|
||||
##### user_is_allowed
|
||||
Bahsbot supports User Access Control, see [Advanced Usage](4_advanced.ma)
|
||||
|
||||
|
@ -348,5 +349,5 @@ Send Input from Telegram to waiting Interactive Chat.
|
|||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -71,5 +71,5 @@ fi
|
|||
#### [Prev Function Reference](6_function.md)
|
||||
#### [Next Bashbot Environment](8_custom.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-5-gfe5840d
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ Location of runtime data files 'data-bot-bash', 'count', downloaded files ...
|
|||
```
|
||||
|
||||
#### BASHBOT_COMMANDS
|
||||
Full path to bash script containing your commands, default: './commands.sh'
|
||||
Full path to bash script containing your commandsm, default: './commands.sh', must end with '.sh'
|
||||
```bash
|
||||
unset BASHBOT_COMMANDS # telegram-bot-bash/commands.sh (default)
|
||||
export BASHBOT_COMMANDS "" # telegram-bot-bash/commands.sh
|
||||
|
@ -48,7 +48,7 @@ Full path to bash script containing your commands, default: './commands.sh'
|
|||
export BASHBOT_COMMANDS "/etc/bashbot/bot2/commands.sh" # multibot configuration bot 2
|
||||
```
|
||||
#### BASHBOT_JSONSH
|
||||
Full path to JSON.sh script, default: './JSON.sh/JSON.sh'
|
||||
Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON.sh'.
|
||||
```bash
|
||||
unset BASHBOT_JSONSH # telegram-bot-bash/JSON.sh/JSON.sh (default)
|
||||
export BASHBOT_JSONSH "" # telegram-bot-bash/JSON.sh/JSON.sh
|
||||
|
@ -131,5 +131,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
|
|||
|
||||
#### [Prev Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-8-gf412a29
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
|
||||
SHELL=/bin/sh
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# ADD a new test skeleton to test dir, but does not activate test
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-9-g63ef678
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -60,6 +60,12 @@ 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 ...
|
||||
|
||||
EOF
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# common variables
|
||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -45,8 +45,8 @@ if [ "$fail" -eq 0 ]; then
|
|||
else
|
||||
/bin/echo -n 'FAILURE '
|
||||
exitcode=1
|
||||
rm -rf "${TESTENV}/test"
|
||||
find "${TESTENV}/"* ! -name '[a-z]-*' -delete
|
||||
#rm -rf "${TESTENV}/test"
|
||||
#find "${TESTENV}/"* ! -name '[a-z]-*' -delete
|
||||
fi
|
||||
|
||||
echo "${passed} / ${tests}"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
../dev/hooks/pre-commit.sh
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
../dev/hooks/pre-push.sh
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-0-g4fff4c3
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-4-g893ee61
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
|
58
test/d-user_is-test.sh
Executable file
58
test/d-user_is-test.sh
Executable file
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-10-gfa9e879
|
||||
|
||||
# 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
|
||||
echo " test \"user_is_botadmin\" ..."
|
||||
echo '?' >"${ADMINFILE}" # auto mode
|
||||
user_is_botadmin "BOTADMIN" || exit 1 # should never fail
|
||||
|
||||
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 ...
|
||||
echo " test \"user_is_allowed\" ..."
|
||||
echo " ... with not rules"
|
||||
user_is_allowed "NOBOTADMIN" "ANYTHING" && exit 1 # should always fail because not rules exist
|
||||
user_is_allowed "BOTADMIN" "ANYTHING" && exit 1 # should fail even is BOTADMIN
|
||||
echo "${SUCCESS}"
|
||||
|
||||
echo " ... with BOTADMIN:*:*"
|
||||
echo 'BOTADMIN:*:*' >"${ACLFILE}" # RULE allow BOTADMIN everything
|
||||
|
||||
user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should always work
|
||||
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
|
||||
|
||||
user_is_allowed "BOTADMIN" "ANYTHING" || exit 1 # should always work
|
||||
user_is_allowed "BOTADMIN" "SOMETHING" || exit 1 # should always work
|
||||
user_is_allowed "NOBOTADMIN" "SOMETHING" || exit 1 # should work
|
||||
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."
|
||||
|
Loading…
Reference in New Issue
Block a user