1
0
mirror of https://github.com/docker-mailserver/docker-mailserver.git synced 2025-08-08 23:06:49 +02:00

tests(refactor): Extract mail account management tests from tests.bats (#3055)

* chore: Extract out accounts test cases from `tests.bats`

Standard test file format, the test cases have been copied over unmodified.

* chore: Revise test case descriptions

* tests(refactor): `accounts.bats`

Revised test cases:
- Some common test case logic extracted to test methods.
- Update direct user management commands to use the `setup email ...` variants.
- Improved assertions.
- Removed `sleep 2` lines as the need for that is ambiguous (may no longer be relevant?)
- Additional commentary for maintaining
- Two test cases for missing `postfix-accounts.cf` opted to just run the image without any volumes instead, as the `without-accounts/` folder  was empty anyway. 2nd test case can instead use a single `docker run` to check  the newly created`postfix-accounts.cf` content.
- `test/config/without-accounts/` remains as `open_dkim.bats` presently uses it.

* chore: Remove unnecessary account removal assert

Traced this back to the original PR where it appears to have been a typo and was probably intended as a cleanup on the `user4` account. Not necessary, removing.

* chore: Rename `accounts.bat` -> `account_management.bats`

---------

* feedback: Avoid `ls` for detecting directories

Replace `ls -d` approach from original test cases

Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>

* feedback: Remove asserting empty output on failure

Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
This commit is contained in:
Brennan Kinney
2023-02-04 11:52:30 +13:00
committed by GitHub
parent 774a340d76
commit 05db27f817
3 changed files with 164 additions and 136 deletions

View File

@ -31,7 +31,6 @@ function setup_file() {
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
_add_mail_account_then_wait_until_ready 'added@localhost.localdomain' 'mypassword'
_add_mail_account_then_wait_until_ready 'pass@localhost.localdomain' 'may be \a `p^a.*ssword'
_wait_for_service postfix
_wait_for_smtp_port_in_container
@ -114,44 +113,6 @@ function teardown_file() { _default_teardown ; }
assert_success
}
#
# accounts
#
@test "accounts: user accounts" {
_run_in_container doveadm user '*'
assert_success
assert_line --index 0 "user1@localhost.localdomain"
assert_line --index 1 "user2@otherdomain.tld"
assert_line --index 2 "user3@localhost.localdomain"
assert_line --index 3 "added@localhost.localdomain"
}
@test "accounts: user mail folder for user1" {
_run_in_container_bash "ls -d /var/mail/localhost.localdomain/user1"
assert_success
}
@test "accounts: user mail folder for user2" {
_run_in_container_bash "ls -d /var/mail/otherdomain.tld/user2"
assert_success
}
@test "accounts: user mail folder for user3" {
_run_in_container_bash "ls -d /var/mail/localhost.localdomain/user3"
assert_success
}
@test "accounts: user mail folder for added user" {
_run_in_container_bash "ls -d /var/mail/localhost.localdomain/added"
assert_success
}
@test "accounts: comments are not parsed" {
_run_in_container_bash "ls /var/mail | grep 'comment'"
assert_failure
}
#
# postfix
#
@ -283,103 +244,6 @@ zip
EOF
}
#
# accounts
#
@test "accounts: user_without_domain creation should be rejected since user@domain format is required" {
_run_in_container_bash "addmailuser user_without_domain mypassword"
assert_failure
assert_output --partial 'should include the domain (eg: user@example.com)'
}
@test "accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" {
_exec_in_container_bash "addmailuser user3@domain.tld mypassword"
_run_in_container_bash "grep '^user3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf"
assert_success
[[ -n ${output} ]]
}
@test "accounts: auser3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" {
_exec_in_container_bash "addmailuser auser3@domain.tld mypassword"
_run_in_container_bash "grep '^auser3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf"
assert_success
[[ -n ${output} ]]
}
@test "accounts: a.ser3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" {
_exec_in_container_bash "addmailuser a.ser3@domain.tld mypassword"
_run_in_container_bash "grep '^a\.ser3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf"
assert_success
[[ -n ${output} ]]
}
@test "accounts: user3 should have been removed from /tmp/docker-mailserver/postfix-accounts.cf but not auser3" {
_wait_until_account_maildir_exists 'user3@domain.tld'
_exec_in_container_bash "delmailuser -y user3@domain.tld"
_run_in_container_bash "grep '^user3@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf"
assert_failure
[[ -z ${output} ]]
_run_in_container_bash "grep '^auser3@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf"
assert_success
[[ -n ${output} ]]
}
@test "user updating password for user in /tmp/docker-mailserver/postfix-accounts.cf" {
_add_mail_account_then_wait_until_ready 'user4@domain.tld'
initialpass=$(_exec_in_container_bash "grep '^user4@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf")
sleep 2
_exec_in_container_bash "updatemailuser user4@domain.tld mynewpassword"
sleep 2
changepass=$(_exec_in_container_bash "grep '^user4@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf")
[[ ${initialpass} != "${changepass}" ]]
_run_in_container_bash "delmailuser -y auser3@domain.tld"
assert_success
}
@test "accounts: listmailuser (quotas disabled)" {
_run_in_container_bash "echo 'ENABLE_QUOTAS=0' >> /etc/dms-settings && listmailuser | head -n 1"
assert_success
assert_output '* user1@localhost.localdomain'
}
@test "accounts: listmailuser (quotas enabled)" {
_run_in_container_bash "sed -i '/ENABLE_QUOTAS=0/d' /etc/dms-settings; listmailuser | head -n 1"
assert_success
assert_output '* user1@localhost.localdomain ( 0 / ~ ) [0%]'
}
@test "accounts: no error is generated when deleting a user if /tmp/docker-mailserver/postfix-accounts.cf is missing" {
run docker run --rm \
-v "$(_duplicate_config_for_container without-accounts/ without-accounts-deleting-user)":/tmp/docker-mailserver/ \
"${IMAGE_NAME:?}" /bin/sh -c 'delmailuser -y user3@domain.tld'
assert_success
[[ -z ${output} ]]
}
@test "accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" {
local PRIVATE_CONFIG
PRIVATE_CONFIG=$(_duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist)
run docker run --rm \
-v "${PRIVATE_CONFIG}/without-accounts/":/tmp/docker-mailserver/ \
"${IMAGE_NAME:?}" /bin/sh -c 'addmailuser user3@domain.tld mypassword'
assert_success
run docker run --rm \
-v "${PRIVATE_CONFIG}/without-accounts/":/tmp/docker-mailserver/ \
"${IMAGE_NAME:?}" /bin/sh -c 'grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf'
assert_success
[[ -n ${output} ]]
}
@test "quota: setquota user must be existing" {
_add_mail_account_then_wait_until_ready 'quota_user@domain.tld'