Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require ["fileinto", "copy"];

if address :contains ["From"] "[email protected]" {
fileinto :copy "INBOX";
fileinto :copy "INBOX";
}

7 changes: 7 additions & 0 deletions test/config/dovecot-sieve/dovecot.sieve
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require ["fileinto"];

if address :contains ["From"] "[email protected]" {
fileinto "INBOX.spam";
} else {
keep;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
mail_max_userip_connections = 69
recipient_delimiter = ~
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
recipient_delimiter = ~
max_idle = 600s
# this is a comment
# this is also a comment
Expand Down
8 changes: 0 additions & 8 deletions test/config/sieve/dovecot.sieve

This file was deleted.

1 change: 1 addition & 0 deletions test/config/smtp-delivery/dovecot.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recipient_delimiter = ~
1 change: 1 addition & 0 deletions test/config/smtp-delivery/postfix-main.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recipient_delimiter = ~
5 changes: 5 additions & 0 deletions test/helper/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,8 @@ function wait_for_empty_mail_queue_in_container() {
# shellcheck disable=SC2016
repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" bash -c '[[ $(mailq) == *"Mail queue is empty"* ]]'
}

# `lines` is a special BATS variable updated via `run`:
function _should_output_number_of_lines() {
assert_equal "${#lines[@]}" $1
}
25 changes: 25 additions & 0 deletions test/tests/parallel/set1/spam_virus/amavis.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load "${REPOSITORY_ROOT}/test/helper/common"
load "${REPOSITORY_ROOT}/test/helper/setup"

TEST_NAME_PREFIX='Amavis:'
CONTAINER_NAME='dms-test_amavis'

function setup_file() {
init_with_defaults

local CUSTOM_SETUP_ARGUMENTS=(
--env ENABLE_AMAVIS=1
--env AMAVIS_LOGLEVEL=2
--env ENABLE_SPAMASSASSIN=1
)

common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
}

function teardown_file() { _default_teardown ; }

@test "${TEST_NAME_PREFIX} Amavis integration should be active" {
_run_in_container grep 'ANTI-SPAM-SA' /var/log/mail/mail.log
assert_output --partial 'loaded'
refute_output --partial 'NOT loaded'
}
47 changes: 47 additions & 0 deletions test/tests/parallel/set3/config-overrides.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
load "${REPOSITORY_ROOT}/test/helper/common"
load "${REPOSITORY_ROOT}/test/helper/setup"

TEST_NAME_PREFIX='Override Configs:'
CONTAINER_NAME='dms-test_config-overrides'

function setup_file() {
init_with_defaults

# Move override configs into main `/tmp/docker-mailserver` config location:
mv "${TEST_TMP_CONFIG}/override-configs/"* "${TEST_TMP_CONFIG}/"

common_container_setup
}

function teardown_file() { _default_teardown ; }

@test "${TEST_NAME_PREFIX}: Postfix - 'postfix-main.cf' overrides applied to '/etc/postfix/main.cf'" {
_run_in_container grep -q 'max_idle = 600s' /tmp/docker-mailserver/postfix-main.cf
assert_success

_run_in_container grep -q 'readme_directory = /tmp' /tmp/docker-mailserver/postfix-main.cf
assert_success

_run_in_container postconf
assert_success
assert_output --partial 'max_idle = 600s'
assert_output --partial 'readme_directory = /tmp'
}

@test "${TEST_NAME_PREFIX}: Postfix - 'postfix-master.cf' overrides applied to '/etc/postfix/master.cf'" {
_run_in_container grep -q 'submission/inet/smtpd_sasl_security_options=noanonymous' /tmp/docker-mailserver/postfix-master.cf
assert_success

_run_in_container postconf -M
assert_success
assert_output --partial '-o smtpd_sasl_security_options=noanonymous'
}

@test "${TEST_NAME_PREFIX}: Dovecot - 'dovecot.cf' overrides applied to '/etc/dovecot/local.conf'" {
_run_in_container grep -q 'mail_max_userip_connections = 69' /tmp/docker-mailserver/dovecot.cf
assert_success

_run_in_container doveconf
assert_success
assert_output --partial 'mail_max_userip_connections = 69'
}
63 changes: 63 additions & 0 deletions test/tests/parallel/set3/dovecot-sieve.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
load "${REPOSITORY_ROOT}/test/helper/common"
load "${REPOSITORY_ROOT}/test/helper/setup"

# Docs:
# https://docker-mailserver.github.io/docker-mailserver/edge/config/advanced/mail-sieve/

TEST_NAME_PREFIX='Dovecot [Sieve Support]:'
CONTAINER_NAME='dms-test_dovecot-sieve'

function setup_file() {
init_with_defaults

# Move sieve configs into main `/tmp/docker-mailserver` config location:
mv "${TEST_TMP_CONFIG}/dovecot-sieve/"* "${TEST_TMP_CONFIG}/"

local CONTAINER_ARGS_ENV_CUSTOM=(
--env ENABLE_MANAGESIEVE=1
# Required for mail delivery via nc:
--env PERMIT_DOCKER=container
# Mount into mail dir for user1 to treat as a user-sieve:
# NOTE: Cannot use ':ro', 'start-mailserver.sh' attempts to 'chown -R' /var/mail:
--volume "${TEST_TMP_CONFIG}/dovecot.sieve:/var/mail/localhost.localdomain/user1/.dovecot.sieve"
)
common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'

wait_for_smtp_port_in_container "${CONTAINER_NAME}"

# Single mail sent from '[email protected]' that is handled by User (relocate) and Global (copy) sieves for user1:
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt"
# Mail for user2 triggers the sieve-pipe:
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt"

wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}"
}

function teardown_file() { _default_teardown ; }

# dovecot-sieve/dovecot.sieve
@test "${TEST_NAME_PREFIX} User Sieve - should store mail from '[email protected]' into recipient (user1) mailbox 'INBOX.spam'" {
_run_in_container bash -c 'ls -A /var/mail/localhost.localdomain/user1/.INBOX.spam/new'
assert_success
_should_output_number_of_lines 1
}

# dovecot-sieve/before.dovecot.sieve
@test "${TEST_NAME_PREFIX} Global Sieve - should have copied mail from '[email protected]' to recipient (user1) inbox" {
_run_in_container grep 'Spambot <[email protected]>' -R /var/mail/localhost.localdomain/user1/new/
assert_success
}

# dovecot-sieve/sieve-pipe + dovecot-sieve/[email protected]
@test "${TEST_NAME_PREFIX} Sieve Pipe - should pipe mail received for user2 into '/tmp/pipe-test.out'" {
_run_in_container bash -c 'ls -A /tmp/pipe-test.out'
assert_success
_should_output_number_of_lines 1
}

# Only test coverage for feature is to check that the service is listening on the expected port:
# https://doc.dovecot.org/admin_manual/pigeonhole_managesieve_server/
@test "${TEST_NAME_PREFIX} ENV 'ENABLE_MANAGESIEVE' - should have enabled service on port 4190" {
_run_in_container bash -c 'nc -z 0.0.0.0 4190'
assert_success
}
Loading