Skip to content

Commit abbb22d

Browse files
authored
Added email dkim tests (hestiacp#2601)
* Added email dkim tests * Fixes error when removing email dkim records and prevent removal of custom dkim selectors Fixes hestiacp#2602
1 parent 1ff8a4e commit abbb22d

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

bin/v-delete-mail-domain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fi
6060

6161
# Deleting dkim dns record
6262
if [ "$DKIM" = 'yes' ] && [ -e "$USER_DATA/dns/$domain.conf" ]; then
63-
dkim_records=$($BIN/v-list-dns-records "$user" "$domain" plain | awk '{print $1,$2}' | grep -w '_domainkey' | cut -f 1 -d ' ')
63+
dkim_records=$($BIN/v-list-dns-records "$user" "$domain" | grep -E "\s(mail\._domainkey|_domainkey)\s" | cut -f 1 -d ' ')
6464
for id in $dkim_records; do
6565
$BIN/v-delete-dns-record "$user" "$domain" "$id" '' 'yes'
6666
done

bin/v-delete-mail-domain-dkim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fi
5252

5353
# Deleting dns record
5454
if [ -n "$DNS_SYSTEM" ] && [ -e "$USER_DATA/dns/$domain.conf" ]; then
55-
records=$($BIN/v-list-dns-records "$user" "$domain" plain)
56-
dkim_records=$(echo "$records" |grep -w '_domainkey' | cut -f 1 -d ' ')
55+
records=$($BIN/v-list-dns-records "$user" "$domain")
56+
dkim_records=$(echo "$records" |grep -E "\s(mail\._domainkey|_domainkey)\s" | cut -f 1 -d ' ')
5757
for id in $dkim_records; do
5858
$BIN/v-delete-dns-record "$user" "$domain" "$id" 'yes'
5959
done
@@ -63,7 +63,7 @@ fi
6363
# Hestia #
6464
#----------------------------------------------------------#
6565

66-
# Updatoing config
66+
# Updating config
6767
update_object_value 'mail' 'DOMAIN' "$domain" '$DKIM' 'no'
6868
decrease_user_value "$user" '$U_MAIL_DKIM'
6969

test/test.bats

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,49 @@ function check_ip_not_banned(){
14681468
refute_output
14691469
}
14701470

1471+
@test "MAIL: Delete DKIM" {
1472+
run v-delete-mail-domain-dkim $user $domain
1473+
assert_success
1474+
refute_output
1475+
1476+
run grep "RECORD='_domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
1477+
assert_failure
1478+
refute_output
1479+
1480+
run grep "RECORD='mail._domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
1481+
assert_failure
1482+
refute_output
1483+
}
1484+
1485+
@test "MAIL: Add DKIM" {
1486+
run v-add-mail-domain-dkim $user $domain
1487+
assert_success
1488+
refute_output
1489+
1490+
run grep "RECORD='_domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
1491+
assert_success
1492+
assert_output --partial "RECORD='_domainkey' TYPE='TXT'"
1493+
1494+
run grep "RECORD='mail._domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
1495+
assert_success
1496+
assert_output --partial "RECORD='mail._domainkey' TYPE='TXT'"
1497+
}
1498+
1499+
@test "MAIL: Delete DKIM but preserve custom dkim records" {
1500+
run v-add-dns-record $user $domain 'k2._domainkey' 'TXT' 'v=DKIM1; k=rsa; p=123456'
1501+
assert_success
1502+
refute_output
1503+
1504+
run v-delete-mail-domain-dkim $user $domain
1505+
assert_success
1506+
refute_output
1507+
1508+
run grep "RECORD='k2._domainkey'" "${HESTIA}/data/users/${user}/dns/${domain}.conf"
1509+
assert_success
1510+
assert_output --partial "RECORD='k2._domainkey' TYPE='TXT'"
1511+
}
1512+
1513+
14711514
#----------------------------------------------------------#
14721515
# Limit possibilities adding different owner domain #
14731516
#----------------------------------------------------------#

0 commit comments

Comments
 (0)