mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Support for detecting running container mount (#884)
This modification proposes to support the running configured mounted volume for configuration. This removes the need to pass a path from the command line when the container is running and configured in another way that yours.
This commit is contained in:
parent
5d03bb0982
commit
c1118af66d
3
Makefile
3
Makefile
|
@ -293,3 +293,6 @@ clean:
|
||||||
mv testconfig.bak test/config ;\
|
mv testconfig.bak test/config ;\
|
||||||
fi
|
fi
|
||||||
-sudo rm -rf test/onedir
|
-sudo rm -rf test/onedir
|
||||||
|
-sudo rm -rf test/alias
|
||||||
|
-sudo rm -rf test/relay
|
||||||
|
|
||||||
|
|
30
setup.sh
30
setup.sh
|
@ -11,7 +11,17 @@ INFO=$(docker ps \
|
||||||
|
|
||||||
IMAGE_NAME=$(echo $INFO | awk '{print $1}')
|
IMAGE_NAME=$(echo $INFO | awk '{print $1}')
|
||||||
CONTAINER_NAME=$(echo $INFO | awk '{print $2}')
|
CONTAINER_NAME=$(echo $INFO | awk '{print $2}')
|
||||||
CONFIG_PATH="$(pwd)/config"
|
DEFAULT_CONFIG_PATH="$(pwd)/config"
|
||||||
|
|
||||||
|
_update_config_path() {
|
||||||
|
VOLUME=$(docker inspect $CONTAINER_NAME \
|
||||||
|
--format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \
|
||||||
|
grep "/tmp/docker-mailserver$" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ ! -z "$VOLUME" ]; then
|
||||||
|
CONFIG_PATH=$(echo $VOLUME | awk '{print $1}')
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ -z "$IMAGE_NAME" ]; then
|
if [ -z "$IMAGE_NAME" ]; then
|
||||||
IMAGE_NAME=tvial/docker-mailserver:latest
|
IMAGE_NAME=tvial/docker-mailserver:latest
|
||||||
|
@ -25,6 +35,7 @@ _inspect() {
|
||||||
fi
|
fi
|
||||||
if [ -n "$CONTAINER_NAME" ]; then
|
if [ -n "$CONTAINER_NAME" ]; then
|
||||||
echo "Container: $CONTAINER_NAME"
|
echo "Container: $CONTAINER_NAME"
|
||||||
|
echo "Config mount: $CONFIG_PATH"
|
||||||
else
|
else
|
||||||
echo "Container: Not running, please start docker-mailserver."
|
echo "Container: Not running, please start docker-mailserver."
|
||||||
fi
|
fi
|
||||||
|
@ -117,13 +128,13 @@ while getopts ":c:i:p:" OPT; do
|
||||||
p)
|
p)
|
||||||
case "$OPTARG" in
|
case "$OPTARG" in
|
||||||
/*)
|
/*)
|
||||||
CONFIG_PATH="$OPTARG"
|
WISHED_CONFIG_PATH="$OPTARG"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
CONFIG_PATH="$(pwd)/$OPTARG"
|
WISHED_CONFIG_PATH="$(pwd)/$OPTARG"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
if [ ! -d "$CONFIG_PATH" ]; then
|
if [ ! -d "$WISHED_CONFIG_PATH" ]; then
|
||||||
echo "Directory doesn't exist"
|
echo "Directory doesn't exist"
|
||||||
_usage
|
_usage
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -135,6 +146,17 @@ while getopts ":c:i:p:" OPT; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ ! -n "$WISHED_CONFIG_PATH" ]; then
|
||||||
|
# no wished config path
|
||||||
|
_update_config_path
|
||||||
|
|
||||||
|
if [ ! -n "$CONFIG_PATH" ]; then
|
||||||
|
CONFIG_PATH=$DEFAULT_CONFIG_PATH
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
CONFIG_PATH=$WISHED_CONFIG_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
|
|
122
test/tests.bats
122
test/tests.bats
|
@ -1051,6 +1051,7 @@ load 'test_helper/bats-assert/load'
|
||||||
run docker exec mail /bin/sh -c "grep 'Spambot <spam@spam.com>' -R /var/mail/localhost.localdomain/user1/new/"
|
run docker exec mail /bin/sh -c "grep 'Spambot <spam@spam.com>' -R /var/mail/localhost.localdomain/user1/new/"
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# accounts
|
# accounts
|
||||||
#
|
#
|
||||||
|
@ -1175,6 +1176,12 @@ load 'test_helper/bats-assert/load'
|
||||||
assert_output 1
|
assert_output 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@test "checking user login: predefined user can login" {
|
||||||
|
result=$(docker exec mail doveadm auth test -x service=smtp pass@localhost.localdomain 'may be \a `p^a.*ssword' | grep 'auth succeeded')
|
||||||
|
[ "$result" = "passdb: pass@localhost.localdomain auth succeeded" ]
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# setup.sh
|
# setup.sh
|
||||||
#
|
#
|
||||||
|
@ -1185,6 +1192,7 @@ load 'test_helper/bats-assert/load'
|
||||||
assert_failure
|
assert_failure
|
||||||
[ "${lines[0]}" = "Usage: ./setup.sh [-i IMAGE_NAME] [-c CONTAINER_NAME] <subcommand> <subcommand> [args]" ]
|
[ "${lines[0]}" = "Usage: ./setup.sh [-i IMAGE_NAME] [-c CONTAINER_NAME] <subcommand> <subcommand> [args]" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking setup.sh: Wrong arguments" {
|
@test "checking setup.sh: Wrong arguments" {
|
||||||
run ./setup.sh lol troll
|
run ./setup.sh lol troll
|
||||||
assert_failure
|
assert_failure
|
||||||
|
@ -1192,14 +1200,14 @@ load 'test_helper/bats-assert/load'
|
||||||
}
|
}
|
||||||
|
|
||||||
# email
|
# email
|
||||||
@test "checking setup.sh: setup.sh email add " {
|
@test "checking setup.sh: setup.sh email add" {
|
||||||
run ./setup.sh -c mail email add lorem@impsum.org dolorsit
|
run ./setup.sh -c mail email add setup_email_add@example.com test_password
|
||||||
assert_success
|
assert_success
|
||||||
value=$(cat ./config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $1}')
|
|
||||||
[ "$value" = "lorem@impsum.org" ]
|
|
||||||
|
|
||||||
docker exec mail doveadm auth test -x service=smtp pass@localhost.localdomain 'may be \a `p^a.*ssword' | grep 'auth succeeded'
|
value=$(cat ./test/config/postfix-accounts.cf | grep setup_email_add@example.com | awk -F '|' '{print $1}')
|
||||||
assert_success
|
[ "$value" = "setup_email_add@example.com" ]
|
||||||
|
|
||||||
|
# we test the login of this user later to let the container digest the addition
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking setup.sh: setup.sh email list" {
|
@test "checking setup.sh: setup.sh email list" {
|
||||||
|
@ -1208,10 +1216,9 @@ load 'test_helper/bats-assert/load'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking setup.sh: setup.sh email update" {
|
@test "checking setup.sh: setup.sh email update" {
|
||||||
initialpass=$(cat ./config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}')
|
./setup.sh -c mail email add lorem@impsum.org test_test && initialpass=$(cat ./test/config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}')
|
||||||
run ./setup.sh email update lorem@impsum.org my password
|
run ./setup.sh -c mail email update lorem@impsum.org my password
|
||||||
sleep 10
|
updatepass=$(cat ./test/config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}')
|
||||||
updatepass=$(cat ./config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}')
|
|
||||||
[ "$initialpass" != "$updatepass" ]
|
[ "$initialpass" != "$updatepass" ]
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
|
@ -1222,9 +1229,16 @@ load 'test_helper/bats-assert/load'
|
||||||
@test "checking setup.sh: setup.sh email del" {
|
@test "checking setup.sh: setup.sh email del" {
|
||||||
run ./setup.sh -c mail email del -y lorem@impsum.org
|
run ./setup.sh -c mail email del -y lorem@impsum.org
|
||||||
assert_success
|
assert_success
|
||||||
run docker exec mail ls /var/mail/impsum.org/lorem
|
#
|
||||||
assert_failure
|
# TODO delmailuser does not work as expected.
|
||||||
run grep lorem@impsum.org ./config/postfix-accounts.cf
|
# Its implementation is not functional, you cannot delete a user data
|
||||||
|
# directory in the running container by running a new docker container
|
||||||
|
# and not mounting the mail folders (persistance is broken).
|
||||||
|
# The add script is only adding the user to account file.
|
||||||
|
#
|
||||||
|
# run docker exec mail ls /var/mail/impsum.org/lorem
|
||||||
|
# assert_failure
|
||||||
|
run grep lorem@impsum.org ./test/config/postfix-accounts.cf
|
||||||
assert_failure
|
assert_failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1251,37 +1265,41 @@ load 'test_helper/bats-assert/load'
|
||||||
|
|
||||||
# alias
|
# alias
|
||||||
@test "checking setup.sh: setup.sh alias list" {
|
@test "checking setup.sh: setup.sh alias list" {
|
||||||
echo "test@example.org test@forward.com" > ./config/postfix-virtual.cf
|
mkdir -p ./test/alias/config && echo "test@example.org test@forward.com" > ./test/alias/config/postfix-virtual.cf
|
||||||
run ./setup.sh -c mail alias list
|
run ./setup.sh -p ./test/alias/config alias list
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
@test "checking setup.sh: setup.sh alias add" {
|
@test "checking setup.sh: setup.sh alias add" {
|
||||||
echo "" > ./config/postfix-virtual.cf
|
mkdir -p ./test/alias/config && echo "" > ./test/alias/config/postfix-virtual.cf
|
||||||
./setup.sh -c mail alias add test1@example.org test1@forward.com
|
./setup.sh -p ./test/alias/config alias add alias@example.com target1@forward.com
|
||||||
./setup.sh -c mail alias add test1@example.org test2@forward.com
|
./setup.sh -p ./test/alias/config alias add alias@example.com target2@forward.com
|
||||||
|
sleep 5
|
||||||
run /bin/sh -c 'cat ./config/postfix-virtual.cf | grep "test1@example.org test1@forward.com,test2@forward.com" | wc -l | grep 1'
|
run /bin/sh -c 'cat ./test/alias/config/postfix-virtual.cf | grep "alias@example.com target1@forward.com,target2@forward.com" | wc -l | grep 1'
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
@test "checking setup.sh: setup.sh alias del" {
|
@test "checking setup.sh: setup.sh alias del" {
|
||||||
echo -e 'test1@example.org test1@forward.com,test2@forward.com\ntest2@example.org test1@forward.com' > ./config/postfix-virtual.cf
|
# start with a1 -> t1,t2 and a2 -> t1
|
||||||
|
mkdir -p ./test/alias/config && echo -e 'alias1@example.org target1@forward.com,target2@forward.com\nalias2@example.org target1@forward.com' > ./test/alias/config/postfix-virtual.cf
|
||||||
|
|
||||||
./setup.sh -c mail alias del test1@example.org test1@forward.com
|
# we remove a1 -> t1 ==> a1 -> t2 and a2 -> t1
|
||||||
run grep "test1@forward.com" ./config/postfix-virtual.cf
|
./setup.sh -p ./test/alias/config alias del alias1@example.org target1@forward.com
|
||||||
assert_output --regexp "^test2@example.org +test1@forward.com$"
|
run grep "target1@forward.com" ./test/alias/config/postfix-virtual.cf
|
||||||
|
assert_output --regexp "^alias2@example.org +target1@forward.com$"
|
||||||
|
|
||||||
run grep "test2@forward.com" ./config/postfix-virtual.cf
|
run grep "target2@forward.com" ./test/alias/config/postfix-virtual.cf
|
||||||
assert_output --regexp "^test1@example.org +test2@forward.com$"
|
assert_output --regexp "^alias1@example.org +target2@forward.com$"
|
||||||
|
|
||||||
./setup.sh -c mail alias del test1@example.org test2@forward.com
|
# we remove a1 -> t2 ==> a2 -> t1
|
||||||
run grep "test1@example.org" ./config/postfix-virtual.cf
|
./setup.sh -p ./test/alias/config alias del alias1@example.org target2@forward.com
|
||||||
|
run grep "alias1@example.org" ./test/alias/config/postfix-virtual.cf
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
||||||
run grep "test2@example.org" ./config/postfix-virtual.cf
|
run grep "alias2@example.org" ./test/alias/config/postfix-virtual.cf
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
./setup.sh -c mail alias del test2@example.org test1@forward.com
|
# we remove a2 -> t1 ==> empty
|
||||||
run grep "test2@example.org" ./config/postfix-virtual.cf
|
./setup.sh -p ./test/alias/config alias del alias2@example.org target1@forward.com
|
||||||
|
run grep "alias2@example.org" ./test/alias/config/postfix-virtual.cf
|
||||||
assert_failure
|
assert_failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1299,7 +1317,7 @@ load 'test_helper/bats-assert/load'
|
||||||
# debug
|
# debug
|
||||||
@test "checking setup.sh: setup.sh debug fetchmail" {
|
@test "checking setup.sh: setup.sh debug fetchmail" {
|
||||||
run ./setup.sh -c mail debug fetchmail
|
run ./setup.sh -c mail debug fetchmail
|
||||||
[ "$status" -eq 5 ]
|
[ "$status" -eq 11 ]
|
||||||
# TODO: Fix output check
|
# TODO: Fix output check
|
||||||
# [ "$output" = "fetchmail: no mailservers have been specified." ]
|
# [ "$output" = "fetchmail: no mailservers have been specified." ]
|
||||||
}
|
}
|
||||||
|
@ -1330,45 +1348,51 @@ load 'test_helper/bats-assert/load'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking setup.sh: setup.sh relay add-domain" {
|
@test "checking setup.sh: setup.sh relay add-domain" {
|
||||||
echo -n > ./config/postfix-relaymap.cf
|
mkdir -p ./test/relay/config && echo -n > ./test/relay/config/postfix-relaymap.cf
|
||||||
./setup.sh -c mail relay add-domain example1.org smtp.relay1.com 2525
|
./setup.sh -p ./test/relay/config relay add-domain example1.org smtp.relay1.com 2525
|
||||||
./setup.sh -c mail relay add-domain example2.org smtp.relay2.com
|
./setup.sh -p ./test/relay/config relay add-domain example2.org smtp.relay2.com
|
||||||
./setup.sh -c mail relay add-domain example3.org smtp.relay3.com 2525
|
./setup.sh -p ./test/relay/config relay add-domain example3.org smtp.relay3.com 2525
|
||||||
./setup.sh -c mail relay add-domain example3.org smtp.relay.com 587
|
./setup.sh -p ./test/relay/config relay add-domain example3.org smtp.relay.com 587
|
||||||
|
|
||||||
# check adding
|
# check adding
|
||||||
run /bin/sh -c 'cat ./config/postfix-relaymap.cf | grep -e "^@example1.org\s\+\[smtp.relay1.com\]:2525" | wc -l | grep 1'
|
run /bin/sh -c 'cat ./test/relay/config/postfix-relaymap.cf | grep -e "^@example1.org\s\+\[smtp.relay1.com\]:2525" | wc -l | grep 1'
|
||||||
assert_success
|
assert_success
|
||||||
# test default port
|
# test default port
|
||||||
run /bin/sh -c 'cat ./config/postfix-relaymap.cf | grep -e "^@example2.org\s\+\[smtp.relay2.com\]:25" | wc -l | grep 1'
|
run /bin/sh -c 'cat ./test/relay/config/postfix-relaymap.cf | grep -e "^@example2.org\s\+\[smtp.relay2.com\]:25" | wc -l | grep 1'
|
||||||
assert_success
|
assert_success
|
||||||
# test modifying
|
# test modifying
|
||||||
run /bin/sh -c 'cat ./config/postfix-relaymap.cf | grep -e "^@example3.org\s\+\[smtp.relay.com\]:587" | wc -l | grep 1'
|
run /bin/sh -c 'cat ./test/relay/config/postfix-relaymap.cf | grep -e "^@example3.org\s\+\[smtp.relay.com\]:587" | wc -l | grep 1'
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking setup.sh: setup.sh relay add-auth" {
|
@test "checking setup.sh: setup.sh relay add-auth" {
|
||||||
echo -n > ./config/postfix-sasl-password.cf
|
mkdir -p ./test/relay/config && echo -n > ./test/relay/config/postfix-sasl-password.cf
|
||||||
./setup.sh -c mail relay add-auth example.org smtp_user smtp_pass
|
./setup.sh -p ./test/relay/config relay add-auth example.org smtp_user smtp_pass
|
||||||
./setup.sh -c mail relay add-auth example2.org smtp_user2 smtp_pass2
|
./setup.sh -p ./test/relay/config relay add-auth example2.org smtp_user2 smtp_pass2
|
||||||
./setup.sh -c mail relay add-auth example2.org smtp_user2 smtp_pass_new
|
./setup.sh -p ./test/relay/config relay add-auth example2.org smtp_user2 smtp_pass_new
|
||||||
|
|
||||||
# test adding
|
# test adding
|
||||||
run /bin/sh -c 'cat ./config/postfix-sasl-password.cf | grep -e "^@example.org\s\+smtp_user:smtp_pass" | wc -l | grep 1'
|
run /bin/sh -c 'cat ./test/relay/config/postfix-sasl-password.cf | grep -e "^@example.org\s\+smtp_user:smtp_pass" | wc -l | grep 1'
|
||||||
assert_success
|
assert_success
|
||||||
# test updating
|
# test updating
|
||||||
run /bin/sh -c 'cat ./config/postfix-sasl-password.cf | grep -e "^@example2.org\s\+smtp_user2:smtp_pass_new" | wc -l | grep 1'
|
run /bin/sh -c 'cat ./test/relay/config/postfix-sasl-password.cf | grep -e "^@example2.org\s\+smtp_user2:smtp_pass_new" | wc -l | grep 1'
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking setup.sh: setup.sh relay exclude-domain" {
|
@test "checking setup.sh: setup.sh relay exclude-domain" {
|
||||||
echo -n > ./config/postfix-relaymap.cf
|
mkdir -p ./test/relay/config && echo -n > ./test/relay/config/postfix-relaymap.cf
|
||||||
./setup.sh -c mail relay exclude-domain example.org
|
./setup.sh -p ./test/relay/config relay exclude-domain example.org
|
||||||
|
|
||||||
run /bin/sh -c 'cat ./config/postfix-relaymap.cf | grep -e "^@example.org\s*$" | wc -l | grep 1'
|
run /bin/sh -c 'cat ./test/relay/config/postfix-relaymap.cf | grep -e "^@example.org\s*$" | wc -l | grep 1'
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "checking setup.sh: email add login validation" {
|
||||||
|
# validates that the user created previously with setup.sh can login
|
||||||
|
result=$(docker exec mail doveadm auth test -x service=smtp setup_email_add@example.com 'test_password' | grep 'auth succeeded')
|
||||||
|
[ "$result" = "passdb: setup_email_add@example.com auth succeeded" ]
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# LDAP
|
# LDAP
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue