mirror of
https://github.com/docker-mailserver/docker-mailserver
synced 2024-10-18 10:18:07 +02:00
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:
parent
4119849284
commit
b222035112
@ -70,6 +70,8 @@ The most noteworthy change of this release is the update of the container's base
|
||||
- `supervisor-app.conf` renamed to `dms-services.conf`
|
||||
- **Rspamd**:
|
||||
- the Redis history key has been changed in order to not incorporate the hostname of the container (which is desirable in Kubernetes environments) ([#3927](https://github.com/docker-mailserver/docker-mailserver/pull/3927))
|
||||
- **Account Management**
|
||||
- addresses (accounts) are now normalized to lowercase automatically and a warning is logged in case uppercase letters are supplied
|
||||
|
||||
### Added
|
||||
|
||||
|
@ -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
|
||||
|
@ -74,6 +74,19 @@ function teardown_file() { _default_teardown ; }
|
||||
__should_add_new_user 'user3@domain.tld'
|
||||
}
|
||||
|
||||
@test "should add new user 'USeRx@domain.tld' as 'userx@domain.tld' into 'postfix-accounts.cf' and log a warning" {
|
||||
local MAIL_ACCOUNT='USeRx@domain.tld'
|
||||
local NORMALIZED_MAIL_ACCOUNT='userx@domain.tld'
|
||||
|
||||
_run_in_container setup email add "${MAIL_ACCOUNT}" mypassword
|
||||
assert_success
|
||||
assert_output --partial "'USeRx@domain.tld' has uppercase letters and will be normalized to 'userx@domain.tld'"
|
||||
|
||||
__check_mail_account_exists "${NORMALIZED_MAIL_ACCOUNT}"
|
||||
assert_success
|
||||
assert_output "${NORMALIZED_MAIL_ACCOUNT}"
|
||||
}
|
||||
|
||||
# To catch mistakes from substring matching:
|
||||
@test "should add new user 'auser3@domain.tld' into 'postfix-accounts.cf'" {
|
||||
__should_add_new_user 'auser3@domain.tld'
|
||||
|
Loading…
Reference in New Issue
Block a user