From 2e06228b101b4deff794686e3cb997e458eb3d3b Mon Sep 17 00:00:00 2001 From: 17Halbe Date: Mon, 2 Apr 2018 16:55:54 +0200 Subject: [PATCH] Password creation fix (#908, #914) * fix password with spaces is stripped to first word --- target/bin/addmailuser | 4 ++-- target/bin/updatemailuser | 3 +-- test/tests.bats | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/target/bin/addmailuser b/target/bin/addmailuser index c9e83d9c..8d881cb1 100755 --- a/target/bin/addmailuser +++ b/target/bin/addmailuser @@ -28,5 +28,5 @@ if [ -z "$PASSWD" ]; then echo [ -z "$PASSWD" ] && errex "Password must not be empty" fi - -echo "$USER|$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$PASSWD")" >>$DATABASE +HASH="$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$PASSWD")" +echo "$USER|$HASH" >> $DATABASE diff --git a/target/bin/updatemailuser b/target/bin/updatemailuser index 0616c73d..e071b430 100755 --- a/target/bin/updatemailuser +++ b/target/bin/updatemailuser @@ -3,7 +3,7 @@ DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf} USER="$1" -PASSWD=$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$2") +PASSWD="$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$2")" usage() { echo "Usage: updatemailuser [password]" @@ -23,4 +23,3 @@ escape() { grep -qi "^$(escape "$USER")|" $DATABASE 2>/dev/null || errex "User \"$USER\" does not exist" sed -i "s ^"$USER"|.* "$USER"|"$PASSWD" " $DATABASE -#sed -i "s/^"$(escape "$USER")"|*/"$USER"|"$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$PASSWD")"/" $DATABASE diff --git a/test/tests.bats b/test/tests.bats index 8c9d38da..3a6a0ad0 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1188,17 +1188,34 @@ load 'test_helper/bats-assert/load' assert_success 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 } + @test "checking setup.sh: setup.sh email list" { run ./setup.sh -c mail email list assert_success } + @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 updatepass=$(cat ./config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') [ "$initialpass" != "$changepass" ] + + 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'" + assert_success } + @test "checking setup.sh: setup.sh email del" { run ./setup.sh -c mail email del -y lorem@impsum.org assert_success @@ -1243,7 +1260,6 @@ load 'test_helper/bats-assert/load' run /bin/sh -c 'cat ./config/postfix-virtual.cf | grep "test1@example.org test1@forward.com,test2@forward.com" | wc -l | grep 1' assert_success } - @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