From ed6917ff22a551586fc6778903b93475b262e2e9 Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:30:16 +1300 Subject: [PATCH] tests: Migrate Dovecot DBox tests (sdbox + mdbox) (#3051) * tests: Migrate Dovecot DBox tests to new testing format * tests: Group Dovecot related tests into subfolder --- test/helper/common.bash | 3 +- .../set1/{ => dovecot}/dovecot_sieve.bats | 0 .../set1/dovecot/mailbox_format_dbox.bats | 59 +++++++++++++++++++ .../set1/{ => dovecot}/quotas_disabled.bats | 0 .../{ => dovecot}/special_use_folders.bats | 0 test/tests/serial/mail_with_mdbox.bats | 29 --------- test/tests/serial/mail_with_sdbox.bats | 29 --------- 7 files changed, 61 insertions(+), 59 deletions(-) rename test/tests/parallel/set1/{ => dovecot}/dovecot_sieve.bats (100%) create mode 100644 test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats rename test/tests/parallel/set1/{ => dovecot}/quotas_disabled.bats (100%) rename test/tests/parallel/set1/{ => dovecot}/special_use_folders.bats (100%) delete mode 100644 test/tests/serial/mail_with_mdbox.bats delete mode 100644 test/tests/serial/mail_with_sdbox.bats diff --git a/test/helper/common.bash b/test/helper/common.bash index e6dde10d..cc72f3e1 100644 --- a/test/helper/common.bash +++ b/test/helper/common.bash @@ -410,8 +410,9 @@ function _count_files_in_directory_in_container() _run_in_container_bash "[[ -d ${DIRECTORY} ]]" assert_success - _run_in_container_bash "find ${DIRECTORY} -maxdepth 1 -type f -printf 'x\n'" + _run_in_container_bash "find ${DIRECTORY} -maxdepth 1 -type f" assert_success + _should_output_number_of_lines "${NUMBER_OF_LINES}" } diff --git a/test/tests/parallel/set1/dovecot_sieve.bats b/test/tests/parallel/set1/dovecot/dovecot_sieve.bats similarity index 100% rename from test/tests/parallel/set1/dovecot_sieve.bats rename to test/tests/parallel/set1/dovecot/dovecot_sieve.bats diff --git a/test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats b/test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats new file mode 100644 index 00000000..b2b32777 --- /dev/null +++ b/test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats @@ -0,0 +1,59 @@ +load "${REPOSITORY_ROOT}/test/helper/common" +load "${REPOSITORY_ROOT}/test/helper/setup" + +# Feature (ENV DOVECOT_MAILBOX_FORMAT) - Logic in `setup-stack:_setup_dovecot()` +# - Configures mail_location in 10-mail.conf to a supported dbox type +# - Then adds a cron task to purge dbox for freeing disk space (see upstream docs) + +# PR: https://github.com/docker-mailserver/docker-mailserver/pull/1314 +# Docs (upstream): https://doc.dovecot.org/configuration_manual/mail_location/dbox/#dbox-settings + +BATS_TEST_NAME_PREFIX='[Dovecot] ' + +CONTAINER1_NAME='dms-test_dovecot-dbox_sdbox' +CONTAINER2_NAME='dms-test_dovecot-dbox_mdbox' + +function teardown() { _default_teardown ; } + +@test "(ENV DOVECOT_MAILBOX_FORMAT=sdbox) should store received mail at expected location" { + export CONTAINER_NAME=${CONTAINER1_NAME} + local CUSTOM_SETUP_ARGUMENTS=( + --env DOVECOT_MAILBOX_FORMAT=sdbox + --env PERMIT_DOCKER=container + ) + + _init_with_defaults + _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' + _wait_for_smtp_port_in_container + + _send_email 'existing-user1' + _wait_for_empty_mail_queue_in_container + + # Mail received should be stored as `u.1` (one file per message) + local MAILBOX_STORAGE='/var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails' + _count_files_in_directory_in_container "${MAILBOX_STORAGE}" 3 + assert_output --partial "${MAILBOX_STORAGE}/dovecot.index.log" + assert_output --partial "${MAILBOX_STORAGE}/u.1" + assert_output --partial "${MAILBOX_STORAGE}/dovecot.index.cache" +} + +@test "(ENV DOVECOT_MAILBOX_FORMAT=mdbox) should store received mail at expected location" { + export CONTAINER_NAME=${CONTAINER2_NAME} + local CUSTOM_SETUP_ARGUMENTS=( + --env DOVECOT_MAILBOX_FORMAT=mdbox + --env PERMIT_DOCKER=container + ) + + _init_with_defaults + _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' + _wait_for_smtp_port_in_container + + _send_email 'existing-user1' + _wait_for_empty_mail_queue_in_container + + # Mail received should be stored in `m.1` (1 or more messages) + local MAILBOX_STORAGE='/var/mail/localhost.localdomain/user1/storage' + _count_files_in_directory_in_container "${MAILBOX_STORAGE}" 2 + assert_output --partial "${MAILBOX_STORAGE}/dovecot.map.index.log" + assert_output --partial "${MAILBOX_STORAGE}/m.1" +} diff --git a/test/tests/parallel/set1/quotas_disabled.bats b/test/tests/parallel/set1/dovecot/quotas_disabled.bats similarity index 100% rename from test/tests/parallel/set1/quotas_disabled.bats rename to test/tests/parallel/set1/dovecot/quotas_disabled.bats diff --git a/test/tests/parallel/set1/special_use_folders.bats b/test/tests/parallel/set1/dovecot/special_use_folders.bats similarity index 100% rename from test/tests/parallel/set1/special_use_folders.bats rename to test/tests/parallel/set1/dovecot/special_use_folders.bats diff --git a/test/tests/serial/mail_with_mdbox.bats b/test/tests/serial/mail_with_mdbox.bats deleted file mode 100644 index d49b4608..00000000 --- a/test/tests/serial/mail_with_mdbox.bats +++ /dev/null @@ -1,29 +0,0 @@ -load "${REPOSITORY_ROOT}/test/test_helper/common" - -setup_file() { - local PRIVATE_CONFIG - PRIVATE_CONFIG=$(duplicate_config_for_container .) - - docker run -d --name mail_with_mdbox_format \ - -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_CLAMAV=0 \ - -e ENABLE_SPAMASSASSIN=0 \ - -e DOVECOT_MAILBOX_FORMAT=mdbox \ - -e PERMIT_DOCKER=host \ - -h mail.my-domain.com -t "${NAME}" - - wait_for_smtp_port_in_container mail_with_mdbox_format -} - -teardown_file() { - docker rm -f mail_with_mdbox_format -} - -@test "checking dovecot mailbox format: mdbox file created" { - run docker exec mail_with_mdbox_format /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" - assert_success - - # shellcheck disable=SC2016 - repeat_until_success_or_timeout 30 docker exec mail_with_mdbox_format /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/storage/m.1 | wc -l) -eq 1 ]' -} diff --git a/test/tests/serial/mail_with_sdbox.bats b/test/tests/serial/mail_with_sdbox.bats deleted file mode 100644 index 005b58f2..00000000 --- a/test/tests/serial/mail_with_sdbox.bats +++ /dev/null @@ -1,29 +0,0 @@ -load "${REPOSITORY_ROOT}/test/test_helper/common" - -setup_file() { - local PRIVATE_CONFIG - PRIVATE_CONFIG=$(duplicate_config_for_container .) - - docker run -d --name mail_with_sdbox_format \ - -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_CLAMAV=0 \ - -e ENABLE_SPAMASSASSIN=0 \ - -e DOVECOT_MAILBOX_FORMAT=sdbox \ - -e PERMIT_DOCKER=host \ - -h mail.my-domain.com -t "${NAME}" - - wait_for_smtp_port_in_container mail_with_sdbox_format -} - -teardown_file() { - docker rm -f mail_with_sdbox_format -} - -@test "checking dovecot mailbox format: sdbox file created" { - run docker exec mail_with_sdbox_format /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" - assert_success - - # shellcheck disable=SC2016 - repeat_until_success_or_timeout 30 docker exec mail_with_sdbox_format /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/mailboxes/INBOX/dbox-Mails/u.1 | wc -l) -eq 1 ]' -}