Просмотр исходного кода

Fix is_mail_new function (#3785)

* Add new tests for mail
* Fix is_new_mail function in domain.sh
Jaap Marcus 2 лет назад
Родитель
Сommit
d6beef8afe
2 измененных файлов с 44 добавлено и 6 удалено
  1. 8 6
      func/domain.sh
  2. 36 0
      test/test.bats

+ 8 - 6
func/domain.sh

@@ -679,14 +679,16 @@ is_mail_domain_new() {
 is_mail_new() {
 	check_acc=$(grep "ACCOUNT='$1'" $USER_DATA/mail/$domain.conf)
 	if [ -n "$check_acc" ]; then
-		check_result "$E_EXISTS" "mail account $1 is already exists"
+		check_result "$E_EXISTS" "mail account $1 already exists"
 	fi
 	check_als=$(awk -F "ALIAS='" '{print $2}' $USER_DATA/mail/$domain.conf)
-	match=$(echo $check_als | cut -d "'" -f1)
-	parse_object_kv_list $(grep "ALIAS='$match'" $USER_DATA/mail/$domain.conf)
-	check_als=$(echo ",$ALIAS," | grep ",$1,")
-	if [ -n "$check_als" ]; then
-		check_result "$E_EXISTS" "mail alias $1 is already exists"
+	match=$(echo "$check_als" | cut -f 1 -d "'" | grep $1)
+	if [ -n "$match" ]; then
+		parse_object_kv_list $(grep "ALIAS='$match'" $USER_DATA/mail/$domain.conf)
+		check_als=$(echo ",$ALIAS," | grep ",$1,")
+		if [ -n "$check_als" ]; then
+			check_result "$E_EXISTS" "mail alias $1 already exists"
+		fi
 	fi
 }
 

+ 36 - 0
test/test.bats

@@ -1571,6 +1571,13 @@ function check_ip_not_banned(){
 	assert_failure $E_EXISTS
 }
 
+@test "MAIL: Add account 2" {
+	run v-add-mail-account $user $domain random "$userpass2"
+	assert_success
+	assert_file_contains  /etc/exim4/domains/$domain/limits "random@$domain"
+	refute_output
+}
+
 @test "MAIL: Add account alias" {
 	run v-add-mail-account-alias $user $domain test hestiacprocks
 	assert_success
@@ -1578,6 +1585,35 @@ function check_ip_not_banned(){
 	refute_output
 }
 
+@test "MAIL: Add account alias 2" {
+	run v-add-mail-account-alias $user $domain test hestiacprocks2
+	assert_success
+	assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacprocks2@$domain"
+	refute_output
+}
+
+@test "MAIL: Add account alias 3" {
+	run v-add-mail-account-alias $user $domain test hestiacp
+	assert_success
+	assert_file_contains /etc/exim4/domains/$domain/aliases "hestiacp@$domain"
+	refute_output
+}
+
+@test "MAIL: Add account 3" {
+	run v-add-mail-account $user $domain hestia "$userpass2"
+	assert_success
+	assert_file_contains /etc/exim4/domains/$domain/limits "hestia@$domain"
+	refute_output
+}
+
+@test "MAIL: Add account 4" {
+	run v-add-mail-account $user $domain hestiarocks3 "$userpass2"
+	assert_success
+	assert_file_contains /etc/exim4/domains/$domain/limits "hestiarocks3@$domain"
+	refute_output
+}
+
+
 @test "MAIL: Add account alias Invalid length" {
 	run v-add-mail-account-alias $user $domain test 'hestiacp-realy-rocks-but-i-want-to-have-feature-xyz-and-i-want-it-now'
 	assert_failure $E_INVALID