mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Handle missing files more gracefully. (#265)
* Wrote functional tests for desired behavior. Redoing the pull request, starting from current master. The tests now fail where expected. * Updated commands to handle missing files better. The functional tests now pass.
This commit is contained in:
parent
f707a11c98
commit
6d2d9dd738
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,6 +2,8 @@
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
.idea
|
.idea
|
||||||
test/config/empty/
|
test/config/empty/
|
||||||
|
test/config/without-accounts/
|
||||||
|
test/config/without-virtual/
|
||||||
test/config/postfix-accounts.cf
|
test/config/postfix-accounts.cf
|
||||||
test/config/letsencrypt/mail.my-domain.com/combined.pem
|
test/config/letsencrypt/mail.my-domain.com/combined.pem
|
||||||
test/onedir
|
test/onedir
|
||||||
|
|
|
@ -9,7 +9,7 @@ function usage {
|
||||||
|
|
||||||
if [ ! -z "$1" ]; then
|
if [ ! -z "$1" ]; then
|
||||||
USER=$1
|
USER=$1
|
||||||
if [ ! -z "$(grep $USER -i $DATABASE)" ]; then
|
if [ -e "$DATABASE" ] && [ ! -z "$(grep $USER -i $DATABASE)" ]; then
|
||||||
echo "User already exists"
|
echo "User already exists"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -9,8 +9,10 @@ function usage {
|
||||||
|
|
||||||
if [ ! -z "$1" ]; then
|
if [ ! -z "$1" ]; then
|
||||||
USER=$1
|
USER=$1
|
||||||
|
if [ -f "$DATABASE" ]; then
|
||||||
ENTRIES=$(grep "$USER" -vi $DATABASE)
|
ENTRIES=$(grep "$USER" -vi $DATABASE)
|
||||||
echo "$ENTRIES" > $DATABASE
|
echo "$ENTRIES" > $DATABASE
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -3,13 +3,16 @@
|
||||||
touch /tmp/vhost.tmp
|
touch /tmp/vhost.tmp
|
||||||
|
|
||||||
# Getting domains from mail accounts
|
# Getting domains from mail accounts
|
||||||
|
if [ -f /tmp/docker-mailserver/postfix-accounts.cf ]; then
|
||||||
while IFS=$'|' read login pass
|
while IFS=$'|' read login pass
|
||||||
do
|
do
|
||||||
domain=$(echo ${login} | cut -d @ -f2)
|
domain=$(echo ${login} | cut -d @ -f2)
|
||||||
echo ${domain} >> /tmp/vhost.tmp
|
echo ${domain} >> /tmp/vhost.tmp
|
||||||
done < /tmp/docker-mailserver/postfix-accounts.cf
|
done < /tmp/docker-mailserver/postfix-accounts.cf
|
||||||
|
fi
|
||||||
|
|
||||||
# Getting domains from mail aliases
|
# Getting domains from mail aliases
|
||||||
|
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
|
||||||
while read from to
|
while read from to
|
||||||
do
|
do
|
||||||
# Setting variables for better readability
|
# Setting variables for better readability
|
||||||
|
@ -18,12 +21,19 @@ do
|
||||||
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
||||||
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
|
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
|
||||||
done < /tmp/docker-mailserver/postfix-virtual.cf
|
done < /tmp/docker-mailserver/postfix-virtual.cf
|
||||||
|
fi
|
||||||
|
|
||||||
# Keeping unique entries
|
# Keeping unique entries
|
||||||
if [ -f /tmp/vhost.tmp ]; then
|
if [ -f /tmp/vhost.tmp ]; then
|
||||||
cat /tmp/vhost.tmp | sort | uniq > /tmp/vhost && rm /tmp/vhost.tmp
|
cat /tmp/vhost.tmp | sort | uniq > /tmp/vhost && rm /tmp/vhost.tmp
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Exit if no entries found
|
||||||
|
if [ ! -f /tmp/vhost ]; then
|
||||||
|
echo "No entries found, no keys to make"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
grep -vE '^(\s*$|#)' /tmp/vhost | while read domainname; do
|
grep -vE '^(\s*$|#)' /tmp/vhost | while read domainname; do
|
||||||
mkdir -p /tmp/docker-mailserver/opendkim/keys/$domainname
|
mkdir -p /tmp/docker-mailserver/opendkim/keys/$domainname
|
||||||
|
|
||||||
|
@ -56,9 +66,8 @@ grep -vE '^(\s*$|#)' /tmp/vhost | while read domainname; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Creates TrustedHosts if missing
|
# Creates TrustedHosts if missing
|
||||||
if [ ! -f "/tmp/docker-mailserver/opendkim/TrustedHosts" ]; then
|
if [ -d "/tmp/docker-mailserver/opendkim" ] && [ ! -f "/tmp/docker-mailserver/opendkim/TrustedHosts" ]; then
|
||||||
echo "Creating DKIM TrustedHosts";
|
echo "Creating DKIM TrustedHosts";
|
||||||
echo "127.0.0.1" > /tmp/docker-mailserver/opendkim/TrustedHosts
|
echo "127.0.0.1" > /tmp/docker-mailserver/opendkim/TrustedHosts
|
||||||
echo "localhost" >> /tmp/docker-mailserver/opendkim/TrustedHosts
|
echo "localhost" >> /tmp/docker-mailserver/opendkim/TrustedHosts
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -328,6 +328,62 @@
|
||||||
[ "$output" -eq 4 ]
|
[ "$output" -eq 4 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-accounts.cf" {
|
||||||
|
rm -rf "$(pwd)/test/config/without-accounts" && mkdir -p "$(pwd)/test/config/without-accounts"
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \
|
||||||
|
-v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" -eq 5 ]
|
||||||
|
# Check keys for localhost.localdomain
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-accounts/opendkim":/etc/opendkim \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" -eq 2 ]
|
||||||
|
# Check keys for otherdomain.tld
|
||||||
|
# run docker run --rm \
|
||||||
|
# -v "$(pwd)/test/config/without-accounts/opendkim":/etc/opendkim \
|
||||||
|
# `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l'
|
||||||
|
# [ "$status" -eq 0 ]
|
||||||
|
# [ "$output" -eq 0 ]
|
||||||
|
# Check presence of tables and TrustedHosts
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-accounts/opendkim":/etc/opendkim \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" -eq 4 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" {
|
||||||
|
rm -rf "$(pwd)/test/config/without-virtual" && mkdir -p "$(pwd)/test/config/without-virtual"
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-virtual/":/tmp/docker-mailserver/ \
|
||||||
|
-v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" -eq 5 ]
|
||||||
|
# Check keys for localhost.localdomain
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-virtual/opendkim":/etc/opendkim \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" -eq 2 ]
|
||||||
|
# Check keys for otherdomain.tld
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-virtual/opendkim":/etc/opendkim \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" -eq 2 ]
|
||||||
|
# Check presence of tables and TrustedHosts
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-virtual/opendkim":/etc/opendkim \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" -eq 4 ]
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# opendmarc
|
# opendmarc
|
||||||
#
|
#
|
||||||
|
@ -535,9 +591,29 @@
|
||||||
[ -z "$output" ]
|
[ -z "$output" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "checking accounts: no error is generated when deleting a user if /tmp/docker-mailserver/postfix-accounts.cf is missing" {
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'delmailuser user3@domain.tld'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ -z "$output" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" {
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'addmailuser user3@domain.tld mypassword'
|
||||||
|
run docker run --rm \
|
||||||
|
-v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \
|
||||||
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf'
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ ! -z "$output" ]
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# PERMIT_DOCKER mynetworks
|
# PERMIT_DOCKER mynetworks
|
||||||
#
|
#
|
||||||
|
|
||||||
@test "checking PERMIT_DOCKER: can get container ip" {
|
@test "checking PERMIT_DOCKER: can get container ip" {
|
||||||
run docker exec mail /bin/sh -c "ip addr show eth0 | grep 'inet ' | sed 's/[^0-9\.\/]*//g' | cut -d '/' -f 1 | egrep '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'"
|
run docker exec mail /bin/sh -c "ip addr show eth0 | grep 'inet ' | sed 's/[^0-9\.\/]*//g' | cut -d '/' -f 1 | egrep '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
|
Loading…
Reference in a new issue