2020-10-23 17:40:11 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load /code/scripts/common.sh
|
|
|
|
load /code/scripts/common-run.sh
|
|
|
|
|
2020-10-23 18:51:02 +08:00
|
|
|
if [[ ! -f /etc/postfix/main.test-multi-comment ]]; then
|
|
|
|
cp /etc/postfix/main.cf /etc/postfix/main.test-multi-comment
|
|
|
|
fi
|
|
|
|
|
2020-10-23 17:40:11 +08:00
|
|
|
@test "make sure #myhostname appears four times in main.cf (default)" {
|
|
|
|
result=$(grep -E "^#myhostname" /etc/postfix/main.cf | wc -l)
|
2020-10-23 18:51:02 +08:00
|
|
|
[[ "$result" -gt 1 ]]
|
2020-10-23 17:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "make sure commenting out #myhostname does not incrase count" {
|
2020-10-23 18:51:02 +08:00
|
|
|
COMMENT_COUNT=$(grep -E "^#myhostname" /etc/postfix/main.test-multi-comment | wc -l)
|
2020-10-23 17:40:11 +08:00
|
|
|
do_postconf -# myhostname
|
2020-10-23 19:20:31 +08:00
|
|
|
postfix check
|
2020-10-23 17:40:11 +08:00
|
|
|
result=$(grep -E "^#myhostname" /etc/postfix/main.cf | wc -l)
|
2020-10-23 18:51:02 +08:00
|
|
|
[ "$result" == "$COMMENT_COUNT" ]
|
2020-10-23 17:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "make sure adding myhostname does not incrase count" {
|
2020-10-23 18:51:02 +08:00
|
|
|
COMMENT_COUNT=$(grep -E "^#myhostname" /etc/postfix/main.test-multi-comment | wc -l)
|
2020-10-23 17:40:11 +08:00
|
|
|
do_postconf -e myhostname=localhost
|
2020-10-23 19:20:31 +08:00
|
|
|
postfix check
|
2020-10-23 17:40:11 +08:00
|
|
|
result=$(grep -E "^#myhostname" /etc/postfix/main.cf | wc -l)
|
2020-10-23 18:51:02 +08:00
|
|
|
[ "$result" == "$COMMENT_COUNT" ]
|
2020-10-23 17:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "make sure adding myhostname is added only once" {
|
|
|
|
do_postconf -e myhostname=localhost
|
2020-10-23 19:20:31 +08:00
|
|
|
postfix check
|
2020-10-23 17:40:11 +08:00
|
|
|
result=$(grep -E "^myhostname" /etc/postfix/main.cf | wc -l)
|
|
|
|
[ "$result" == "1" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "make sure deleting myhostname does not incrase count" {
|
2020-10-23 18:51:02 +08:00
|
|
|
COMMENT_COUNT=$(grep -E "^#myhostname" /etc/postfix/main.test-multi-comment | wc -l)
|
2020-10-23 17:40:11 +08:00
|
|
|
do_postconf -# myhostname
|
2020-10-23 19:20:31 +08:00
|
|
|
postfix check
|
2020-10-23 17:40:11 +08:00
|
|
|
result=$(grep -E "^#myhostname" /etc/postfix/main.cf | wc -l)
|
2020-10-23 18:51:02 +08:00
|
|
|
[ "$result" == "$COMMENT_COUNT" ]
|
2020-10-23 17:40:11 +08:00
|
|
|
}
|
|
|
|
|
2020-10-23 19:20:31 +08:00
|
|
|
@test "test removing relayhost" {
|
|
|
|
do_postconf -# relayhost
|
|
|
|
grep -q -E "^#relayhost" /etc/postfix/main.cf
|
|
|
|
! grep -q -E "^relayhost" /etc/postfix/main.cf
|
|
|
|
postfix check
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "spaces in parameters" {
|
|
|
|
do_postconf -e "smtpd_recipient_restrictions=reject_non_fqdn_recipient, reject_unknown_recipient_domain, check_sender_access hash:example.org, reject"
|
|
|
|
postfix check
|
|
|
|
}
|
|
|
|
|
2020-10-23 17:40:11 +08:00
|
|
|
@test "no sasl password duplications" {
|
|
|
|
local RELAYHOST="demo"
|
|
|
|
local RELAYHOST_USERNAME="foo"
|
|
|
|
local RELAYHOST_PASSWORD="bar"
|
|
|
|
|
|
|
|
postfix_setup_relayhost
|
|
|
|
postfix_setup_relayhost
|
|
|
|
|
2020-10-23 19:20:31 +08:00
|
|
|
postfix check
|
|
|
|
|
2020-10-23 17:40:11 +08:00
|
|
|
result=$(grep -E "^demo" /etc/postfix/sasl_passwd | wc -l)
|
|
|
|
[ "$result" == "1" ]
|
|
|
|
}
|