docker-mailserver/test/tests/parallel/set1/fetchmail.bats

78 lines
2.8 KiB
Plaintext
Raw Normal View History

tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
load "${REPOSITORY_ROOT}/test/helper/common"
load "${REPOSITORY_ROOT}/test/helper/setup"
BATS_TEST_NAME_PREFIX='[Fetchmail] '
CONTAINER1_NAME='dms-test_fetchmail'
CONTAINER2_NAME='dms-test_fetchmail_parallel'
function setup_file() {
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
export CONTAINER_NAME
tests(fix): Adjust for local testing conditions (#2606) * tests(fix): Increase some timeouts Running tests locally via a VM these tests would fail sometimes due to the time from being queued and Amavis actually processing being roughly around 30 seconds. There should be no harm in raising this to 60 seconds, other than delaying a failure case which will ripple through other time sensitive tests. It's better to pass when functionality is actually correct but just needs a bit longer to complete. * tests(fix): Don't setup an invalid hostname During container startup `helpers/dns.sh` would panic with `hostname -f` failing. Dropping `--domainname` for this container is fine and does not affect the point of it's test. --- It's unclear why this does not occur in CI. Possibly changes within the docker daemon since as CI runs docker on Ubuntu 20.04? (2020). For clarity, this may be equivalent to setting a hostname of `domain.com.domain.com`, or `--hostname` value truncated the NIS domain (`--domainname`) of the same value. IIRC, it would still fail with both options using different values if `--hostname` was multi-label. I believe I've documented how non-deterministic these options can be across different environments. `--hostname` should be preferred. There doesn't seem to be any reason to actually need `--domainname` (which is NIS domain name, unrelated to the DNS domain name). We still need to properly investigate reworking our ENV support that `dns.sh` manages. --- Containers were also not removing themselves after failures either (missing teardown). Which would cause problems when running tests again. * chore: Normalize white-space Sets a consistent indent size of 2 spaces. Previously this varied a fair bit, sometimes with tabs or mixed tabs and spaces. Some formatting with blank lines. Easier to review with white-space in diff ignored. Some minor edits besides blank lines, but no change in functionality. * fix: `setup.sh` target container under test Some of the `setup.sh` commands did not specify the container which was problematic if another `docker-mailserver` container was running, causing test failures. This probably doesn't help with `test/no_container.bats`, but at least prevents `test/tests.bats` failing at this point.
2022-05-30 00:53:30 +00:00
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
CONTAINER_NAME=${CONTAINER1_NAME}
local CUSTOM_SETUP_ARGUMENTS=(
--env ENABLE_FETCHMAIL=1
)
_init_with_defaults
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
mv "${TEST_TMP_CONFIG}/fetchmail/fetchmail.cf" "${TEST_TMP_CONFIG}/fetchmail.cf"
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
tests(fix): Adjust for local testing conditions (#2606) * tests(fix): Increase some timeouts Running tests locally via a VM these tests would fail sometimes due to the time from being queued and Amavis actually processing being roughly around 30 seconds. There should be no harm in raising this to 60 seconds, other than delaying a failure case which will ripple through other time sensitive tests. It's better to pass when functionality is actually correct but just needs a bit longer to complete. * tests(fix): Don't setup an invalid hostname During container startup `helpers/dns.sh` would panic with `hostname -f` failing. Dropping `--domainname` for this container is fine and does not affect the point of it's test. --- It's unclear why this does not occur in CI. Possibly changes within the docker daemon since as CI runs docker on Ubuntu 20.04? (2020). For clarity, this may be equivalent to setting a hostname of `domain.com.domain.com`, or `--hostname` value truncated the NIS domain (`--domainname`) of the same value. IIRC, it would still fail with both options using different values if `--hostname` was multi-label. I believe I've documented how non-deterministic these options can be across different environments. `--hostname` should be preferred. There doesn't seem to be any reason to actually need `--domainname` (which is NIS domain name, unrelated to the DNS domain name). We still need to properly investigate reworking our ENV support that `dns.sh` manages. --- Containers were also not removing themselves after failures either (missing teardown). Which would cause problems when running tests again. * chore: Normalize white-space Sets a consistent indent size of 2 spaces. Previously this varied a fair bit, sometimes with tabs or mixed tabs and spaces. Some formatting with blank lines. Easier to review with white-space in diff ignored. Some minor edits besides blank lines, but no change in functionality. * fix: `setup.sh` target container under test Some of the `setup.sh` commands did not specify the container which was problematic if another `docker-mailserver` container was running, causing test failures. This probably doesn't help with `test/no_container.bats`, but at least prevents `test/tests.bats` failing at this point.
2022-05-30 00:53:30 +00:00
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
CONTAINER_NAME=${CONTAINER2_NAME}
local CUSTOM_SETUP_ARGUMENTS=(
--env ENABLE_FETCHMAIL=1
--env FETCHMAIL_PARALLEL=1
)
_init_with_defaults
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
mv "${TEST_TMP_CONFIG}/fetchmail/fetchmail.cf" "${TEST_TMP_CONFIG}/fetchmail.cf"
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
}
function teardown_file() {
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
docker rm -f "${CONTAINER1_NAME}" "${CONTAINER2_NAME}"
}
# ENV `FETCHMAIL=1` runs `setup-stack.sh:_setup_fetchmail()`:
@test "(ENV ENABLE_FETCHMAIL=1) should configure /etc/fetchmailrc with fetchmail.cf contents" {
export CONTAINER_NAME=${CONTAINER1_NAME}
# /etc/fetchmailrc was created with general options copied from /etc/fetchmailrc_general:
_should_have_in_config 'set syslog' /etc/fetchmailrc
# fetchmail.cf content is appended into /etc/fetchmailrc:
# NOTE: FQDN value ends with a dot intentionally to avoid misleading DNS response:
# https://github.com/docker-mailserver/docker-mailserver/pull/1324
_should_have_in_config 'pop3.third-party.test.' /etc/fetchmailrc
}
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
# ENV `FETCHMAIL=1` runs `setup-stack.sh:_setup_fetchmail_parallel()`:
# fetchmail.cf should be parsed and split into multiple separate fetchmail configs:
# NOTE: Parallel fetchmail instances are checked in the `process-check-restart.bats` test.
@test "(ENV FETCHMAIL_PARALLEL=1) should create config fetchmail-1.rc" {
export CONTAINER_NAME=${CONTAINER2_NAME}
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
_should_have_in_config 'set syslog' /etc/fetchmailrc.d/fetchmail-1.rc
_should_have_in_config 'pop3.third-party.test.' /etc/fetchmailrc.d/fetchmail-1.rc
_should_not_have_in_config 'imap.remote-service.test.' /etc/fetchmailrc.d/fetchmail-1.rc
}
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
@test "(ENV FETCHMAIL_PARALLEL=1) should create config fetchmail-2.rc" {
export CONTAINER_NAME=${CONTAINER2_NAME}
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
_should_have_in_config 'set syslog' /etc/fetchmailrc.d/fetchmail-2.rc
_should_have_in_config 'imap.remote-service.test.' /etc/fetchmailrc.d/fetchmail-2.rc
_should_not_have_in_config 'pop3.third-party.test. ' /etc/fetchmailrc.d/fetchmail-2.rc
}
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
function _should_have_in_config() {
local MATCH_CONTENT=$1
local MATCH_IN_FILE=$2
_run_in_container grep -F "${MATCH_CONTENT}" "${MATCH_IN_FILE}"
assert_success
}
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
function _should_not_have_in_config() {
local MATCH_CONTENT=$1
local MATCH_IN_FILE=$2
tests(refactor): `mail_fetchmail.bats` + co-locate test cases for processes (#3010) * chore: Co-locate process checking and process restart verification Extract the test cases for checking a process is running and properly restarts from various test files into a single one: Core (always running): opendkim, opendmarc, master (postfix) ENV dependent: amavi (amavisd-new), clamd, dovecot, fail2ban-server (fail2ban), fetchmail, postgrey, postsrsd, saslauthd These now run off a single container with the required ENV and call a common function (the revised version in parallel test cases). * fix(saslauthd): Quote wrap supervisor config vars `saslauth.conf` calls `-O` option for most commands defined with an ENV that may be empty/null. This would cause the process to silently fail / die. This doesn't happen if quote wrapping the ENV, which calls `-O` with an empty string. Not necessary, but since one of `postgrey` ENV were quote wrapped in `supervisor-app.conf`, I've also done the same there. * fix(postsrsd): Change supervisor `autorestart` policy to `true` The PR that introduced the config switched from `true` to `unexpected` without any context. That prevents restart working when the process is killed. Setting to `true` instead will correctly restart the service. * chore: Remove disabled postgrey test file `mail_with_postgrey_disabled_by_default.bats` only checked the migrated test cases, removed as no longer serving a purpose. * tests(refactor): Make `_should_restart_when_killed()` more reliable The previous version did not ensure that the last checks process was actually restarted, only that it was running. It turns out that `pkill` is only sending the signal, there can be some delay before the original process is actually killed and restarted. This can be identified with `pgrep --older <seconds>`. First ensure the process is at a specified age, then after killing check that the process is not running that is at least that old, finally check that there is a younger process actually running.. (_could fail if a process doesn't restart, or there is a delay such as imposed by `sleep` in wrapper scripts for postfix and fail2ban_) The helper method is not used anywhere else now, move it into this test instead. It has been refactored to accomodate the needs for `--older`, and `--list-full` provides some output that can be matched (similar for `pkill --echo`). * test(docs): Add inline notes about processes * chore: Compress test cases into single case with loop Moves the list of processes into array vars to iterate through instead. If a failure occurs, the process name is visible along with line number in `_should_restart_when_killed()` to identify what went wrong. * chore: Handle `FETCHMAIL_PARALLEL=1` process checks as well * tests: Add test case for disabled ENV Additional coverage to match what other test files were doing before, ensuring that these ENV can prevent their respective service from running. * chore: Move `clamd` enabled check to it's own test case Not sure about this. It reduces the time of CPU activity (sustained full load on a thread) and increase in memory usage (1GB+ loading signatures database), but as a separate test case it also adds 10 seconds without reducing the time of the test case it was extracted from. * chore: Make `disabled` variant the 1st test case * fix: Adjust test cases to pass when using slower wrapper scripts * tests(refactor): `mail_fetchmail.bats` updated to new format Additionally merges in the parallel test file. * chore: Move `config/fetchmail.cf` into separate sub-directory Keep out of the default base config for tests. * chore: Change `fetchmail.cf` FQDNs to `.test` TLD Changed the first configs remote and local user values to more clearly document what their values should represent (_and that they don't need to be a full mail address, that's just what our Dovecot is configured with for login_). Shifted the `here` to the end of the `is` line. It's optional syntax, only intended to contrast with the remote `there` for readability. Additionally configured imap protocol. Not tested or verified if that's correct configuration for usage with imap protocol instead. The fetchmail feature tests are currently lacking. Added an inline doc into the fetchmail test to reference a PR about the importance of the trailing `.` in the config. Updated the partial matching to ensure it matches for that in the value as well. * chore: Finalize `process-check-restart.bats` Few minor adjustments. The other ENV for clamd doesn't seem to provide any benefit, trim out the noise. Added a note about why it's been split out. Fetchmail parallel configs are matching the config file path in the process command that is returned. The `.rc` suffix is just to add further clarity to that.
2023-01-18 01:42:55 +00:00
_run_in_container grep -F "${MATCH_CONTENT}" "${MATCH_IN_FILE}"
assert_failure
}