s3:tests: Add test for changing the local user password with smbpasswd
authorAndreas Schneider <asn@samba.org>
Mon, 21 Aug 2017 10:23:56 +0000 (12:23 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 23 Aug 2017 15:05:48 +0000 (17:05 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12975

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Wed Aug 23 17:05:48 CEST 2017 on sn-devel-144

source3/script/tests/test_smbpasswd.sh [new file with mode: 0755]
source3/selftest/tests.py

diff --git a/source3/script/tests/test_smbpasswd.sh b/source3/script/tests/test_smbpasswd.sh
new file mode 100755 (executable)
index 0000000..62b37a0
--- /dev/null
@@ -0,0 +1,132 @@
+#!/bin/sh
+#
+# Blackbox tests for smbpasswd
+#
+# Copyright (c) 2015-2016 Andreas Schneider <asn@samba.org>
+#
+
+if [ $# -lt 4 ]; then
+cat <<EOF
+Usage: test_smbpasswd.sh SERVER USERNAME PASSWORD
+EOF
+exit 1;
+fi
+
+SERVER=$1
+SERVER_IP=$2
+USERNAME=$3
+PASSWORD=$4
+shift 4
+
+incdir=$(dirname $0)/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+failed=0
+
+samba_bindir="$BINDIR"
+samba_srcdir="$SRCDIR"
+
+samba_texpect="$samba_bindir/texpect"
+samba_smbpasswd="$samba_bindir/smbpasswd"
+
+samba_test_user="alice_smbpasswd"
+samba_test_user_pwd="Secret007"
+samba_test_user_new_pwd="Secret008"
+
+create_local_smb_user()
+{
+       user=$1
+       password=$2
+
+       tmpfile=$PREFIX/smbpasswd_create_user_script
+       cat > $tmpfile <<EOF
+expect New SMB password:
+send $password\n
+expect Retype new SMB password:
+send $password\n
+EOF
+
+       cmd='UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $samba_texpect $tmpfile $samba_smbpasswd -c $SMB_CONF_PATH -a $user 2>&1'
+       eval echo "$cmd"
+       out=$(eval $cmd)
+       ret=$?
+
+       rm -f $tmpfile
+
+       if [ $ret -ne 0 ]; then
+               echo "Failed to create smb user $user"
+               return 1
+       fi
+
+       getent passwd $user
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               echo "Failed to create smb user $user"
+               return 1
+       fi
+}
+
+delete_local_smb_user()
+{
+       user=$1
+
+       # This also deletes the unix account!
+       UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $samba_smbpasswd -c $SMB_CONF_PATH -x $user
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               echo "Failed to delete smb user $user"
+               return 1
+       fi
+}
+
+test_smbpasswd()
+{
+       user=$1
+       oldpwd=$2
+       newpwd=$3
+
+       user_id=$(id -u $user)
+
+       tmpfile=$PREFIX/smbpasswd_change_password_script
+       cat > $tmpfile <<EOF
+expect Old SMB password:
+send $oldpwd\n
+expect New SMB password:
+send $newpwd\n
+expect Retype new SMB password:
+send $newpwd\n
+EOF
+
+       cmd='UID_WRAPPER_INITIAL_RUID=$user_id UID_WRAPPER_INITIAL_EUID=$user_id $samba_texpect $tmpfile $samba_smbpasswd -c $SMB_CONF_PATH -r $SERVER 2>&1'
+       eval echo "$cmd"
+       out=$(eval $cmd)
+       ret=$?
+       rm -f $tmpfile
+       if [ $ret -ne 0 ]; then
+               echo "Failed to change user password $user"
+               return 1
+       fi
+
+       prompt="Password changed for user $user"
+       echo "$out" | grep "$prompt" >/dev/null 2>&1
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               echo "Failed to change password for user $user"
+               echo "$out"
+               return 1
+       fi
+}
+
+testit "Create user $samba_test_user" \
+       create_local_smb_user $samba_test_user $samba_test_user_pwd \
+       || failed=$(expr $failed + 1)
+
+testit "Change user password" \
+       test_smbpasswd $samba_test_user $samba_test_user_pwd $samba_test_user_new_pwd \
+       || failed=$(expr $failed + 1)
+
+testit "Delete user $samba_test_user" \
+       delete_local_smb_user $samba_test_user \
+       || failed=$(expr $failed + 1)
+
+exit $failed
index a624f85b8f67ed61046fae74581ec0fb39927a4a..7e1f213504400de104e3370e84cc111a8b1be58f 100755 (executable)
@@ -188,6 +188,9 @@ for options in ["--option=clientntlmv2auth=no", "--option=clientusespnego=no --o
 env="ad_dc"
 plantestsuite("samba3.blackbox.smbspool", env, [os.path.join(samba3srcdir, "script/tests/test_smbspool.sh"), '$SERVER', '$SERVER_IP', '$DC_USERNAME', '$DC_PASSWORD', env])
 
+for env in ["ad_member:local", "nt4_dc:local"]:
+    plantestsuite("samba3.blackbox.smbpasswd", env, [os.path.join(samba3srcdir, "script/tests/test_smbpasswd.sh"), '$SERVER', '$SERVER_IP', '$DC_USERNAME', '$DC_PASSWORD'])
+
 env="nt4_dc"
 plantestsuite("samba3.blackbox.smbclient_auth.plain (%s) ipv6" % env, env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_auth.sh"), '$SERVER', '$SERVER_IPV6', '$SERVER/$USERNAME', '$PASSWORD', smbclient3, configuration])