From 137d623171daaf9f1219f96ca20d04b9c587d13e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rofes Date: Wed, 4 Apr 2018 18:59:28 +0200 Subject: [PATCH] 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 --- README.md | 2 +- target/bin/addmailuser | 1 + test/tests.bats | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 48d98a32..d15901ea 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Download the docker-compose.yml, the .env and the setup.sh files: #### Create your mail accounts - ./setup.sh email add [] + ./setup.sh email add [] #### Generate DKIM keys diff --git a/target/bin/addmailuser b/target/bin/addmailuser index 8d881cb1..9e613c81 100755 --- a/target/bin/addmailuser +++ b/target/bin/addmailuser @@ -19,6 +19,7 @@ escape() { } [ -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 && errex "User \"$USER\" already exists" diff --git a/test/tests.bats b/test/tests.bats index 3a6a0ad0..47127846 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1050,6 +1050,11 @@ load 'test_helper/bats-assert/load' # # 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" { docker exec mail /bin/sh -c "addmailuser user3@domain.tld mypassword"