scripts: perform additional checks when updating/adding/deletting accounts (#4033)

* normalize accounts to lowercase
* update CHANGELOG
* add test to verify bug fix works correctly
This commit is contained in:
Georg Lauterbach 2024-05-25 19:56:19 +02:00 committed by GitHub
parent 4119849284
commit b222035112
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 0 deletions

View file

@ -13,6 +13,7 @@ function _manage_accounts() {
local PASSWD=${4}
_arg_expect_mail_account
_arg_check_mail_account
case "${ACTION}" in
( 'create' | 'update' )
@ -69,6 +70,15 @@ function _arg_expect_mail_account() {
[[ ${MAIL_ACCOUNT} =~ .*\@.* ]] || { __usage ; _exit_with_error "'${MAIL_ACCOUNT}' should include the domain (eg: user@example.com)" ; }
}
# Checks the mail account string, e.g. on uppercase letters.
function _arg_check_mail_account() {
if grep -q -E '[[:upper:]]+' <<< "${MAIL_ACCOUNT}"; then
local MAIL_ACCOUNT_NORMALIZED=${MAIL_ACCOUNT,,}
_log 'warn' "Mail account '${MAIL_ACCOUNT}' has uppercase letters and will be normalized to '${MAIL_ACCOUNT_NORMALIZED}'"
MAIL_ACCOUNT=${MAIL_ACCOUNT_NORMALIZED}
fi
}
function _account_should_not_exist_yet() {
__account_already_exists && _exit_with_error "'${MAIL_ACCOUNT}' already exists"
if [[ -f ${DATABASE_VIRTUAL} ]] && grep -q "^${MAIL_ACCOUNT}" "${DATABASE_VIRTUAL}"; then