Added script to update users password, made test and updated setup.sh

This commit is contained in:
Cody Alton 2016-12-20 22:14:32 -05:00
parent c4f434b28e
commit d8aa6edc10
3 changed files with 51 additions and 0 deletions

View File

@ -43,6 +43,7 @@ SUBCOMMANDS:
email:
$0 email add <email> <password>
$0 email update <email> <password>
$0 email del <email>
$0 email list
@ -115,6 +116,10 @@ case $1 in
shift
_docker_image addmailuser $@
;;
update)
shift
_docker_image updatemailuser
;;
del)
shift
_docker_image delmailuser $@

29
target/bin/updatemailuser Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
DATABASE=/tmp/docker-mailserver/postfix-accounts.cf
function usage {
echo 'Usage: updatemailuser <user@domain.tld> [password]'
exit 1
}
if [ ! -z "$1" ]; then
USER=$1
if [ -e "$DATABASE" ] && [ -z "$(grep $USER -i $DATABASE)" ]; then
echo "User doesn't exist"
exit 1
fi
if [ ! -z "$2" ]; then
PASS="$2"
else
read -s -p "Enter Password: " PASS
if [ -z "$PASS" ]; then
echo "Password can't be empty"
exit 1
fi
fi
ENTRY=$(echo "$USER|$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$PASS")")
sed -i.bak "s%^$USER.*%$ENTRY%g" $DATABASE
else
usage
fi

17
test/test_update_password.bats Executable file
View File

@ -0,0 +1,17 @@
@test "checking user updating password for user in /tmp/docker-mailserver/postfix-accounts.cf" {
docker exec mail /bin/sh -c "addmailuser user3@domain.tld mypassword"
initialpass=$(run docker exec mail /bin/sh -c "grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf")
sleep 2
docker exec mail /bin/sh -c "updatemailuser user3@domain.tld mynewpassword"
sleep 2
changepass=$(run docker exec mail /bin/sh -c "grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf")
if [ initialpass != changepass ]; then
status="0"
else
status="1"
fi
[ "$status" -eq 0 ]
}