mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-05 02:27:15 +02:00
tests(refactor): Dovecot quotas (#3068)
* chore: Extract out Dovecot Quota test cases into new test file Test cases are just cut + paste, no logic changed there yet. * chore: Rename test case descriptions * chore: Use `setup ...` methods instead of direct calls * chore: Adjust `_run_in_container_bash` to `_run_in_container` Plus some additional bug fixes in the disabled test case * tests(refactor): Revise ENV test cases for max mailbox and message sizes * tests(refactor): Revise ENV test cases for mailbox and message limits v2 Removes the extra variables and filtering in favour of explicit values instead of matching for comparison. - Easier at a glance to know what is actually expected. - Additionally reworks the quota limit checks in other test cases. Using a different formatter for `doveadm` is easier to match the desired value (`Limit`). * chore: Sync improvement from `tests.bats` master --- NOTE: This PR has been merged to avoid additional maintenance burden without losing the improvements. It was not considered complete, but remaining tasks were not documented in the PR.
This commit is contained in:
parent
ee87291225
commit
5908d9f060
5 changed files with 257 additions and 200 deletions
|
@ -17,7 +17,6 @@ function setup_file() {
|
|||
local CONTAINER_ARGS_ENV_CUSTOM=(
|
||||
--env ENABLE_AMAVIS=1
|
||||
--env AMAVIS_LOGLEVEL=2
|
||||
--env ENABLE_QUOTAS=1
|
||||
--env ENABLE_SRS=1
|
||||
--env PERMIT_DOCKER=host
|
||||
--env PFLOGSUMM_TRIGGER=logrotate
|
||||
|
@ -244,198 +243,6 @@ zip
|
|||
EOF
|
||||
}
|
||||
|
||||
@test "quota: setquota user must be existing" {
|
||||
_add_mail_account_then_wait_until_ready 'quota_user@domain.tld'
|
||||
|
||||
_run_in_container_bash "setquota quota_user 50M"
|
||||
assert_failure
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 50M"
|
||||
assert_success
|
||||
|
||||
_run_in_container_bash "setquota username@fulldomain 50M"
|
||||
assert_failure
|
||||
|
||||
_run_in_container_bash "delmailuser -y quota_user@domain.tld"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "quota: setquota <quota> must be well formatted" {
|
||||
_add_mail_account_then_wait_until_ready 'quota_user@domain.tld'
|
||||
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 26GIGOTS"
|
||||
assert_failure
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 123"
|
||||
assert_failure
|
||||
_run_in_container_bash "setquota quota_user@domain.tld M"
|
||||
assert_failure
|
||||
_run_in_container_bash "setquota quota_user@domain.tld -60M"
|
||||
assert_failure
|
||||
|
||||
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 10B"
|
||||
assert_success
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 10k"
|
||||
assert_success
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 10M"
|
||||
assert_success
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 10G"
|
||||
assert_success
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 10T"
|
||||
assert_success
|
||||
|
||||
|
||||
_run_in_container_bash "delmailuser -y quota_user@domain.tld"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "quota: delquota user must be existing" {
|
||||
_add_mail_account_then_wait_until_ready 'quota_user@domain.tld'
|
||||
|
||||
_run_in_container_bash "delquota uota_user@domain.tld"
|
||||
assert_failure
|
||||
_run_in_container_bash "delquota quota_user"
|
||||
assert_failure
|
||||
_run_in_container_bash "delquota dontknowyou@domain.tld"
|
||||
assert_failure
|
||||
|
||||
_run_in_container_bash "setquota quota_user@domain.tld 10T"
|
||||
assert_success
|
||||
_run_in_container_bash "delquota quota_user@domain.tld"
|
||||
assert_success
|
||||
_run_in_container_bash "grep -i 'quota_user@domain.tld' /tmp/docker-mailserver/dovecot-quotas.cf"
|
||||
assert_failure
|
||||
|
||||
_run_in_container_bash "delmailuser -y quota_user@domain.tld"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "quota: delquota allow when no quota for existing user" {
|
||||
_add_mail_account_then_wait_until_ready 'quota_user@domain.tld'
|
||||
|
||||
_run_in_container_bash "grep -i 'quota_user@domain.tld' /tmp/docker-mailserver/dovecot-quotas.cf"
|
||||
assert_failure
|
||||
|
||||
_run_in_container_bash "delquota quota_user@domain.tld"
|
||||
assert_success
|
||||
_run_in_container_bash "delquota quota_user@domain.tld"
|
||||
assert_success
|
||||
|
||||
_run_in_container_bash "delmailuser -y quota_user@domain.tld"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "quota: dovecot quota present in postconf" {
|
||||
_run_in_container_bash "postconf | grep 'check_policy_service inet:localhost:65265'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
|
||||
@test "quota: dovecot mailbox max size must be equal to postfix mailbox max size" {
|
||||
postfix_mailbox_size=$(_exec_in_container_bash "postconf | grep -Po '(?<=mailbox_size_limit = )[0-9]+'")
|
||||
run echo "${postfix_mailbox_size}"
|
||||
refute_output ""
|
||||
|
||||
# dovecot relies on virtual_mailbox_size by default
|
||||
postfix_virtual_mailbox_size=$(_exec_in_container_bash "postconf | grep -Po '(?<=virtual_mailbox_limit = )[0-9]+'")
|
||||
assert_equal "${postfix_virtual_mailbox_size}" "${postfix_mailbox_size}"
|
||||
|
||||
postfix_mailbox_size_mb=$(( postfix_mailbox_size / 1000000))
|
||||
|
||||
dovecot_mailbox_size_mb=$(_exec_in_container_bash "doveconf | grep -oP '(?<=quota_rule \= \*\:storage=)[0-9]+'")
|
||||
run echo "${dovecot_mailbox_size_mb}"
|
||||
refute_output ""
|
||||
|
||||
assert_equal "${postfix_mailbox_size_mb}" "${dovecot_mailbox_size_mb}"
|
||||
}
|
||||
|
||||
|
||||
@test "quota: dovecot message max size must be equal to postfix messsage max size" {
|
||||
postfix_message_size=$(_exec_in_container_bash "postconf | grep -Po '(?<=message_size_limit = )[0-9]+'")
|
||||
run echo "${postfix_message_size}"
|
||||
refute_output ""
|
||||
|
||||
postfix_message_size_mb=$(( postfix_message_size / 1000000))
|
||||
|
||||
dovecot_message_size_mb=$(_exec_in_container_bash "doveconf | grep -oP '(?<=quota_max_mail_size = )[0-9]+'")
|
||||
run echo "${dovecot_message_size_mb}"
|
||||
refute_output ""
|
||||
|
||||
assert_equal "${postfix_message_size_mb}" "${dovecot_message_size_mb}"
|
||||
}
|
||||
|
||||
@test "quota: quota directive is removed when mailbox is removed" {
|
||||
_add_mail_account_then_wait_until_ready 'quserremoved@domain.tld'
|
||||
|
||||
_run_in_container_bash "setquota quserremoved@domain.tld 12M"
|
||||
assert_success
|
||||
|
||||
_run_in_container_bash 'cat /tmp/docker-mailserver/dovecot-quotas.cf | grep -E "^quserremoved@domain.tld\:12M\$" | wc -l | grep 1'
|
||||
assert_success
|
||||
|
||||
_run_in_container_bash "delmailuser -y quserremoved@domain.tld"
|
||||
assert_success
|
||||
|
||||
_run_in_container_bash 'cat /tmp/docker-mailserver/dovecot-quotas.cf | grep -E "^quserremoved@domain.tld\:12M\$"'
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "quota: dovecot applies user quota" {
|
||||
_run_in_container_bash "doveadm quota get -u 'user1@localhost.localdomain' | grep 'User quota STORAGE'"
|
||||
assert_output --partial "- 0"
|
||||
|
||||
_run_in_container_bash "setquota user1@localhost.localdomain 50M"
|
||||
assert_success
|
||||
|
||||
# wait until quota has been updated
|
||||
run _repeat_until_success_or_timeout 20 _exec_in_container_bash 'doveadm quota get -u user1@localhost.localdomain | grep -oP "(User quota STORAGE\s+[0-9]+\s+)51200(.*)"'
|
||||
assert_success
|
||||
|
||||
_run_in_container_bash "delquota user1@localhost.localdomain"
|
||||
assert_success
|
||||
|
||||
# wait until quota has been updated
|
||||
run _repeat_until_success_or_timeout 20 _exec_in_container_bash 'doveadm quota get -u user1@localhost.localdomain | grep -oP "(User quota STORAGE\s+[0-9]+\s+)-(.*)"'
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "quota: warn message received when quota exceeded" {
|
||||
skip 'disabled as it fails randomly: https://github.com/docker-mailserver/docker-mailserver/pull/2511'
|
||||
|
||||
# create user
|
||||
_add_mail_account_then_wait_until_ready 'quotauser@otherdomain.tld'
|
||||
_run_in_container_bash 'setquota quotauser@otherdomain.tld 10k'
|
||||
assert_success
|
||||
|
||||
# wait until quota has been updated
|
||||
run _repeat_until_success_or_timeout 20 _exec_in_container_bash 'doveadm quota get -u quotauser@otherdomain.tld | grep -oP \"(User quota STORAGE\s+[0-9]+\s+)10(.*)\"'
|
||||
assert_success
|
||||
|
||||
# dovecot and postfix has been restarted
|
||||
_wait_for_service postfix
|
||||
_wait_for_service dovecot
|
||||
sleep 10
|
||||
|
||||
# send some big emails
|
||||
_send_email 'email-templates/quota-exceeded' '0.0.0.0 25'
|
||||
_send_email 'email-templates/quota-exceeded' '0.0.0.0 25'
|
||||
_send_email 'email-templates/quota-exceeded' '0.0.0.0 25'
|
||||
|
||||
# check for quota warn message existence
|
||||
run _repeat_until_success_or_timeout 20 _exec_in_container_bash 'grep \"Subject: quota warning\" /var/mail/otherdomain.tld/quotauser/new/ -R'
|
||||
assert_success
|
||||
|
||||
run _repeat_until_success_or_timeout 20 sh -c "docker logs mail | grep 'Quota exceeded (mailbox for user is full)'"
|
||||
assert_success
|
||||
|
||||
# ensure only the first big message and the warn message are present (other messages are rejected: mailbox is full)
|
||||
_run_in_container sh -c 'ls /var/mail/otherdomain.tld/quotauser/new/ | wc -l'
|
||||
assert_success
|
||||
assert_output "2"
|
||||
|
||||
_run_in_container_bash "delmailuser -y quotauser@otherdomain.tld"
|
||||
assert_success
|
||||
}
|
||||
|
||||
#
|
||||
# PERMIT_DOCKER mynetworks
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue