diff --git a/Makefile b/Makefile index b4e3d339..02d2aedd 100644 --- a/Makefile +++ b/Makefile @@ -222,6 +222,8 @@ run: generate-accounts-after-run: docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf + docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' + sleep 10 fixtures: diff --git a/target/bin/addmailuser b/target/bin/addmailuser index 9e613c81..04b40b4b 100755 --- a/target/bin/addmailuser +++ b/target/bin/addmailuser @@ -3,7 +3,8 @@ DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf} USER="$1" -PASSWD="$2" +shift +PASSWD="$@" usage() { echo "Usage: addmailuser []" diff --git a/target/bin/updatemailuser b/target/bin/updatemailuser index e071b430..1d32d0f0 100755 --- a/target/bin/updatemailuser +++ b/target/bin/updatemailuser @@ -3,7 +3,8 @@ DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf} USER="$1" -PASSWD="$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$2")" +shift +PASSWD="$@" usage() { echo "Usage: updatemailuser [password]" @@ -20,6 +21,13 @@ escape() { [ -z "$USER" ] && { usage; errex "no username specified"; } +if [ -z "$PASSWD" ]; then + read -s -p "Enter Password: " PASSWD + echo + [ -z "$PASSWD" ] && errex "Password must not be empty" +fi +HASH="$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$PASSWD")" grep -qi "^$(escape "$USER")|" $DATABASE 2>/dev/null || errex "User \"$USER\" does not exist" -sed -i "s ^"$USER"|.* "$USER"|"$PASSWD" " $DATABASE + +sed -i "s ^"$USER"|.* "$USER"|"$HASH" " $DATABASE diff --git a/test/tests.bats b/test/tests.bats index 27c6f790..4bc6db65 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1198,12 +1198,6 @@ load 'test_helper/bats-assert/load' value=$(cat ./config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $1}') [ "$value" = "lorem@impsum.org" ] - # don't know why, but the test suite needs to delete the (non existant) user prior succeeding in adding him again. - # when executed directly against the container this workaround is not neccessary. - run docker exec mail delmailuser -y pass@localhorst.localdomain - assert_success - docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' - sleep 30 docker exec mail doveadm auth test -x service=smtp pass@localhost.localdomain 'may be \a `p^a.*ssword' | grep 'auth succeeded' assert_success } @@ -1215,13 +1209,13 @@ load 'test_helper/bats-assert/load' @test "checking setup.sh: setup.sh email update" { initialpass=$(cat ./config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') - run ./setup.sh -c mail email update lorem@impsum.org consectetur + run ./setup.sh email update lorem@impsum.org my password + sleep 10 updatepass=$(cat ./config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') - [ "$initialpass" != "$changepass" ] + [ "$initialpass" != "$updatepass" ] + assert_success - docker exec mail /bin/sh -c "updatemailuser pass@localhost.localdomain 'my other password'" - sleep 30 - docker exec mail /bin/sh -c "doveadm auth test -x service=smtp pass@localhost.localdomain 'my other password' | grep 'auth succeeded'" + docker exec mail doveadm pw -t "$updatepass" -p 'my password' | grep 'verified' assert_success }