mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
75a75bfae6
## Quick Summary Resolves a `TODO` task with `addmailuser`. ## Overview The main change is adding three new methods in `common.bash`, which replace the completion delay in `addmailuser` / `setup email add` command. Other than that: - I swapped `sh -c 'addmailuser ...'` to `setup email add ...`. - Improved three tests in `setup-cli.bats` for `setup email add|update|del` (_logic remains effectively the same still_). - Rewrote the `TODO` comment for `setup-cli.bats` test on `setup email del` to better clarify the concern, but the test itself was no longer affected due to changes prior to this PR, so I enabled the commented out assertion. - Removed unnecessary waits. The two `skip` tests in `test/tests.bats` could be enabled again after this PR. - Additional fixes to tests were made during the PR (see discussion comments for details), resolving race conditions. Individual commit messages of the PR provide additional details if helpful. --- ## Relevant commit messages * chore: Remove creation delay in `addmailuser` This was apparently only for supporting tests that need to wait on account creation being ready to test against. As per the removed inline docs, it should be fine to remove once tests are updated to work correctly without it. * tests(feat): Add two new common helper methods `wait_until_account_maildir_exists()` provides the same logic `addmailuser` command was carrying, to wait upon the account dir creation in `/var/mail`. As this was specifically to support tests, it makes more sense as a test method. `add_mail_account_then_wait_until_ready()` was added to handle the common pattern of creating account and waiting on it. An internal assert will ensure the account was successfully created first during the test before attempting to wait. * tests(feat): Add common helper for waiting on change event to be processed The current helper is more complicated for no real benefit, it only detects when a change is made that would trigger a change event in the `changedetector` service. Our usage of this in tests however is only interested in waiting out the completion of the change event. Remove unnecessary change event waits. These waits should not be necessary if handled correctly. * tests: `addmailuser` to `add_mail_account_then_wait_until_ready mail()` This helper method is used where appropriate. - A password is not relevant (optional). - We need to wait on the creation on the account (Dovecot and `/var/mail` directory). * tests: `setup-cli` revise `add`, `update`, `del` tests The delete test was failing as the `/var/mail` directory did not yet exist. There is now a proper delay imposed in the `add` test now shares the same account for both `update` and `del` tests resolving that failure. Additionally tests use better asserts where appropriate and the wait + sleep logic in `add` has been improved (now takes 10 seconds to complete, approx half the time than before). The `del` test TODO while not technically addressed is no longer relevant due to the tests being switched to `-c` option (there is a separate `no container` test file, but it doesn't provide a `del` test). * tests(fix): Ensure Postfix is reachable after waiting on ClamAV There is not much reason to check before waiting on ClamAV. It is more helpful to debug failures from `nc` mail send commands if we know that nothing went wrong inbetween the ClamAV wait time. Additionally added an assertion which should provide more information if this part of the test setup fails again. * tests(fix): Move health check to the top This test is a bit fragile. It relies on defaults for the healthcheck with intervals of 30 seconds. If the check occurs while Postfix is down due a change event from earlier tests and the healthcheck kicks in at that point, then if there is not enough time to refresh the health status from `unhealthy`, the test will fail with a false-positive as Postfix is actually working and up again.. * tests(fix): Wait on directory to be removed Workaround that tries not to introduce heavier delays by waiting on a full change event to complete in the previous `email update` if possible. There is a chance that the account has the folder deleted, but restored from an active change event (for password update, then the account delete).
52 lines
1.4 KiB
Bash
Executable file
52 lines
1.4 KiB
Bash
Executable file
#! /bin/bash
|
|
|
|
# shellcheck source=../scripts/helpers/index.sh
|
|
source /usr/local/bin/helpers/index.sh
|
|
|
|
function _main
|
|
{
|
|
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
|
|
|
|
local MAIL_ACCOUNT="${1}"
|
|
shift
|
|
local PASSWD="${*}"
|
|
|
|
_manage_accounts_create "${MAIL_ACCOUNT}" "${PASSWD}"
|
|
|
|
# NOTE: An account has only been added to `postfix-accounts.cf`.
|
|
# The `changedetector` service will be triggered from this update
|
|
# where the actual account is created in Dovecot. Expect a delay.
|
|
}
|
|
|
|
function __usage
|
|
{
|
|
printf '%s' "${PURPLE}addmailuser${RED}(${YELLOW}8${RED})
|
|
|
|
${ORANGE}USAGE${RESET}
|
|
./setup.sh email add <MAIL ACCOUNT> [<PASSWORD>]
|
|
|
|
${ORANGE}OPTIONS${RESET}
|
|
${BLUE}Generic Program Information${RESET}
|
|
help Print the usage information.
|
|
|
|
${ORANGE}DESCRIPTION${RESET}
|
|
Add a new mail account (email address).
|
|
|
|
To avoid a password being logged in the command history of your shell,
|
|
you may omit it, you'll be prompted to input the password instead.
|
|
|
|
${ORANGE}EXAMPLES${RESET}
|
|
${LWHITE}./setup.sh email add user@example.com${RESET}
|
|
Create the email account 'user@example.com'.
|
|
|
|
You will be prompted to input a password afterwards since no password was supplied.
|
|
|
|
${ORANGE}EXIT STATUS${RESET}
|
|
Exit status is 0 if command was successful. If wrong arguments are provided
|
|
or arguments contain errors, the script will exit early with exit status 1.
|
|
|
|
"
|
|
}
|
|
|
|
_main "${@}"
|