From dcf1d7511b2ce334d9a993672fed9e9bda9a615b Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Mon, 6 Feb 2023 19:33:28 +1300 Subject: [PATCH] tests(refactor): Revise ENV test cases for max mailbox and message sizes --- docs/content/config/environment.md | 8 ++-- mailserver.env | 4 +- .../parallel/set1/dovecot/dovecot_quotas.bats | 40 ++++++++++--------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/docs/content/config/environment.md b/docs/content/config/environment.md index f7187ccc..2fe380c3 100644 --- a/docs/content/config/environment.md +++ b/docs/content/config/environment.md @@ -220,9 +220,9 @@ Provide any valid URI. Examples: - `lmtps:inet::` (secure lmtp with starttls) - `lmtp::2003` (use kopano as mailstore) -##### POSTFIX\_MAILBOX\_SIZE\_LIMIT +##### POSTFIX_MAILBOX_SIZE_LIMIT -Set the mailbox size limit for all users. If set to zero, the size will be unlimited (default). +Set the mailbox size limit for all users. If set to zero, the size will be unlimited (default). Size is in bytes. - **empty** => 0 (no limit) @@ -233,9 +233,9 @@ Set the mailbox size limit for all users. If set to zero, the size will be unlim See [mailbox quota][docs-accounts]. -##### POSTFIX\_MESSAGE\_SIZE\_LIMIT +##### POSTFIX_MESSAGE_SIZE_LIMIT -Set the message size limit for all users. If set to zero, the size will be unlimited (not recommended!) +Set the message size limit for all users. If set to zero, the size will be unlimited (not recommended!). Size is in bytes. - **empty** => 10240000 (~10 MB) diff --git a/mailserver.env b/mailserver.env index 4ad776e5..ee10c4c3 100644 --- a/mailserver.env +++ b/mailserver.env @@ -195,7 +195,7 @@ VIRUSMAILS_DELETE_DELAY= # `lmtp::2003` (use kopano as mailstore) POSTFIX_DAGENT= -# Set the mailbox size limit for all users. If set to zero, the size will be unlimited (default). +# Set the mailbox size limit for all users. If set to zero, the size will be unlimited (default). Size is in bytes. # # empty => 0 POSTFIX_MAILBOX_SIZE_LIMIT= @@ -205,7 +205,7 @@ POSTFIX_MAILBOX_SIZE_LIMIT= # 1 => Dovecot quota is enabled ENABLE_QUOTAS=1 -# Set the message size limit for all users. If set to zero, the size will be unlimited (not recommended!) +# Set the message size limit for all users. If set to zero, the size will be unlimited (not recommended!). Size is in bytes. # # empty => 10240000 (~10 MB) POSTFIX_MESSAGE_SIZE_LIMIT= diff --git a/test/tests/parallel/set1/dovecot/dovecot_quotas.bats b/test/tests/parallel/set1/dovecot/dovecot_quotas.bats index 622215b6..a9a1d32a 100644 --- a/test/tests/parallel/set1/dovecot/dovecot_quotas.bats +++ b/test/tests/parallel/set1/dovecot/dovecot_quotas.bats @@ -114,38 +114,40 @@ function teardown_file() { _default_teardown ; } assert_output --partial 'check_policy_service inet:localhost:65265' } +@test '(ENV POSTFIX_MAILBOX_SIZE_LIMIT) should be configured for both Postfix and Dovecot' { + local MAILBOX_SIZE_POSTFIX MAILBOX_SIZE_DOVECOT MAILBOX_SIZE_POSTFIX_MB MAILBOX_SIZE_DOVECOT_MB -@test '(mailbox max size) should be equal for both Postfix and Dovecot' { - postfix_mailbox_size=$(_exec_in_container_bash "postconf | grep -Po '(?<=mailbox_size_limit = )[0-9]+'") - run echo "${postfix_mailbox_size}" + MAILBOX_SIZE_POSTFIX=$(_exec_in_container postconf -h mailbox_size_limit) + run echo "${MAILBOX_SIZE_POSTFIX}" 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}" + # Dovecot mailbox is sized by `virtual_mailbox_size` from Postfix: + MAILBOX_SIZE_DOVECOT=$(_exec_in_container postconf -h virtual_mailbox_limit) + assert_equal "${MAILBOX_SIZE_DOVECOT}" "${MAILBOX_SIZE_POSTFIX}" - 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}" + # Quota support: + MAILBOX_SIZE_POSTFIX_MB=$(( MAILBOX_SIZE_POSTFIX / 1000000)) + MAILBOX_SIZE_DOVECOT_MB=$(_exec_in_container_bash 'doveconf -h plugin/quota_rule | grep -oE "[0-9]+"') + run echo "${MAILBOX_SIZE_DOVECOT_MB}" refute_output "" - assert_equal "${postfix_mailbox_size_mb}" "${dovecot_mailbox_size_mb}" + assert_equal "${MAILBOX_SIZE_POSTFIX_MB}" "${MAILBOX_SIZE_DOVECOT_MB}" } +@test '(ENV POSTFIX_MESSAGE_SIZE_LIMIT) should be configured for both Postfix and Dovecot' { + local MESSAGE_SIZE_POSTFIX MESSAGE_SIZE_POSTFIX_MB MESSAGE_SIZE_DOVECOT_MB -@test '(message max size) should be equal for both Postfix and Dovecot' { - postfix_message_size=$(_exec_in_container_bash "postconf | grep -Po '(?<=message_size_limit = )[0-9]+'") - run echo "${postfix_message_size}" + MESSAGE_SIZE_POSTFIX=$(_exec_in_container postconf -h message_size_limit) + run echo "${MESSAGE_SIZE_POSTFIX}" 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}" + # Quota support: + MESSAGE_SIZE_POSTFIX_MB=$(( MESSAGE_SIZE_POSTFIX / 1000000)) + MESSAGE_SIZE_DOVECOT_MB=$(_exec_in_container_bash 'doveconf -h plugin/quota_max_mail_size | grep -oE "[0-9]+"') + run echo "${MESSAGE_SIZE_DOVECOT_MB}" refute_output "" - assert_equal "${postfix_message_size_mb}" "${dovecot_message_size_mb}" + assert_equal "${MESSAGE_SIZE_POSTFIX_MB}" "${MESSAGE_SIZE_DOVECOT_MB}" } @test 'Deleting an mailbox account should also remove that account from dovecot-quotas.cf' {