From 7a61214aa5797aaacc710fc9d55416b5e8e513c1 Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:31:37 +1300 Subject: [PATCH] tests: Migrate and combine ENV tests for `*_INET_PROTOCOLS` (#3052) * tests: Migrate and combine ENV tests for `*_INET_PROTOCOLS` These two features + tests were introduced years apart but serve the same purpose for both Postfix and Dovecot. --- .../parallel/set1/dovecot_inet_protocol.bats | 45 ----------- .../parallel/set1/network_inet_protocols.bats | 76 ++++++++++++++++++ test/tests/serial/mail_postfix_inet.bats | 80 ------------------- 3 files changed, 76 insertions(+), 125 deletions(-) delete mode 100644 test/tests/parallel/set1/dovecot_inet_protocol.bats create mode 100644 test/tests/parallel/set1/network_inet_protocols.bats delete mode 100644 test/tests/serial/mail_postfix_inet.bats diff --git a/test/tests/parallel/set1/dovecot_inet_protocol.bats b/test/tests/parallel/set1/dovecot_inet_protocol.bats deleted file mode 100644 index 5879471d..00000000 --- a/test/tests/parallel/set1/dovecot_inet_protocol.bats +++ /dev/null @@ -1,45 +0,0 @@ -load "${REPOSITORY_ROOT}/test/helper/setup" -load "${REPOSITORY_ROOT}/test/helper/common" - -BATS_TEST_NAME_PREFIX='[Dovecot] (protocols) ' -CONTAINER1_NAME='dms-test_dovecot_protocols_all' -CONTAINER2_NAME='dms-test_dovecot_protocols_ipv4' -CONTAINER3_NAME='dms-test_dovecot_protocols_ipv6' - -function teardown() { _default_teardown ; } - -@test "dual-stack IP configuration" { - export CONTAINER_NAME=${CONTAINER1_NAME} - local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=) - - _init_with_defaults - _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' - - _run_in_container grep '^#listen = \*, ::' /etc/dovecot/dovecot.conf - assert_success - assert_output '#listen = *, ::' -} - -@test "IPv4 configuration" { - export CONTAINER_NAME=${CONTAINER2_NAME} - local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=ipv4) - - _init_with_defaults - _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' - - _run_in_container grep '^listen = \*$' /etc/dovecot/dovecot.conf - assert_success - assert_output 'listen = *' -} - -@test "IPv6 configuration" { - export CONTAINER_NAME=${CONTAINER3_NAME} - local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=ipv6) - - _init_with_defaults - _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' - - _run_in_container grep '^listen = \[::\]$' /etc/dovecot/dovecot.conf - assert_success - assert_output 'listen = [::]' -} diff --git a/test/tests/parallel/set1/network_inet_protocols.bats b/test/tests/parallel/set1/network_inet_protocols.bats new file mode 100644 index 00000000..41a1ec78 --- /dev/null +++ b/test/tests/parallel/set1/network_inet_protocols.bats @@ -0,0 +1,76 @@ +load "${REPOSITORY_ROOT}/test/helper/setup" +load "${REPOSITORY_ROOT}/test/helper/common" + +# ENV support for restricting network types that Dovecot and Postfix listen on/ +# PRs: +# DOVECOT_INET_PROTOCOLS: https://github.com/docker-mailserver/docker-mailserver/pull/2358 +# POSTFIX_INET_PROTOCOLS: https://github.com/docker-mailserver/docker-mailserver/pull/1505 + +# Docs (upstream): +# https://doc.dovecot.org/settings/core/#core_setting-listen +# https://www.postfix.org/postconf.5.html#inet_protocols + +BATS_TEST_NAME_PREFIX='[Network] (ENV *_INET_PROTOCOLS) ' +CONTAINER1_NAME='dms-test_inet-protocols_all' +CONTAINER2_NAME='dms-test_inet-protocols_ipv4' +CONTAINER3_NAME='dms-test_inet-protocols_ipv6' + +function teardown() { _default_teardown ; } + +@test "should configure for dual-stack IP by default" { + export CONTAINER_NAME=${CONTAINER1_NAME} + # Unset (default) should be equivalent to 'all': + local CUSTOM_SETUP_ARGUMENTS=( + --env DOVECOT_INET_PROTOCOLS='' + --env POSTFIX_INET_PROTOCOLS='' + ) + + _init_with_defaults + _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' + + _run_in_container grep '^#listen =' /etc/dovecot/dovecot.conf + assert_success + assert_output '#listen = *, ::' + + _run_in_container postconf inet_protocols + assert_success + assert_output 'inet_protocols = all' +} + +@test "should configure for IPv4-only" { + export CONTAINER_NAME=${CONTAINER2_NAME} + local CUSTOM_SETUP_ARGUMENTS=( + --env DOVECOT_INET_PROTOCOLS='ipv4' + --env POSTFIX_INET_PROTOCOLS='ipv4' + ) + + _init_with_defaults + _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' + + _run_in_container grep '^listen =' /etc/dovecot/dovecot.conf + assert_success + assert_output 'listen = *' + + _run_in_container postconf inet_protocols + assert_success + assert_output 'inet_protocols = ipv4' +} + +@test "should configure for IPv6-only networks" { + export CONTAINER_NAME=${CONTAINER3_NAME} + local CUSTOM_SETUP_ARGUMENTS=( + --env DOVECOT_INET_PROTOCOLS='ipv6' + --env POSTFIX_INET_PROTOCOLS='ipv6' + ) + + _init_with_defaults + _common_container_setup 'CUSTOM_SETUP_ARGUMENTS' + + _run_in_container grep '^listen =' /etc/dovecot/dovecot.conf + assert_success + assert_output 'listen = [::]' + + _run_in_container postconf inet_protocols + assert_success + assert_output 'inet_protocols = ipv6' +} diff --git a/test/tests/serial/mail_postfix_inet.bats b/test/tests/serial/mail_postfix_inet.bats deleted file mode 100644 index 22656aa9..00000000 --- a/test/tests/serial/mail_postfix_inet.bats +++ /dev/null @@ -1,80 +0,0 @@ -load "${REPOSITORY_ROOT}/test/test_helper/common" - -# Test case -# --------- -# POSTFIX_INET_PROTOCOLS value is set - -@test "checking postfix: inet default" { - local PRIVATE_CONFIG - PRIVATE_CONFIG=$(duplicate_config_for_container . ) - - docker run -d --name mail_postfix_inet_default \ - -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -h mail.my-domain.com -t "${NAME}" - - teardown() { docker rm -f mail_postfix_inet_default; } - - wait_for_finished_setup_in_container mail_postfix_inet_default - - run docker exec mail_postfix_inet_default postconf inet_protocols - assert_output "inet_protocols = all" - assert_success -} - -@test "checking postfix: inet all" { - local PRIVATE_CONFIG - PRIVATE_CONFIG=$(duplicate_config_for_container . ) - - docker run -d --name mail_postfix_inet_all \ - -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e POSTFIX_INET_PROTOCOLS=all \ - -h mail.my-domain.com -t "${NAME}" - - teardown() { docker rm -f mail_postfix_inet_all; } - - wait_for_finished_setup_in_container mail_postfix_inet_all - - run docker exec mail_postfix_inet_all postconf inet_protocols - assert_output "inet_protocols = all" - assert_success -} - -@test "checking postfix: inet ipv4" { - local PRIVATE_CONFIG - PRIVATE_CONFIG=$(duplicate_config_for_container . ) - - docker run -d --name mail_postfix_inet_ipv4 \ - -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e POSTFIX_INET_PROTOCOLS=ipv4 \ - -h mail.my-domain.com -t "${NAME}" - - teardown() { docker rm -f mail_postfix_inet_ipv4; } - - wait_for_finished_setup_in_container mail_postfix_inet_ipv4 - - run docker exec mail_postfix_inet_ipv4 postconf inet_protocols - assert_output "inet_protocols = ipv4" - assert_success -} - -@test "checking postfix: inet ipv6" { - local PRIVATE_CONFIG - PRIVATE_CONFIG=$(duplicate_config_for_container . ) - - docker run -d --name mail_postfix_inet_ipv6 \ - -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e POSTFIX_INET_PROTOCOLS=ipv6 \ - -h mail.my-domain.com -t "${NAME}" - - teardown() { docker rm -f mail_postfix_inet_ipv6; } - - wait_for_finished_setup_in_container mail_postfix_inet_ipv6 - - run docker exec mail_postfix_inet_ipv6 postconf inet_protocols - assert_output "inet_protocols = ipv6" - assert_success -}