Ensure that the account contains a @ (#923, #924)

* Ensure that the provided username actually contains a domain
* Update README.md to be consistent with addmailuser script
* Add a test to check if the username includes the domain
This commit is contained in:
Pierre-Yves Rofes 2018-04-04 18:59:28 +02:00 committed by Johan Smits
parent 7015d09404
commit 137d623171
3 changed files with 7 additions and 1 deletions

View file

@ -67,7 +67,7 @@ Download the docker-compose.yml, the .env and the setup.sh files:
#### Create your mail accounts #### Create your mail accounts
./setup.sh email add <email> [<password>] ./setup.sh email add <user@domain> [<password>]
#### Generate DKIM keys #### Generate DKIM keys

View file

@ -19,6 +19,7 @@ escape() {
} }
[ -z "$USER" ] && { usage; errex "no username specified"; } [ -z "$USER" ] && { usage; errex "no username specified"; }
expr index "$USER" "@" >/dev/null || { usage; errex "username must include the domain"; }
grep -qi "^$(escape "$USER")|" $DATABASE 2>/dev/null && grep -qi "^$(escape "$USER")|" $DATABASE 2>/dev/null &&
errex "User \"$USER\" already exists" errex "User \"$USER\" already exists"

View file

@ -1050,6 +1050,11 @@ load 'test_helper/bats-assert/load'
# #
# accounts # accounts
# #
@test "checking accounts: user_without_domain creation should be rejected since user@domain format is required" {
run docker exec mail /bin/sh -c "addmailuser user_without_domain mypassword"
assert_failure
assert_output --partial "username must include the domain"
}
@test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" { @test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" {
docker exec mail /bin/sh -c "addmailuser user3@domain.tld mypassword" docker exec mail /bin/sh -c "addmailuser user3@domain.tld mypassword"