public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] network ftp: some cleanup
@ 2014-07-29 11:42 Zeng Linggang
  2014-07-29 11:42 ` [LTP] [PATCH 2/2] network ssh: " Zeng Linggang
  2014-07-31 11:55 ` [LTP] [PATCH 1/2] network ftp: " Alexey
  0 siblings, 2 replies; 8+ messages in thread
From: Zeng Linggang @ 2014-07-29 11:42 UTC (permalink / raw)
  To: ltp-list

* Move do_setup and do_cleanup into ftp_setup.

* Delete ftp02_s1 and add do_test function for it.

* Delete ftp_set_passwd and ftp_setup_vsftp_conf, since they are not be used.

* Use test.sh instead of net_cmdlib.sh

* Define local exists function instead of which in cmdlib.sh

* Abandon trap and use tst_exit.

* Make the test like:
	(set TCID TST_TOTAL ...)
	setup
	do_test
	check_result
	tst_exit

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/tcp_cmds/ftp/ftp02               | 100 +++++++-----
 testcases/network/tcp_cmds/ftp/ftp02_s1            |  71 ---------
 testcases/network/tcp_cmds/ftp/ftp03               | 177 ++++++++-------------
 testcases/network/tcp_cmds/ftp/ftp04               | 109 ++++++-------
 testcases/network/tcp_cmds/ftp/ftp05               | 149 ++++++++---------
 testcases/network/tcp_cmds/ftp/ftp_set_passwd      |  28 ----
 testcases/network/tcp_cmds/ftp/ftp_setup           |  82 ++++++++++
 .../network/tcp_cmds/ftp/ftp_setup_vsftp_conf      |   5 -
 8 files changed, 320 insertions(+), 401 deletions(-)
 delete mode 100755 testcases/network/tcp_cmds/ftp/ftp02_s1
 delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_set_passwd
 create mode 100644 testcases/network/tcp_cmds/ftp/ftp_setup
 delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf

diff --git a/testcases/network/tcp_cmds/ftp/ftp02 b/testcases/network/tcp_cmds/ftp/ftp02
index 6d6e021..a86319f 100755
--- a/testcases/network/tcp_cmds/ftp/ftp02
+++ b/testcases/network/tcp_cmds/ftp/ftp02
@@ -28,59 +28,73 @@
 #  NOTE:
 #       This version is intended for EAL certification, it will need modification
 #       to conform with LTP standards in the offical LTP tree.
+#
+# DESCRIPTION:
+#	Create Test User
+#	Make sure test user cannont log in with invalid password
+#	Cleanup Test User from system
+#	Exit with exit code of script called upon
+#
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
+	exists expect ftp useradd userdel
+	export TEST_USER="ftpuser2"
+	CONNECTION_FAILED="Connection failed; test FAILED"
+	EXPECTED="Login failed as expected; test PASSED"
+	UNEXPECTED="Login succeeded unexpectedly; test FAILED"
+}
 
-    export RHOST="localhost"
-    export TEST_USER="ftpuser2"
-    export TEST_USER_PASSWD="eal"
-    export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    # erase user if he may exist, so we can have a clean env
-    TCtmp="/home/$TEST_USER"
-
-    tst_setup
+do_test()
+{
+	set PASSWD "invaild_password?!!"
 
-    exists expect ftp ftp02_s1 useradd userdel
+	set timeout 90
 
-    userdel $TEST_USER
-    sleep 1
+	expect -c "
+		#ftp to host
+		spawn ftp $RHOST
+		sleep 1
+		# Check if connection succeeded.
+		expect {
+			\"Name\" {}
+			timeout {send_user \"\n$CONNECTION_FAILED\n\";exit 1}
+		}
 
-    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
+		send \"$RUSER\r\"
+		sleep 1
+		expect -re \"Password:\"
+		send \"$PASSWD\r\"
+		sleep 1
 
-    trap do_cleanup EXIT
+		expect {
+			# 530 - Login failed
+			\"530\" {send_user \"$EXPECTED\n\";exit 0}
+			# 230 - Login successful
+			\"230\" {send_user \"$UNEXPECTED\n\"; exit 1}
+		}
 
+		expect \"ftp>\"
+		send \"exit\r\"
+	"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel $TEST_USER
-    tst_cleanup
-}
-
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#              Call upon script to make sure test user cannont log in with invalid password
-#	       Cleanup Test User from system
-#              Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
+. test.sh
+. ftp_setup
 
-read_opts $*
+setup
 do_setup
-ftp02_s1 || end_testcase "Testcase failed."
-end_testcase
+TST_CLEANUP=do_cleanup
+
+do_test
+ret=$?
+if [ $ret -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp02_s1 b/testcases/network/tcp_cmds/ftp/ftp02_s1
deleted file mode 100755
index 18b08da..0000000
--- a/testcases/network/tcp_cmds/ftp/ftp02_s1
+++ /dev/null
@@ -1,71 +0,0 @@
-#! /usr/bin/expect -f
-#*********************************************************************
-#   Copyright (c) International Business Machines  Corp., 2003, 2005
-#
-#   This program is free software;  you can redistribute it and/or modify
-#   it under the terms of the GNU General Public License as published by
-#   the Free Software Foundation; either version 2 of the License, or
-#   (at your option) any later version.
-#
-#   This program is distributed in the hope that it will be useful,
-#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#   the GNU General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public License
-#   along with this program;  if not, write to the Free Software
-#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-#
-#
-#  FILE   : ftp
-#
-#  PURPOSE: Test to see if ftp rejects a user with an invalid password
-#
-#  SETUP: The program `/usr/bin/expect' MUST be installed.
-#
-#  HISTORY:
-# 	03/04/03 Jerone Young (jeroney@us.ibm.com)
-#       09/21/05 Kris Wilson (krisw@us.ibm.com) Check for connection failure.
-#                (If WS system, no vsftpd; connection will fail.)
-
-set RHOST $env(RHOST)
-set TEST_USER $env(TEST_USER)
-set TEST_USER_PASSWD $env(TEST_USER_PASSWD)
-set TEST_USER_HOMEDIR $env(TEST_USER_HOMEDIR)
-
-#RUSER
-set RUSER $TEST_USER
-
-#set PASSWD to be an invalid Password
-set PASSWD "invaild_password?!!"
-
-set timeout 90
-
-#ftp to host
-spawn ftp $RHOST
-sleep 1
-# Check if connection succeeded.
-expect {
-    "Name" {}
-    timeout {send_user "\nConnection failed; test FAILED\n";exit 1}
-}
-
-send "$RUSER\r"
-sleep 1
-expect -re "Password:"
-send "$PASSWD\r"
-sleep 1
-
-expect {
-    # 530 - Login failed
-    "530" {send_user "Login failed as expected; test PASSED\n"}
-    # 230 - Login successful
-    "230" {send_user "Login succeeded unexpectedly; test FAILED\n"; exit 1}
-}
-
-expect "ftp>"
-send "exit\r"
-
-send_user "\nTest Successful\n\n"
-exit 0
diff --git a/testcases/network/tcp_cmds/ftp/ftp03 b/testcases/network/tcp_cmds/ftp/ftp03
index a99a1a0..13e5273 100755
--- a/testcases/network/tcp_cmds/ftp/ftp03
+++ b/testcases/network/tcp_cmds/ftp/ftp03
@@ -31,130 +31,77 @@
 #	This version is intended for EAL certification, it will need modification
 #	to conform with LTP standards in the offical LTP tree.
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-
-    RHOST="localhost"
-    TEST_USER="ftpuser1"
-    TCtmp=/home/$TEST_USER
-    TEST_USER_PASSWD="eal"
-    TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
-    TEST_USER_HOMEDIR="/home/$TEST_USER"
-    VSFTP_CONF=
-
-    tst_setup
-
-    exists ftp useradd userdel vftpd
-
-    for vsftp_conf in /etc/vsftpd /etc; do
-
-        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
-            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
-            break
-        fi
-
-    done
-    if [ ! -r "$VSFTP_CONF" ] ; then
-        end_testcase "vsftpd.conf not found."
-    fi
-    LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
-
-    [ "$LOCAL_ENABLE" != "YES" ] && LOCAL_ENABLE="NO"
-
-    userdel $TEST_USER
-    sleep 1
-
-    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER on system $RHOST."
-    fi
-
-    trap do_cleanup QUIT
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    USER_UID=$(id -u $TEST_USER)
-    USER_GID=$(id -g $TEST_USER)
-    mkdir -p "$TEST_USER_HOMEDIR"
-    chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
-
+	exists ftp useradd userdel vsftpd
+	export TEST_USER="ftpuser3"
+	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
+	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
+	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
+	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
+	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
-
-do_cleanup()
+do_test()
 {
-    userdel $TEST_USER
-    tst_cleanup
-}
-
-#-----------------------------------------------------------------------
-# FUNCTION:  do_test
-#
-# DESCRIPTION: The test user will ftp in and create a directory in his home directory on the remote host.
-#              The directory is then checked on the remote hosts to see if it is owned
-#	       by the test user.
-#-----------------------------------------------------------------------
-
-do_test(){
-    tst_resm TINFO "TEST: Ftp into a remote host as a local user (other than root), LOCAL_ENABLE=$LOCAL_ENABLE"
+	echo "TEST: Ftp into a remote host as a local user (other than root),"
+	echo "LOCAL_ENABLE=$LOCAL_ENABLE"
 
-    if [ "$LOCAL_ENABLE" = "YES" ]; then
+	if [ "$LOCAL_ENABLE" = "YES" ]; then
 	expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 530 - Login failed
+			\"530\" {send_user \"$FAIL_530\n\";exit 1}
+			# 230 - Login successful
+			\"230\" {send_user \"$PASS_230\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
 	"
-    else
-        expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
-                # 500 - Login failed
-                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
-        "
-    fi
-
-    if [ $? != 0 ]; then
-        end_testcase "Testcase failed"
-    fi
+	else
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 230 - Login successful
+			\"230\" {send_user \"$FAIL_230\n\";exit 1}
+			# 500 - Login failed
+			\"500\" {send_user \"$PASS_500\n\";exit 0}
+			# 530 - Login failed
+			\"530\" {send_user \"$PASS_530\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
+	"
+	fi
 }
 
-#----------------------------------------------------------------------
-# FUNCTION: MAIN
-# PURPOSE:  To invoke the functions to perform the tasks described in
-#           the prologue.
-#----------------------------------------------------------------------
-. net_cmdlib.sh
+TCID="$0"
+TST_TOTAL=1
 
-read_opts $*
+. test.sh
+. ftp_setup
+
+setup
 do_setup
+TST_CLEANUP=do_cleanup
+
 do_test
-end_testcase
+ret=$?
+if [ $ret -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp04 b/testcases/network/tcp_cmds/ftp/ftp04
index 8329eb0..c13614d 100755
--- a/testcases/network/tcp_cmds/ftp/ftp04
+++ b/testcases/network/tcp_cmds/ftp/ftp04
@@ -28,77 +28,66 @@
 #   03/04/03 Jerone Young (jeroney@us.ibm.com)
 #   09/21/05 Kris Wilson (krisw@us.ibm.com) Check if vsftpd is on system.
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
+	exists awk expect ftp vsftpd
 
-    tvar=${MACHTYPE%-*}
-    tvar=${tvar#*-}
-
-    RHOST=localhost
-    TEST_USER=root
-
-    tst_setup
+	TEST_USER=root
 
-    if [ -n "$PASSWD" ]; then
-        TEST_USER_PASSWORD=$PASSWD
-    else
-        end_testcase "You must set your password via the PASSWD variable."
-        exit 1
-    fi
+	tvar=${MACHTYPE%-*}
+	tvar=${tvar#*-}
 
-    exists awk expect ftp vsftpd
-
-    if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
-        echo "Verifying test user $TEST_USER is in /etc/vsftpd.ftpusers database..."
-        FTPUSERS=$(awk "/$TEST_USER/" /etc/vsftpd.ftpusers)
-    else
-        echo "Verifying test user $TEST_USER is in /etc/ftpusers database..."
-        FTPUSERS=$(awk "/$TEST_USER/" /etc/ftpusers)
-    fi
-    if [ -z "$FTPUSERS" ] ; then
-        end_testcase "Test user $TEST_USER not found in /etc/ftpusers unable to run TEST, exiting 0 ..."
-    fi
+	if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
+		ftpusers="/etc/vsftpd/ftpusers"
+	else
+		ftpusers="/etc/ftpusers"
+	fi
+	echo "Verifying test user $TEST_USER is in ${ftpusers} database..."
+	FTPUSERS=$(awk "/$TEST_USER/" ${ftpusers})
+	if [ -z "$FTPUSERS" ] ; then
+		tst_brkm TBROK "$TEST_USER not found in $ftpusers exiting 0 ..."
+	fi
 
+	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
+	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_test
-#-----------------------------------------------------------------------
 do_test()
 {
-
-    tst_resm TINFO "Ftp should reject $TEST_USER from loging in successfully"
-    expect -c "
-        spawn ftp $RHOST
-        sleep 1
-        expect -re \": \"
-        send \"$TEST_USER\r\"
-        expect -re \"Password:\"
-        send \"$TEST_USER_PASSWD\r\"
-        expect {
-            # 230 - Login successful
-            \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
-            # 530 - Login failed
-            \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-        }
-        expect \"ftp> \"
-        send \"quit\r\"
-    "
-
-    [ $? -eq 0 ] || end_testcase "Testcase failed."
-
+	echo "Ftp should reject $TEST_USER from loging in successfully"
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 230 - Login successful
+			\"230\" {send_user \"$FAIL_230\n\";exit 1}
+			# 530 - Login failed
+			\"530\" {send_user \"$PASS_530\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
+	"
 }
 
-#----------------------------------------------------------------------
-# FUNCTION: MAIN
-#----------------------------------------------------------------------
-. net_cmdlib.sh
+TCID="$0"
+TST_TOTAL=1
+
+. test.sh
+. ftp_setup
 
-read_opts $*
+setup
 do_setup
+
 do_test
-end_testcase
+ret=$?
+if [ $ret -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp05 b/testcases/network/tcp_cmds/ftp/ftp05
index 4f91334..746c87a 100755
--- a/testcases/network/tcp_cmds/ftp/ftp05
+++ b/testcases/network/tcp_cmds/ftp/ftp05
@@ -30,96 +30,87 @@
 #  NOTE:
 #	This version is intended for EAL certification, it will need modification
 #	to conform with LTP standards in the offical LTP tree.
+#
+# DESCRIPTION:
+#	The anonymous user will ftp in and create a directory in his/her
+#	home directory on the remote host.
+#
 
-do_setup()
+setup()
 {
-    RHOST="localhost"
-    TEST_USER="anonymous"
-    TEST_USER_PASSWD="noone@nowhere.com"
-    VSFTP_CONF=
-
-    tst_setup
-
-    exists expect ftp vsftpd
-
-    for vsftp_conf in /etc/vsftpd /etc; do
-
-        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
-            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
-            break
-        fi
-
-    done
-    if [ ! -r "$VSFTP_CONF" ] ; then
-        end_testcase "vsftpd.conf not found."
-    fi
-    ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
-    if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
-        ANONYMOUS_ENABLE="YES"
-    fi
+	exists expect ftp vsftpd
+	TEST_USER="anonymous"
+	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
+	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
+	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
+	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
+	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION   : do_test
-#
-# DESCRIPTION: The anonymous user will ftp in and create a directory in his/her
-#              home directory on the remote host.
-#-----------------------------------------------------------------------
-
 do_test()
 {
-    tst_resm TINFO "Ftp into a remote host as anonymous user; ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
+	echo "Ftp into a remote host as anonymous user;"
+	echo "ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
 
-    if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
-        expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
+	if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 530 - Login failed
+			\"530\" {send_user \"$FAIL_530\n\";exit 1}
+			# 230 - Login successful
+			\"230\" {send_user \"$PASS_230\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
 	"
-    else
-        expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
-                # 500 - Login failed
-                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
-        "
-    fi
-
-    [ $? -eq 0 ] || end_testcase "Testcase failed."
+	else
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 230 - Login successful
+			\"230\" {send_user \"$FAIL_230\n\";exit 1}
+			# 500 - Login failed
+			\"500\" {send_user \"$PASS_500\n\";exit 0}
+			# 530 - Login failed
+			\"530\" {send_user \"$PASS_530\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
+	"
+	fi
 
+	if [ $? -ne 0 ]; then
+		 tst_exit TBROK "Testcase failed."
+	fi
 }
 
-#----------------------------------------------------------------------
-# FUNCTION: MAIN
-# PURPOSE:  To invoke the functions to perform the tasks described in
-#           the prologue.
-#----------------------------------------------------------------------
-. net_cmdlib.sh
+TCID="$0"
+TST_TOTAL=1
 
-read_opts $*
+. test.sh
+. ftp_setup
+
+setup
 do_setup
+#TEST_USER_PASSWD="noone@nowhere.com"
+
 do_test
-end_testcase
+ret=$?
+if [ $ret -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp_set_passwd b/testcases/network/tcp_cmds/ftp/ftp_set_passwd
deleted file mode 100755
index 7c275c9..0000000
--- a/testcases/network/tcp_cmds/ftp/ftp_set_passwd
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/expect
-#
-# Set Password for a specific new user
-# This script should be run as 'root'
-#
-# Example:
-#		./set_passwd USER PASSWD
-#
-
-if { [llength $argv] < 2} {
-    exit 1
-}
-
-set USER [lindex $argv 0]
-set PASSWD [lindex $argv 1]
-
-set timeout 30
-
-spawn passwd $USER
-expect "Enter new password: "
-sleep 1
-exp_send "$PASSWD\r"
-expect "Re-type new password: "
-sleep 1
-exp_send "$PASSWD\r"
-expect success
-
-exit 0
diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup b/testcases/network/tcp_cmds/ftp/ftp_setup
new file mode 100644
index 0000000..7100736
--- /dev/null
+++ b/testcases/network/tcp_cmds/ftp/ftp_setup
@@ -0,0 +1,82 @@
+#!/bin/sh
+###############################################################################
+## Copyright (c) International Business Machines  Corp., 2003                ##
+##                                                                           ##
+## This program is free software;  you can redistribute it and/or modify     ##
+## it under the terms of the GNU General Public License as published by      ##
+## the Free Software Foundation; either version 2 of the License, or         ##
+## (at your option) any later version.                                       ##
+##                                                                           ##
+## This program is distributed in the hope that it will be useful,           ##
+## but WITHOUT ANY WARRANTY;  without even the implied warranty of           ##
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                 ##
+## the GNU General Public License for more details.                          ##
+##                                                                           ##
+## You should have received a copy of the GNU General Public License         ##
+## along with this program;  if not, write to the Free Software Foundation,  ##
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          ##
+##                                                                           ##
+###############################################################################
+
+exists()
+{
+	for cmd in $*; do
+		if ! command -v $cmd > /dev/null 2>&1; then
+			tst_brkm TBROK "$cmd: command not found"
+		fi
+	done
+}
+
+do_setup()
+{
+
+	export RHOST="localhost"
+	export TEST_USER_PASSWD="eal"
+	export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
+	export TEST_USER_HOMEDIR="/home/$TEST_USER"
+
+	for vsftp_confdir in /etc/vsftpd /etc; do
+		if [ -r "$vsftp_confdir/vsftpd.conf" ]; then
+			VSFTP_CONF="$vsftp_confdir/vsftpd.conf"
+			break
+		fi
+	done
+	if [ ! -r "$VSFTP_CONF" ] ; then
+		tst_brkm TBROK "vsftpd.conf not found."
+	fi
+
+	LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
+	if [ "$LOCAL_ENABLE" != "YES" ]; then
+		LOCAL_ENABLE="NO"
+	fi
+
+	ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
+	if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
+		ANONYMOUS_ENABLE="YES"
+	fi
+
+	if [ $TEST_USER = "root" -o $TEST_USER = "anonymous" ]; then
+		return
+	fi
+
+	userdel -r $TEST_USER
+	sleep 1
+
+	if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
+		tst_brkm TBROK "Could not add test user $TEST_USER to system $RHOST."
+	fi
+
+	# create users home diretory (SLES 8 does not do this, even when specified
+	# in adduser)
+	USER_UID=$(id -u $TEST_USER)
+	USER_GID=$(id -g $TEST_USER)
+	mkdir -p "$TEST_USER_HOMEDIR"
+	chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
+}
+
+do_cleanup()
+{
+	if [ $TEST_USER != "root" -a $TEST_USER != "anonymous" ]; then
+		userdel -r $TEST_USER
+	fi
+}
diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf b/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
deleted file mode 100755
index 7e496f6..0000000
--- a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-grep -v "local_enable" /etc/vsftpd.conf > /tmp/vsftpd.conf
-mv -f /tmp/vsftpd.conf /etc/vsftpd.conf
-echo "local_enable=YES" >> /etc/vsftpd.conf
-- 
1.9.3




------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 2/2] network ssh: some cleanup
  2014-07-29 11:42 [LTP] [PATCH 1/2] network ftp: some cleanup Zeng Linggang
@ 2014-07-29 11:42 ` Zeng Linggang
  2014-07-31 11:55 ` [LTP] [PATCH 1/2] network ftp: " Alexey
  1 sibling, 0 replies; 8+ messages in thread
From: Zeng Linggang @ 2014-07-29 11:42 UTC (permalink / raw)
  To: ltp-list

* Move do_setup and do_cleanup into the file of ssh_setup.

* Use test.sh instead of net_cmdlib.sh

* Define local exists function instead of which in cmdlib.sh

* Abandon trap and use tst_exit.

* Make the test like:
	(set TCID TST_TOTAL ...)
	setup
	do_test
	check_result
	tst_exit

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/tcp_cmds/ssh/ssh01     | 83 +++++++++-----------------------
 testcases/network/tcp_cmds/ssh/ssh01_s1  | 36 ++++++++------
 testcases/network/tcp_cmds/ssh/ssh02     | 83 +++++++++-----------------------
 testcases/network/tcp_cmds/ssh/ssh02_s1  | 36 ++++++++------
 testcases/network/tcp_cmds/ssh/ssh03     | 78 ++++++++----------------------
 testcases/network/tcp_cmds/ssh/ssh03_s1  | 36 ++++++++------
 testcases/network/tcp_cmds/ssh/ssh_setup | 63 ++++++++++++++++++++++++
 7 files changed, 192 insertions(+), 223 deletions(-)
 create mode 100755 testcases/network/tcp_cmds/ssh/ssh_setup

diff --git a/testcases/network/tcp_cmds/ssh/ssh01 b/testcases/network/tcp_cmds/ssh/ssh01
index a0c66f5..06a830a 100755
--- a/testcases/network/tcp_cmds/ssh/ssh01
+++ b/testcases/network/tcp_cmds/ssh/ssh01
@@ -25,69 +25,34 @@
 #  HISTORY:
 #    03/03 Jerone Young (jeroney@us.ibm.com)
 #
+# DESCRIPTION:
+#	Create test user
+#	Make sure test user can't login with invalid password
+#	Cleanup test user from system
+#	Exit with exit code of script called upon
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-    export RHOST="localhost"
-    export TEST_USER="ssh_usr1"
-    export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    exists expect ssh ssh01_s1 useradd userdel
-
-    trap do_cleanup EXIT
-
-    # erase user if he/she already exists, so we can have a clean env
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    sleep 1
-
-    tst_setup
-
-    if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
-
-    echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    if [ ! -d "$TEST_USER_HOMEDIR" ]; then
-        USER_UID=$(id -u $TEST_USER)
-        USER_GID=$(id -g $TEST_USER)
-        if ! mkdir -p "$TEST_USER_HOMEDIR"; then
-            end_testcase "Failed to create $TEST_USER_HOMEDIR"
-        fi
-        chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
-    fi
+	exists ssh01_s1
+	export TEST_USER="ssh_usr1"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    tst_cleanup
-}
+. test.sh
+. ssh_setup
 
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#          Call upon script to make sure test user cannont log in with invalid password
-#          Cleanup Test User from system
-#          Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
+setup
 do_setup
-ssh01_s1 || end_testcase "Testcase failed"
-do_cleanup
+TST_CLEANUP=do_cleanup
+
+ssh01_s1
+ret=$?
+if [ $ret -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ssh/ssh01_s1 b/testcases/network/tcp_cmds/ssh/ssh01_s1
index c1cc127..ab86e2a 100755
--- a/testcases/network/tcp_cmds/ssh/ssh01_s1
+++ b/testcases/network/tcp_cmds/ssh/ssh01_s1
@@ -45,22 +45,28 @@ set PASSWD "invalid_password!"
 spawn ssh -l $RUSER $RHOST whoami
 
 while 1 {
-    sleep 2
-    expect {
+	sleep 2
+	expect {
 
-        "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\r"}
-        "assword:" {exp_send "$PASSWD\r"}
-        -re "Permission denied (.*)\." {
-            send_user "SSH would not allow $RUSER to login with invalid password, Test Passed \n"
-            send_user "\nTEST_PASSED\n"
-            exit 0
-        }
-        "$RUSER" {
-            send_user "SSH allowed $RUSER to login with invalid pass, Test Failed \n"
-            exit 1
-        }
-    }
-    sleep 1
+		"Are you sure you want to continue connecting (yes/no)?" {
+			exp_send "yes\r"
+		}
+		"assword:" {
+			exp_send "$PASSWD\r"
+		}
+		-re "Permission denied (.*)\." {
+			send_user "SSH would not allow $RUSER to login with\
+				   invalid password, Test Passed \n"
+			send_user "\nTEST_PASSED\n"
+			exit 0
+		}
+		"$RUSER" {
+			send_user "SSH allowed $RUSER to login with invalid\
+				   pass, Test Failed \n"
+			exit 1
+		}
+	}
+	sleep 1
 }
 
 exit 1
diff --git a/testcases/network/tcp_cmds/ssh/ssh02 b/testcases/network/tcp_cmds/ssh/ssh02
index 2d82acb..edf7434 100755
--- a/testcases/network/tcp_cmds/ssh/ssh02
+++ b/testcases/network/tcp_cmds/ssh/ssh02
@@ -25,69 +25,34 @@
 #  HISTORY:
 #    03/03 Jerone Young (jeroney@us.ibm.com)
 #
+# DESCRIPTION:
+#	Create Test User
+#	Make sure an invalid user can not have access
+#	Cleanup Test User from system
+#	Exit with exit code of script called upon
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-    export RHOST="localhost"
-    export TEST_USER="ssh_usr2"
-    export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    exists expect ssh ssh02_s1 useradd userdel
-
-    trap do_cleanup EXIT
-
-    # erase user if he/she already exists, so we can have a clean env
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    sleep 1
-
-    tst_setup
-
-    if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
-
-    echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    if [ ! -d "$TEST_USER_HOMEDIR" ]; then
-        USER_UID=$(id -u $TEST_USER)
-        USER_GID=$(id -g $TEST_USER)
-        if ! mkdir -p "$TEST_USER_HOMEDIR"; then
-            end_testcase "Failed to create $TEST_USER_HOMEDIR"
-        fi
-        chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
-    fi
+	exists ssh02_s1
+	export TEST_USER="ssh_usr2"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    tst_cleanup
-}
+. test.sh
+. ssh_setup
 
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#          Call upon script to make sure an invalid user can not have access
-#          Cleanup Test User from system
-#          Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
+setup
 do_setup
-ssh02_s1 || end_testcase "Testcase failed"
-do_cleanup
+TST_CLEANUP=do_cleanup
+
+ssh02_s1
+ret=$?
+if [ $ret -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ssh/ssh02_s1 b/testcases/network/tcp_cmds/ssh/ssh02_s1
index d49e1e9..cf95709 100755
--- a/testcases/network/tcp_cmds/ssh/ssh02_s1
+++ b/testcases/network/tcp_cmds/ssh/ssh02_s1
@@ -46,22 +46,28 @@ set RUSER "Invaild_User"
 spawn ssh -l $RUSER $RHOST whoami
 
 while 1 {
-    sleep 2
-    expect {
+	sleep 2
+	expect {
 
-        "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\r"}
-        "assword:" {exp_send "$PASSWD\r"}
-        -re "Permission denied (.*)\." {
-            send_user "SSH would not allow $RUSER to login with invalid password, Test Passed \n"
-            send_user "\nTEST_PASSED\n"
-            exit 0
-        }
-        "$RUSER" {
-            send_user "SSH allowed $RUSER to login with invalid pass, Test Failed \n"
-            exit 1
-        }
-    }
-    sleep 1
+		"Are you sure you want to continue connecting (yes/no)?" {
+			exp_send "yes\r"
+		}
+		"assword:" {
+			exp_send "$PASSWD\r"
+		}
+		-re "Permission denied (.*)\." {
+			send_user "SSH would not allow $RUSER to login with\
+				   invalid password, Test Passed \n"
+			send_user "\nTEST_PASSED\n"
+			exit 0
+		}
+		"$RUSER" {
+			send_user "SSH allowed $RUSER to login with invalid\
+				   pass, Test Failed \n"
+			exit 1
+		}
+	}
+	sleep 1
 }
 
 exit 1
diff --git a/testcases/network/tcp_cmds/ssh/ssh03 b/testcases/network/tcp_cmds/ssh/ssh03
index 49b6527..b50c9aa 100755
--- a/testcases/network/tcp_cmds/ssh/ssh03
+++ b/testcases/network/tcp_cmds/ssh/ssh03
@@ -26,68 +26,28 @@
 #    03/03 Jerone Young (jeroney@us.ibm.com)
 #
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-    export RHOST="localhost"
-    export TEST_USER="ssh_usr3"
-    export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    exists expect ssh ssh03_s1 useradd userdel
-
-    trap do_cleanup EXIT
-
-    # erase user if he/she already exists, so we can have a clean env
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    sleep 1
-
-    tst_setup
-
-    if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
-
-    echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    if [ ! -d "$TEST_USER_HOMEDIR" ]; then
-        USER_UID=$(id -u $TEST_USER)
-        USER_GID=$(id -g $TEST_USER)
-        if ! mkdir -p "$TEST_USER_HOMEDIR"; then
-            end_testcase "Failed to create $TEST_USER_HOMEDIR"
-        fi
-        chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
-    fi
+	exists ssh03_s1
+	export TEST_USER="ssh_usr3"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    tst_cleanup
-}
+. test.sh
+. ssh_setup
 
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#          Call upon script to make sure a valid user can have access
-#          Cleanup Test User from system
-#          Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
+setup
 do_setup
-ssh03_s1 || end_testcase "Testcase failed"
-do_cleanup
+TST_CLEANUP=do_cleanup
+
+ssh03_s1
+ret=$?
+if [ $ret -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ssh/ssh03_s1 b/testcases/network/tcp_cmds/ssh/ssh03_s1
index bf6aada..e3f8ceb 100755
--- a/testcases/network/tcp_cmds/ssh/ssh03_s1
+++ b/testcases/network/tcp_cmds/ssh/ssh03_s1
@@ -39,25 +39,29 @@ set timeout 90
 
 send_user "TEST: SSH allow (non-root) valid User \n"
 
-
 spawn ssh -l $RUSER $RHOST whoami
 
 while 1 {
-    sleep 2
-    expect {
-
-        "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\r"}
-        "assword:" {exp_send "$PASSWD\r"}
-        -re "Permission denied (.*)\." {
-            send_user "\nSSH would not allow $RUSER to login, Test FAILED \n"
-            exit 1
-        }
-        "$RUSER" {
-            send_user "SSH allowed $RUSER to login, Test PASSED \n"
-            exit 0
-        }
-    }
-    sleep 1
+	sleep 2
+	expect {
+
+		"Are you sure you want to continue connecting (yes/no)?" {
+			exp_send "yes\r"
+		}
+		"assword:" {
+			exp_send "$PASSWD\r"
+		}
+		-re "Permission denied (.*)\." {
+			send_user "\nSSH would not allow $RUSER to login, Test\
+				   FAILED \n"
+			exit 1
+		}
+		"$RUSER" {
+			send_user "SSH allowed $RUSER to login, Test PASSED \n"
+			exit 0
+		}
+	}
+	sleep 1
 }
 
 exit 1
diff --git a/testcases/network/tcp_cmds/ssh/ssh_setup b/testcases/network/tcp_cmds/ssh/ssh_setup
new file mode 100755
index 0000000..f0d6f7c
--- /dev/null
+++ b/testcases/network/tcp_cmds/ssh/ssh_setup
@@ -0,0 +1,63 @@
+#!/bin/sh
+################################################################################
+## Copyright (c) International Business Machines  Corp., 2000                 ##
+##                                                                            ##
+## This program is free software;  you can redistribute it and/or modify      ##
+## it under the terms of the GNU General Public License as published by       ##
+## the Free Software Foundation; either version 2 of the License, or          ##
+## (at your option) any later version.                                        ##
+##                                                                            ##
+## This program is distributed in the hope that it will be useful,            ##
+## but WITHOUT ANY WARRANTY;  without even the implied warranty of            ##
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  ##
+## the GNU General Public License for more details.                           ##
+##                                                                            ##
+## You should have received a copy of the GNU General Public License          ##
+## along with this program;  if not, write to the Free Software Foundation,   ##
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
+##                                                                            ##
+################################################################################
+
+exists()
+{
+	for cmd in $*; do
+		if ! command -v $cmd > /dev/null 2>&1; then
+			tst_brkm TBROK "$cmd: command not found"
+		fi
+	done
+}
+
+do_setup()
+{
+	export RHOST="localhost"
+	export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
+	export TEST_USER_HOMEDIR="/home/$TEST_USER"
+
+	exists expect ssh useradd userdel
+
+	# erase user if he/she already exists, so we can have a clean env
+	do_cleanup
+	sleep 1
+
+	if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
+		tst_brkm TBROK "Failed to add user $TEST_USER to system $RHOST."
+	fi
+
+	echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
+
+	# create users home diretory (SLES 8 does not do this, even when
+	# specified in adduser)
+	if [ ! -d "$TEST_USER_HOMEDIR" ]; then
+		USER_UID=$(id -u $TEST_USER)
+		USER_GID=$(id -g $TEST_USER)
+		if ! mkdir -p "$TEST_USER_HOMEDIR"; then
+			tst_brkm TBROK "Failed to create $TEST_USER_HOMEDIR"
+		fi
+		chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
+	fi
+}
+
+do_cleanup()
+{
+	userdel -r $TEST_USER 2> /dev/null
+}
-- 
1.9.3




------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH 1/2] network ftp: some cleanup
  2014-07-29 11:42 [LTP] [PATCH 1/2] network ftp: some cleanup Zeng Linggang
  2014-07-29 11:42 ` [LTP] [PATCH 2/2] network ssh: " Zeng Linggang
@ 2014-07-31 11:55 ` Alexey
  2014-08-01  1:25   ` Zeng Linggang
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Alexey @ 2014-07-31 11:55 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi Zeng!
On 07/29/2014 03:42 PM, Zeng Linggang wrote:
> * Move do_setup and do_cleanup into ftp_setup.
>
> * Delete ftp02_s1 and add do_test function for it.
>
> * Delete ftp_set_passwd and ftp_setup_vsftp_conf, since they are not be used.
>
> * Use test.sh instead of net_cmdlib.sh
>
> * Define local exists function instead of which in cmdlib.sh
>
> * Abandon trap and use tst_exit.
>
> * Make the test like:
> 	(set TCID TST_TOTAL ...)
> 	setup
> 	do_test
> 	check_result
> 	tst_exit
>
> * Some cleanup.
>
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> ---
>   testcases/network/tcp_cmds/ftp/ftp02               | 100 +++++++-----
>   testcases/network/tcp_cmds/ftp/ftp02_s1            |  71 ---------
>   testcases/network/tcp_cmds/ftp/ftp03               | 177 ++++++++-------------
>   testcases/network/tcp_cmds/ftp/ftp04               | 109 ++++++-------
>   testcases/network/tcp_cmds/ftp/ftp05               | 149 ++++++++---------
>   testcases/network/tcp_cmds/ftp/ftp_set_passwd      |  28 ----
>   testcases/network/tcp_cmds/ftp/ftp_setup           |  82 ++++++++++
>   .../network/tcp_cmds/ftp/ftp_setup_vsftp_conf      |   5 -
>   8 files changed, 320 insertions(+), 401 deletions(-)
>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp02_s1
>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_set_passwd
>   create mode 100644 testcases/network/tcp_cmds/ftp/ftp_setup
>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
>
> diff --git a/testcases/network/tcp_cmds/ftp/ftp02 b/testcases/network/tcp_cmds/ftp/ftp02
> index 6d6e021..a86319f 100755
> --- a/testcases/network/tcp_cmds/ftp/ftp02
> +++ b/testcases/network/tcp_cmds/ftp/ftp02
> @@ -28,59 +28,73 @@
>   #  NOTE:
>   #       This version is intended for EAL certification, it will need modification
>   #       to conform with LTP standards in the offical LTP tree.
> +#
> +# DESCRIPTION:
> +#	Create Test User
> +#	Make sure test user cannont log in with invalid password
> +#	Cleanup Test User from system
> +#	Exit with exit code of script called upon
> +#
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_setup
> -#-----------------------------------------------------------------------
> -
> -do_setup()
> +setup()
>   {
> +	exists expect ftp useradd userdel
We don't need "exists()" anymore, use tst_check_cmd() from test.sh instead.

> +	export TEST_USER="ftpuser2"
> +	CONNECTION_FAILED="Connection failed; test FAILED"
> +	EXPECTED="Login failed as expected; test PASSED"
> +	UNEXPECTED="Login succeeded unexpectedly; test FAILED"
> +}
>   
> -    export RHOST="localhost"
> -    export TEST_USER="ftpuser2"
> -    export TEST_USER_PASSWD="eal"
> -    export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
> -    export TEST_USER_HOMEDIR="/home/$TEST_USER"
> -
> -    # erase user if he may exist, so we can have a clean env
> -    TCtmp="/home/$TEST_USER"
> -
> -    tst_setup
> +do_test()
> +{
> +	set PASSWD "invaild_password?!!"
>   
> -    exists expect ftp ftp02_s1 useradd userdel
> +	set timeout 90
>   
> -    userdel $TEST_USER
> -    sleep 1
> +	expect -c "
> +		#ftp to host
> +		spawn ftp $RHOST
> +		sleep 1
> +		# Check if connection succeeded.
> +		expect {
> +			\"Name\" {}
> +			timeout {send_user \"\n$CONNECTION_FAILED\n\";exit 1}
> +		}
>   
> -    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
> -        end_testcase "Could not add test user $TEST_USER to system $RHOST."
> -    fi
> +		send \"$RUSER\r\"
> +		sleep 1
> +		expect -re \"Password:\"
> +		send \"$PASSWD\r\"
> +		sleep 1
>   
> -    trap do_cleanup EXIT
> +		expect {
> +			# 530 - Login failed
> +			\"530\" {send_user \"$EXPECTED\n\";exit 0}
> +			# 230 - Login successful
> +			\"230\" {send_user \"$UNEXPECTED\n\"; exit 1}
> +		}
>   
> +		expect \"ftp>\"
> +		send \"exit\r\"
> +	"
>   }
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_cleanup
> -#-----------------------------------------------------------------------
> +TCID="$0"
> +TST_TOTAL=1
>   
> -do_cleanup()
> -{
> -    userdel $TEST_USER
> -    tst_cleanup
> -}
> -
> -#-----------------------------------------------------------------------
> -# FUNCTION:  MAIN
> -#
> -# DESCRIPTION: Create Test User
> -#              Call upon script to make sure test user cannont log in with invalid password
> -#	       Cleanup Test User from system
> -#              Exit with exit code of script called upon
> -#-----------------------------------------------------------------------
> -. net_cmdlib.sh
> +. test.sh
> +. ftp_setup
>   
> -read_opts $*
> +setup
>   do_setup
> -ftp02_s1 || end_testcase "Testcase failed."
> -end_testcase
> +TST_CLEANUP=do_cleanup
> +
> +do_test
> +ret=$?
> +if [ $ret -ne 0 ]; then
> +	tst_resm TFAIL "Test $TCID FAIL"
> +else
> +	tst_resm TPASS "Test $TCID PASS"
> +fi
> +
> +tst_exit
> diff --git a/testcases/network/tcp_cmds/ftp/ftp02_s1 b/testcases/network/tcp_cmds/ftp/ftp02_s1
> deleted file mode 100755
> index 18b08da..0000000
> --- a/testcases/network/tcp_cmds/ftp/ftp02_s1
> +++ /dev/null
> @@ -1,71 +0,0 @@
> -#! /usr/bin/expect -f
> -#*********************************************************************
> -#   Copyright (c) International Business Machines  Corp., 2003, 2005
> -#
> -#   This program is free software;  you can redistribute it and/or modify
> -#   it under the terms of the GNU General Public License as published by
> -#   the Free Software Foundation; either version 2 of the License, or
> -#   (at your option) any later version.
> -#
> -#   This program is distributed in the hope that it will be useful,
> -#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
> -#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> -#   the GNU General Public License for more details.
> -#
> -#   You should have received a copy of the GNU General Public License
> -#   along with this program;  if not, write to the Free Software
> -#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> -#
> -#
> -#
> -#  FILE   : ftp
> -#
> -#  PURPOSE: Test to see if ftp rejects a user with an invalid password
> -#
> -#  SETUP: The program `/usr/bin/expect' MUST be installed.
> -#
> -#  HISTORY:
> -# 	03/04/03 Jerone Young (jeroney@us.ibm.com)
> -#       09/21/05 Kris Wilson (krisw@us.ibm.com) Check for connection failure.
> -#                (If WS system, no vsftpd; connection will fail.)
> -
> -set RHOST $env(RHOST)
> -set TEST_USER $env(TEST_USER)
> -set TEST_USER_PASSWD $env(TEST_USER_PASSWD)
> -set TEST_USER_HOMEDIR $env(TEST_USER_HOMEDIR)
> -
> -#RUSER
> -set RUSER $TEST_USER
> -
> -#set PASSWD to be an invalid Password
> -set PASSWD "invaild_password?!!"
> -
> -set timeout 90
> -
> -#ftp to host
> -spawn ftp $RHOST
> -sleep 1
> -# Check if connection succeeded.
> -expect {
> -    "Name" {}
> -    timeout {send_user "\nConnection failed; test FAILED\n";exit 1}
> -}
> -
> -send "$RUSER\r"
> -sleep 1
> -expect -re "Password:"
> -send "$PASSWD\r"
> -sleep 1
> -
> -expect {
> -    # 530 - Login failed
> -    "530" {send_user "Login failed as expected; test PASSED\n"}
> -    # 230 - Login successful
> -    "230" {send_user "Login succeeded unexpectedly; test FAILED\n"; exit 1}
> -}
> -
> -expect "ftp>"
> -send "exit\r"
> -
> -send_user "\nTest Successful\n\n"
> -exit 0
> diff --git a/testcases/network/tcp_cmds/ftp/ftp03 b/testcases/network/tcp_cmds/ftp/ftp03
> index a99a1a0..13e5273 100755
> --- a/testcases/network/tcp_cmds/ftp/ftp03
> +++ b/testcases/network/tcp_cmds/ftp/ftp03
> @@ -31,130 +31,77 @@
>   #	This version is intended for EAL certification, it will need modification
>   #	to conform with LTP standards in the offical LTP tree.
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_setup
> -#-----------------------------------------------------------------------
> -
> -do_setup()
> +setup()
>   {
> -
> -    RHOST="localhost"
> -    TEST_USER="ftpuser1"
> -    TCtmp=/home/$TEST_USER
> -    TEST_USER_PASSWD="eal"
> -    TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
> -    TEST_USER_HOMEDIR="/home/$TEST_USER"
> -    VSFTP_CONF=
> -
> -    tst_setup
> -
> -    exists ftp useradd userdel vftpd
> -
> -    for vsftp_conf in /etc/vsftpd /etc; do
> -
> -        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
> -            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
> -            break
> -        fi
> -
> -    done
> -    if [ ! -r "$VSFTP_CONF" ] ; then
> -        end_testcase "vsftpd.conf not found."
> -    fi
> -    LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
> -
> -    [ "$LOCAL_ENABLE" != "YES" ] && LOCAL_ENABLE="NO"
> -
> -    userdel $TEST_USER
> -    sleep 1
> -
> -    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
> -        end_testcase "Could not add test user $TEST_USER on system $RHOST."
> -    fi
> -
> -    trap do_cleanup QUIT
> -
> -    # create users home diretory (SLES 8 does not do this, even when specified
> -    # in adduser)
> -    USER_UID=$(id -u $TEST_USER)
> -    USER_GID=$(id -g $TEST_USER)
> -    mkdir -p "$TEST_USER_HOMEDIR"
> -    chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
> -
> +	exists ftp useradd userdel vsftpd
> +	export TEST_USER="ftpuser3"
> +	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
> +	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
> +	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
> +	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
> +	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
>   }
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_cleanup
> -#-----------------------------------------------------------------------
> -
> -do_cleanup()
> +do_test()
>   {
> -    userdel $TEST_USER
> -    tst_cleanup
> -}
> -
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_test
> -#
> -# DESCRIPTION: The test user will ftp in and create a directory in his home directory on the remote host.
> -#              The directory is then checked on the remote hosts to see if it is owned
> -#	       by the test user.
> -#-----------------------------------------------------------------------
> -
> -do_test(){
> -    tst_resm TINFO "TEST: Ftp into a remote host as a local user (other than root), LOCAL_ENABLE=$LOCAL_ENABLE"
> +	echo "TEST: Ftp into a remote host as a local user (other than root),"
> +	echo "LOCAL_ENABLE=$LOCAL_ENABLE"
>   
> -    if [ "$LOCAL_ENABLE" = "YES" ]; then
> +	if [ "$LOCAL_ENABLE" = "YES" ]; then
>   	expect -c "
> -            spawn ftp $RHOST
> -            sleep 1
> -            expect -re \": \"
> -            send \"$TEST_USER\r\"
> -            expect -re \"Password:\"
> -            send \"$TEST_USER_PASSWD\r\"
> -            expect {
> -                # 530 - Login failed
> -                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
> -                # 230 - Login successful
> -                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
> -            }
> -            expect \"ftp> \"
> -            send \"quit\r\"
> +		spawn ftp $RHOST
> +		sleep 1
> +		expect -re \": \"
> +		send \"$TEST_USER\r\"
> +		expect -re \"Password:\"
> +		send \"$TEST_USER_PASSWD\r\"
> +		expect {
> +			# 530 - Login failed
> +			\"530\" {send_user \"$FAIL_530\n\";exit 1}
> +			# 230 - Login successful
> +			\"230\" {send_user \"$PASS_230\n\";exit 0}
> +		}
> +		expect \"ftp> \"
> +		send \"quit\r\"
>   	"
> -    else
> -        expect -c "
> -            spawn ftp $RHOST
> -            sleep 1
> -            expect -re \": \"
> -            send \"$TEST_USER\r\"
> -            expect -re \"Password:\"
> -            send \"$TEST_USER_PASSWD\r\"
> -            expect {
> -                # 230 - Login successful
> -                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
> -                # 500 - Login failed
> -                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> -                # 530 - Login failed
> -                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> -            }
> -            expect \"ftp> \"
> -            send \"quit\r\"
> -        "
> -    fi
> -
> -    if [ $? != 0 ]; then
> -        end_testcase "Testcase failed"
> -    fi
> +	else
> +	expect -c "
> +		spawn ftp $RHOST
> +		sleep 1
> +		expect -re \": \"
> +		send \"$TEST_USER\r\"
> +		expect -re \"Password:\"
> +		send \"$TEST_USER_PASSWD\r\"
> +		expect {
> +			# 230 - Login successful
> +			\"230\" {send_user \"$FAIL_230\n\";exit 1}
> +			# 500 - Login failed
> +			\"500\" {send_user \"$PASS_500\n\";exit 0}
> +			# 530 - Login failed
> +			\"530\" {send_user \"$PASS_530\n\";exit 0}
> +		}
> +		expect \"ftp> \"
> +		send \"quit\r\"
> +	"
> +	fi
>   }
>   
> -#----------------------------------------------------------------------
> -# FUNCTION: MAIN
> -# PURPOSE:  To invoke the functions to perform the tasks described in
> -#           the prologue.
> -#----------------------------------------------------------------------
> -. net_cmdlib.sh
> +TCID="$0"
> +TST_TOTAL=1
>   
> -read_opts $*
> +. test.sh
> +. ftp_setup
> +
> +setup
>   do_setup
> +TST_CLEANUP=do_cleanup
> +
>   do_test
> -end_testcase
> +ret=$?
> +if [ $ret -ne 0 ]; then

I would use "$?" inside if, don't need "ret" variable here and in other 
places as well.

> +	tst_resm TFAIL "Test $TCID FAIL"
> +else
> +	tst_resm TPASS "Test $TCID PASS"
> +fi
> +
> +tst_exit
> diff --git a/testcases/network/tcp_cmds/ftp/ftp04 b/testcases/network/tcp_cmds/ftp/ftp04
> index 8329eb0..c13614d 100755
> --- a/testcases/network/tcp_cmds/ftp/ftp04
> +++ b/testcases/network/tcp_cmds/ftp/ftp04
> @@ -28,77 +28,66 @@
>   #   03/04/03 Jerone Young (jeroney@us.ibm.com)
>   #   09/21/05 Kris Wilson (krisw@us.ibm.com) Check if vsftpd is on system.
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_setup
> -#-----------------------------------------------------------------------
> -
> -do_setup()
> +setup()
>   {
> +	exists awk expect ftp vsftpd
>   

Use tst_check_cmd()

> -    tvar=${MACHTYPE%-*}
> -    tvar=${tvar#*-}
> -
> -    RHOST=localhost
> -    TEST_USER=root
> -
> -    tst_setup
> +	TEST_USER=root
>   
> -    if [ -n "$PASSWD" ]; then
> -        TEST_USER_PASSWORD=$PASSWD
> -    else
> -        end_testcase "You must set your password via the PASSWD variable."
> -        exit 1
> -    fi
> +	tvar=${MACHTYPE%-*}
> +	tvar=${tvar#*-}
>   
> -    exists awk expect ftp vsftpd
> -
> -    if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
> -        echo "Verifying test user $TEST_USER is in /etc/vsftpd.ftpusers database..."
> -        FTPUSERS=$(awk "/$TEST_USER/" /etc/vsftpd.ftpusers)
> -    else
> -        echo "Verifying test user $TEST_USER is in /etc/ftpusers database..."
> -        FTPUSERS=$(awk "/$TEST_USER/" /etc/ftpusers)
> -    fi
> -    if [ -z "$FTPUSERS" ] ; then
> -        end_testcase "Test user $TEST_USER not found in /etc/ftpusers unable to run TEST, exiting 0 ..."
> -    fi
> +	if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
> +		ftpusers="/etc/vsftpd/ftpusers"
> +	else
> +		ftpusers="/etc/ftpusers"
> +	fi
> +	echo "Verifying test user $TEST_USER is in ${ftpusers} database..."
> +	FTPUSERS=$(awk "/$TEST_USER/" ${ftpusers})
> +	if [ -z "$FTPUSERS" ] ; then
> +		tst_brkm TBROK "$TEST_USER not found in $ftpusers exiting 0 ..."
> +	fi
>   
> +	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
> +	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
>   }
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_test
> -#-----------------------------------------------------------------------
>   do_test()
>   {
> -
> -    tst_resm TINFO "Ftp should reject $TEST_USER from loging in successfully"
> -    expect -c "
> -        spawn ftp $RHOST
> -        sleep 1
> -        expect -re \": \"
> -        send \"$TEST_USER\r\"
> -        expect -re \"Password:\"
> -        send \"$TEST_USER_PASSWD\r\"
> -        expect {
> -            # 230 - Login successful
> -            \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
> -            # 530 - Login failed
> -            \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> -        }
> -        expect \"ftp> \"
> -        send \"quit\r\"
> -    "
> -
> -    [ $? -eq 0 ] || end_testcase "Testcase failed."
> -
> +	echo "Ftp should reject $TEST_USER from loging in successfully"
> +	expect -c "
> +		spawn ftp $RHOST
> +		sleep 1
> +		expect -re \": \"
> +		send \"$TEST_USER\r\"
> +		expect -re \"Password:\"
> +		send \"$TEST_USER_PASSWD\r\"
> +		expect {
> +			# 230 - Login successful
> +			\"230\" {send_user \"$FAIL_230\n\";exit 1}
> +			# 530 - Login failed
> +			\"530\" {send_user \"$PASS_530\n\";exit 0}
> +		}
> +		expect \"ftp> \"
> +		send \"quit\r\"
> +	"
>   }
>   
> -#----------------------------------------------------------------------
> -# FUNCTION: MAIN
> -#----------------------------------------------------------------------
> -. net_cmdlib.sh
> +TCID="$0"
> +TST_TOTAL=1
> +
> +. test.sh
> +. ftp_setup
>   
> -read_opts $*
> +setup
>   do_setup
> +
>   do_test
> -end_testcase
> +ret=$?
> +if [ $ret -ne 0 ]; then
> +	tst_resm TFAIL "Test $TCID FAIL"
> +else
> +	tst_resm TPASS "Test $TCID PASS"
> +fi
> +
> +tst_exit
> diff --git a/testcases/network/tcp_cmds/ftp/ftp05 b/testcases/network/tcp_cmds/ftp/ftp05
> index 4f91334..746c87a 100755
> --- a/testcases/network/tcp_cmds/ftp/ftp05
> +++ b/testcases/network/tcp_cmds/ftp/ftp05
> @@ -30,96 +30,87 @@
>   #  NOTE:
>   #	This version is intended for EAL certification, it will need modification
>   #	to conform with LTP standards in the offical LTP tree.
> +#
> +# DESCRIPTION:
> +#	The anonymous user will ftp in and create a directory in his/her
> +#	home directory on the remote host.
> +#
>   
> -do_setup()
> +setup()
>   {
> -    RHOST="localhost"
> -    TEST_USER="anonymous"
> -    TEST_USER_PASSWD="noone@nowhere.com"
> -    VSFTP_CONF=
> -
> -    tst_setup
> -
> -    exists expect ftp vsftpd
> -
> -    for vsftp_conf in /etc/vsftpd /etc; do
> -
> -        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
> -            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
> -            break
> -        fi
> -
> -    done
> -    if [ ! -r "$VSFTP_CONF" ] ; then
> -        end_testcase "vsftpd.conf not found."
> -    fi
> -    ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
> -    if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
> -        ANONYMOUS_ENABLE="YES"
> -    fi
> +	exists expect ftp vsftpd
> +	TEST_USER="anonymous"
> +	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
> +	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
> +	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
> +	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
> +	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
>   }
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION   : do_test
> -#
> -# DESCRIPTION: The anonymous user will ftp in and create a directory in his/her
> -#              home directory on the remote host.
> -#-----------------------------------------------------------------------
> -
>   do_test()
>   {
> -    tst_resm TINFO "Ftp into a remote host as anonymous user; ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
> +	echo "Ftp into a remote host as anonymous user;"
> +	echo "ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
>   
> -    if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
> -        expect -c "
> -            spawn ftp $RHOST
> -            sleep 1
> -            expect -re \": \"
> -            send \"$TEST_USER\r\"
> -            expect -re \"Password:\"
> -            send \"$TEST_USER_PASSWD\r\"
> -            expect {
> -                # 530 - Login failed
> -                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
> -                # 230 - Login successful
> -                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
> -            }
> -            expect \"ftp> \"
> -            send \"quit\r\"
> +	if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
> +	expect -c "
> +		spawn ftp $RHOST
> +		sleep 1
> +		expect -re \": \"
> +		send \"$TEST_USER\r\"
> +		expect -re \"Password:\"
> +		send \"$TEST_USER_PASSWD\r\"
> +		expect {
> +			# 530 - Login failed
> +			\"530\" {send_user \"$FAIL_530\n\";exit 1}
> +			# 230 - Login successful
> +			\"230\" {send_user \"$PASS_230\n\";exit 0}
> +		}
> +		expect \"ftp> \"
> +		send \"quit\r\"
>   	"
> -    else
> -        expect -c "
> -            spawn ftp $RHOST
> -            sleep 1
> -            expect -re \": \"
> -            send \"$TEST_USER\r\"
> -            expect -re \"Password:\"
> -            send \"$TEST_USER_PASSWD\r\"
> -            expect {
> -                # 230 - Login successful
> -                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
> -                # 500 - Login failed
> -                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> -                # 530 - Login failed
> -                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> -            }
> -            expect \"ftp> \"
> -            send \"quit\r\"
> -        "
> -    fi
> -
> -    [ $? -eq 0 ] || end_testcase "Testcase failed."
> +	else
> +	expect -c "
> +		spawn ftp $RHOST
> +		sleep 1
> +		expect -re \": \"
> +		send \"$TEST_USER\r\"
> +		expect -re \"Password:\"
> +		send \"$TEST_USER_PASSWD\r\"
> +		expect {
> +			# 230 - Login successful
> +			\"230\" {send_user \"$FAIL_230\n\";exit 1}
> +			# 500 - Login failed
> +			\"500\" {send_user \"$PASS_500\n\";exit 0}
> +			# 530 - Login failed
> +			\"530\" {send_user \"$PASS_530\n\";exit 0}
> +		}
> +		expect \"ftp> \"
> +		send \"quit\r\"
> +	"
> +	fi
>   
> +	if [ $? -ne 0 ]; then
> +		tst_exit TBROK "Testcase failed."

There is tst_brkm library function for that purpose, it includes tst_exit.

> +	fi
>   }
>   
> -#----------------------------------------------------------------------
> -# FUNCTION: MAIN
> -# PURPOSE:  To invoke the functions to perform the tasks described in
> -#           the prologue.
> -#----------------------------------------------------------------------
> -. net_cmdlib.sh
> +TCID="$0"
> +TST_TOTAL=1
>   
> -read_opts $*
> +. test.sh
> +. ftp_setup
> +
> +setup
>   do_setup
> +#TEST_USER_PASSWD="noone@nowhere.com"
> +
>   do_test
> -end_testcase
> +ret=$?
> +if [ $ret -ne 0 ]; then
> +	tst_resm TFAIL "Test $TCID FAIL"
> +else
> +	tst_resm TPASS "Test $TCID PASS"
> +fi
> +
> +tst_exit
> diff --git a/testcases/network/tcp_cmds/ftp/ftp_set_passwd b/testcases/network/tcp_cmds/ftp/ftp_set_passwd
> deleted file mode 100755
> index 7c275c9..0000000
> --- a/testcases/network/tcp_cmds/ftp/ftp_set_passwd
> +++ /dev/null
> @@ -1,28 +0,0 @@
> -#!/usr/bin/expect
> -#
> -# Set Password for a specific new user
> -# This script should be run as 'root'
> -#
> -# Example:
> -#		./set_passwd USER PASSWD
> -#
> -
> -if { [llength $argv] < 2} {
> -    exit 1
> -}
> -
> -set USER [lindex $argv 0]
> -set PASSWD [lindex $argv 1]
> -
> -set timeout 30
> -
> -spawn passwd $USER
> -expect "Enter new password: "
> -sleep 1
> -exp_send "$PASSWD\r"
> -expect "Re-type new password: "
> -sleep 1
> -exp_send "$PASSWD\r"
> -expect success
> -
> -exit 0
> diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup b/testcases/network/tcp_cmds/ftp/ftp_setup
> new file mode 100644
> index 0000000..7100736
> --- /dev/null
> +++ b/testcases/network/tcp_cmds/ftp/ftp_setup
> @@ -0,0 +1,82 @@
> +#!/bin/sh
> +###############################################################################
> +## Copyright (c) International Business Machines  Corp., 2003                ##
> +##                                                                           ##
> +## This program is free software;  you can redistribute it and/or modify     ##
> +## it under the terms of the GNU General Public License as published by      ##
> +## the Free Software Foundation; either version 2 of the License, or         ##
> +## (at your option) any later version.                                       ##
> +##                                                                           ##
> +## This program is distributed in the hope that it will be useful,           ##
> +## but WITHOUT ANY WARRANTY;  without even the implied warranty of           ##
> +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                 ##
> +## the GNU General Public License for more details.                          ##
> +##                                                                           ##
> +## You should have received a copy of the GNU General Public License         ##
> +## along with this program;  if not, write to the Free Software Foundation,  ##
> +## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          ##
> +##                                                                           ##
> +###############################################################################
> +
> +exists()
> +{
> +	for cmd in $*; do
> +		if ! command -v $cmd > /dev/null 2>&1; then
> +			tst_brkm TBROK "$cmd: command not found"
> +		fi
> +	done
> +}

tst_check_cmd() replaces it.

> +
> +do_setup()
> +{
> +
> +	export RHOST="localhost"
> +	export TEST_USER_PASSWD="eal"
> +	export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
> +	export TEST_USER_HOMEDIR="/home/$TEST_USER"
> +
> +	for vsftp_confdir in /etc/vsftpd /etc; do
> +		if [ -r "$vsftp_confdir/vsftpd.conf" ]; then
> +			VSFTP_CONF="$vsftp_confdir/vsftpd.conf"
> +			break
> +		fi
> +	done
> +	if [ ! -r "$VSFTP_CONF" ] ; then
> +		tst_brkm TBROK "vsftpd.conf not found."
> +	fi
> +
> +	LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
> +	if [ "$LOCAL_ENABLE" != "YES" ]; then
> +		LOCAL_ENABLE="NO"
> +	fi
> +
> +	ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
> +	if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
> +		ANONYMOUS_ENABLE="YES"
> +	fi
> +
> +	if [ $TEST_USER = "root" -o $TEST_USER = "anonymous" ]; then
> +		return
> +	fi
> +
> +	userdel -r $TEST_USER
> +	sleep 1
> +
> +	if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
> +		tst_brkm TBROK "Could not add test user $TEST_USER to system $RHOST."
> +	fi
> +
> +	# create users home diretory (SLES 8 does not do this, even when specified
> +	# in adduser)
> +	USER_UID=$(id -u $TEST_USER)
> +	USER_GID=$(id -g $TEST_USER)
> +	mkdir -p "$TEST_USER_HOMEDIR"
> +	chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
> +}
> +
> +do_cleanup()
> +{
> +	if [ $TEST_USER != "root" -a $TEST_USER != "anonymous" ]; then
> +		userdel -r $TEST_USER
> +	fi
> +}
> diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf b/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
> deleted file mode 100755
> index 7e496f6..0000000
> --- a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
> +++ /dev/null
> @@ -1,5 +0,0 @@
> -#!/bin/sh
> -
> -grep -v "local_enable" /etc/vsftpd.conf > /tmp/vsftpd.conf
> -mv -f /tmp/vsftpd.conf /etc/vsftpd.conf
> -echo "local_enable=YES" >> /etc/vsftpd.conf

Also, the same comments apply to the 2nd ssh patch.

Thanks,
Alexey


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH 1/2] network ftp: some cleanup
  2014-07-31 11:55 ` [LTP] [PATCH 1/2] network ftp: " Alexey
@ 2014-08-01  1:25   ` Zeng Linggang
  2014-08-01  3:11   ` [LTP] [PATCH v2 " Zeng Linggang
  2014-08-01  3:12   ` [LTP] [PATCH v2 2/2] network ssh: " Zeng Linggang
  2 siblings, 0 replies; 8+ messages in thread
From: Zeng Linggang @ 2014-08-01  1:25 UTC (permalink / raw)
  To: Alexey; +Cc: ltp-list

Hi Alexey!
On Thu, 2014-07-31 at 16:20 +0400, Alexey wrote:
> Hi Zeng!
> On 07/29/2014 03:42 PM, Zeng Linggang wrote:
> > * Move do_setup and do_cleanup into ftp_setup.
> >
> > * Delete ftp02_s1 and add do_test function for it.
> >
> > * Delete ftp_set_passwd and ftp_setup_vsftp_conf, since they are not be used.
> >
> > * Use test.sh instead of net_cmdlib.sh
> >
> > * Define local exists function instead of which in cmdlib.sh
> >
> > * Abandon trap and use tst_exit.
> >
> > * Make the test like:
> > 	(set TCID TST_TOTAL ...)
> > 	setup
> > 	do_test
> > 	check_result
> > 	tst_exit
> >
> > * Some cleanup.
> >
> > Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> > ---
> >   testcases/network/tcp_cmds/ftp/ftp02               | 100 +++++++-----
> >   testcases/network/tcp_cmds/ftp/ftp02_s1            |  71 ---------
> >   testcases/network/tcp_cmds/ftp/ftp03               | 177 ++++++++-------------
> >   testcases/network/tcp_cmds/ftp/ftp04               | 109 ++++++-------
> >   testcases/network/tcp_cmds/ftp/ftp05               | 149 ++++++++---------
> >   testcases/network/tcp_cmds/ftp/ftp_set_passwd      |  28 ----
> >   testcases/network/tcp_cmds/ftp/ftp_setup           |  82 ++++++++++
> >   .../network/tcp_cmds/ftp/ftp_setup_vsftp_conf      |   5 -
> >   8 files changed, 320 insertions(+), 401 deletions(-)
> >   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp02_s1
> >   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_set_passwd
> >   create mode 100644 testcases/network/tcp_cmds/ftp/ftp_setup
> >   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
> >
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp02 b/testcases/network/tcp_cmds/ftp/ftp02
> > index 6d6e021..a86319f 100755
> > --- a/testcases/network/tcp_cmds/ftp/ftp02
> > +++ b/testcases/network/tcp_cmds/ftp/ftp02
> > @@ -28,59 +28,73 @@
> >   #  NOTE:
> >   #       This version is intended for EAL certification, it will need modification
> >   #       to conform with LTP standards in the offical LTP tree.
> > +#
> > +# DESCRIPTION:
> > +#	Create Test User
> > +#	Make sure test user cannont log in with invalid password
> > +#	Cleanup Test User from system
> > +#	Exit with exit code of script called upon
> > +#
> >   
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  do_setup
> > -#-----------------------------------------------------------------------
> > -
> > -do_setup()
> > +setup()
> >   {
> > +	exists expect ftp useradd userdel
> We don't need "exists()" anymore, use tst_check_cmd() from test.sh instead.
> 

Thank you for your review.
I got it.

> > +	export TEST_USER="ftpuser2"
> > +	CONNECTION_FAILED="Connection failed; test FAILED"
> > +	EXPECTED="Login failed as expected; test PASSED"
> > +	UNEXPECTED="Login succeeded unexpectedly; test FAILED"
> > +}
> >   
> > -    export RHOST="localhost"
> > -    export TEST_USER="ftpuser2"
> > -    export TEST_USER_PASSWD="eal"
> > -    export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
> > -    export TEST_USER_HOMEDIR="/home/$TEST_USER"
> > -
> > -    # erase user if he may exist, so we can have a clean env
> > -    TCtmp="/home/$TEST_USER"
> > -
> > -    tst_setup
> > +do_test()
> > +{
> > +	set PASSWD "invaild_password?!!"
> >   
> > -    exists expect ftp ftp02_s1 useradd userdel
> > +	set timeout 90
> >   
> > -    userdel $TEST_USER
> > -    sleep 1
> > +	expect -c "
> > +		#ftp to host
> > +		spawn ftp $RHOST
> > +		sleep 1
> > +		# Check if connection succeeded.
> > +		expect {
> > +			\"Name\" {}
> > +			timeout {send_user \"\n$CONNECTION_FAILED\n\";exit 1}
> > +		}
> >   
> > -    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
> > -        end_testcase "Could not add test user $TEST_USER to system $RHOST."
> > -    fi
> > +		send \"$RUSER\r\"
> > +		sleep 1
> > +		expect -re \"Password:\"
> > +		send \"$PASSWD\r\"
> > +		sleep 1
> >   
> > -    trap do_cleanup EXIT
> > +		expect {
> > +			# 530 - Login failed
> > +			\"530\" {send_user \"$EXPECTED\n\";exit 0}
> > +			# 230 - Login successful
> > +			\"230\" {send_user \"$UNEXPECTED\n\"; exit 1}
> > +		}
> >   
> > +		expect \"ftp>\"
> > +		send \"exit\r\"
> > +	"
> >   }
> >   
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  do_cleanup
> > -#-----------------------------------------------------------------------
> > +TCID="$0"
> > +TST_TOTAL=1
> >   
> > -do_cleanup()
> > -{
> > -    userdel $TEST_USER
> > -    tst_cleanup
> > -}
> > -
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  MAIN
> > -#
> > -# DESCRIPTION: Create Test User
> > -#              Call upon script to make sure test user cannont log in with invalid password
> > -#	       Cleanup Test User from system
> > -#              Exit with exit code of script called upon
> > -#-----------------------------------------------------------------------
> > -. net_cmdlib.sh
> > +. test.sh
> > +. ftp_setup
> >   
> > -read_opts $*
> > +setup
> >   do_setup
> > -ftp02_s1 || end_testcase "Testcase failed."
> > -end_testcase
> > +TST_CLEANUP=do_cleanup
> > +
> > +do_test
> > +ret=$?
> > +if [ $ret -ne 0 ]; then
> > +	tst_resm TFAIL "Test $TCID FAIL"
> > +else
> > +	tst_resm TPASS "Test $TCID PASS"
> > +fi
> > +
> > +tst_exit
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp02_s1 b/testcases/network/tcp_cmds/ftp/ftp02_s1
> > deleted file mode 100755
> > index 18b08da..0000000
> > --- a/testcases/network/tcp_cmds/ftp/ftp02_s1
> > +++ /dev/null
> > @@ -1,71 +0,0 @@
> > -#! /usr/bin/expect -f
> > -#*********************************************************************
> > -#   Copyright (c) International Business Machines  Corp., 2003, 2005
> > -#
> > -#   This program is free software;  you can redistribute it and/or modify
> > -#   it under the terms of the GNU General Public License as published by
> > -#   the Free Software Foundation; either version 2 of the License, or
> > -#   (at your option) any later version.
> > -#
> > -#   This program is distributed in the hope that it will be useful,
> > -#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
> > -#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> > -#   the GNU General Public License for more details.
> > -#
> > -#   You should have received a copy of the GNU General Public License
> > -#   along with this program;  if not, write to the Free Software
> > -#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > -#
> > -#
> > -#
> > -#  FILE   : ftp
> > -#
> > -#  PURPOSE: Test to see if ftp rejects a user with an invalid password
> > -#
> > -#  SETUP: The program `/usr/bin/expect' MUST be installed.
> > -#
> > -#  HISTORY:
> > -# 	03/04/03 Jerone Young (jeroney@us.ibm.com)
> > -#       09/21/05 Kris Wilson (krisw@us.ibm.com) Check for connection failure.
> > -#                (If WS system, no vsftpd; connection will fail.)
> > -
> > -set RHOST $env(RHOST)
> > -set TEST_USER $env(TEST_USER)
> > -set TEST_USER_PASSWD $env(TEST_USER_PASSWD)
> > -set TEST_USER_HOMEDIR $env(TEST_USER_HOMEDIR)
> > -
> > -#RUSER
> > -set RUSER $TEST_USER
> > -
> > -#set PASSWD to be an invalid Password
> > -set PASSWD "invaild_password?!!"
> > -
> > -set timeout 90
> > -
> > -#ftp to host
> > -spawn ftp $RHOST
> > -sleep 1
> > -# Check if connection succeeded.
> > -expect {
> > -    "Name" {}
> > -    timeout {send_user "\nConnection failed; test FAILED\n";exit 1}
> > -}
> > -
> > -send "$RUSER\r"
> > -sleep 1
> > -expect -re "Password:"
> > -send "$PASSWD\r"
> > -sleep 1
> > -
> > -expect {
> > -    # 530 - Login failed
> > -    "530" {send_user "Login failed as expected; test PASSED\n"}
> > -    # 230 - Login successful
> > -    "230" {send_user "Login succeeded unexpectedly; test FAILED\n"; exit 1}
> > -}
> > -
> > -expect "ftp>"
> > -send "exit\r"
> > -
> > -send_user "\nTest Successful\n\n"
> > -exit 0
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp03 b/testcases/network/tcp_cmds/ftp/ftp03
> > index a99a1a0..13e5273 100755
> > --- a/testcases/network/tcp_cmds/ftp/ftp03
> > +++ b/testcases/network/tcp_cmds/ftp/ftp03
> > @@ -31,130 +31,77 @@
> >   #	This version is intended for EAL certification, it will need modification
> >   #	to conform with LTP standards in the offical LTP tree.
> >   
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  do_setup
> > -#-----------------------------------------------------------------------
> > -
> > -do_setup()
> > +setup()
> >   {
> > -
> > -    RHOST="localhost"
> > -    TEST_USER="ftpuser1"
> > -    TCtmp=/home/$TEST_USER
> > -    TEST_USER_PASSWD="eal"
> > -    TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
> > -    TEST_USER_HOMEDIR="/home/$TEST_USER"
> > -    VSFTP_CONF=
> > -
> > -    tst_setup
> > -
> > -    exists ftp useradd userdel vftpd
> > -
> > -    for vsftp_conf in /etc/vsftpd /etc; do
> > -
> > -        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
> > -            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
> > -            break
> > -        fi
> > -
> > -    done
> > -    if [ ! -r "$VSFTP_CONF" ] ; then
> > -        end_testcase "vsftpd.conf not found."
> > -    fi
> > -    LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
> > -
> > -    [ "$LOCAL_ENABLE" != "YES" ] && LOCAL_ENABLE="NO"
> > -
> > -    userdel $TEST_USER
> > -    sleep 1
> > -
> > -    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
> > -        end_testcase "Could not add test user $TEST_USER on system $RHOST."
> > -    fi
> > -
> > -    trap do_cleanup QUIT
> > -
> > -    # create users home diretory (SLES 8 does not do this, even when specified
> > -    # in adduser)
> > -    USER_UID=$(id -u $TEST_USER)
> > -    USER_GID=$(id -g $TEST_USER)
> > -    mkdir -p "$TEST_USER_HOMEDIR"
> > -    chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
> > -
> > +	exists ftp useradd userdel vsftpd
> > +	export TEST_USER="ftpuser3"
> > +	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
> > +	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
> > +	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
> > +	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
> > +	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
> >   }
> >   
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  do_cleanup
> > -#-----------------------------------------------------------------------
> > -
> > -do_cleanup()
> > +do_test()
> >   {
> > -    userdel $TEST_USER
> > -    tst_cleanup
> > -}
> > -
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  do_test
> > -#
> > -# DESCRIPTION: The test user will ftp in and create a directory in his home directory on the remote host.
> > -#              The directory is then checked on the remote hosts to see if it is owned
> > -#	       by the test user.
> > -#-----------------------------------------------------------------------
> > -
> > -do_test(){
> > -    tst_resm TINFO "TEST: Ftp into a remote host as a local user (other than root), LOCAL_ENABLE=$LOCAL_ENABLE"
> > +	echo "TEST: Ftp into a remote host as a local user (other than root),"
> > +	echo "LOCAL_ENABLE=$LOCAL_ENABLE"
> >   
> > -    if [ "$LOCAL_ENABLE" = "YES" ]; then
> > +	if [ "$LOCAL_ENABLE" = "YES" ]; then
> >   	expect -c "
> > -            spawn ftp $RHOST
> > -            sleep 1
> > -            expect -re \": \"
> > -            send \"$TEST_USER\r\"
> > -            expect -re \"Password:\"
> > -            send \"$TEST_USER_PASSWD\r\"
> > -            expect {
> > -                # 530 - Login failed
> > -                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
> > -                # 230 - Login successful
> > -                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
> > -            }
> > -            expect \"ftp> \"
> > -            send \"quit\r\"
> > +		spawn ftp $RHOST
> > +		sleep 1
> > +		expect -re \": \"
> > +		send \"$TEST_USER\r\"
> > +		expect -re \"Password:\"
> > +		send \"$TEST_USER_PASSWD\r\"
> > +		expect {
> > +			# 530 - Login failed
> > +			\"530\" {send_user \"$FAIL_530\n\";exit 1}
> > +			# 230 - Login successful
> > +			\"230\" {send_user \"$PASS_230\n\";exit 0}
> > +		}
> > +		expect \"ftp> \"
> > +		send \"quit\r\"
> >   	"
> > -    else
> > -        expect -c "
> > -            spawn ftp $RHOST
> > -            sleep 1
> > -            expect -re \": \"
> > -            send \"$TEST_USER\r\"
> > -            expect -re \"Password:\"
> > -            send \"$TEST_USER_PASSWD\r\"
> > -            expect {
> > -                # 230 - Login successful
> > -                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
> > -                # 500 - Login failed
> > -                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> > -                # 530 - Login failed
> > -                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> > -            }
> > -            expect \"ftp> \"
> > -            send \"quit\r\"
> > -        "
> > -    fi
> > -
> > -    if [ $? != 0 ]; then
> > -        end_testcase "Testcase failed"
> > -    fi
> > +	else
> > +	expect -c "
> > +		spawn ftp $RHOST
> > +		sleep 1
> > +		expect -re \": \"
> > +		send \"$TEST_USER\r\"
> > +		expect -re \"Password:\"
> > +		send \"$TEST_USER_PASSWD\r\"
> > +		expect {
> > +			# 230 - Login successful
> > +			\"230\" {send_user \"$FAIL_230\n\";exit 1}
> > +			# 500 - Login failed
> > +			\"500\" {send_user \"$PASS_500\n\";exit 0}
> > +			# 530 - Login failed
> > +			\"530\" {send_user \"$PASS_530\n\";exit 0}
> > +		}
> > +		expect \"ftp> \"
> > +		send \"quit\r\"
> > +	"
> > +	fi
> >   }
> >   
> > -#----------------------------------------------------------------------
> > -# FUNCTION: MAIN
> > -# PURPOSE:  To invoke the functions to perform the tasks described in
> > -#           the prologue.
> > -#----------------------------------------------------------------------
> > -. net_cmdlib.sh
> > +TCID="$0"
> > +TST_TOTAL=1
> >   
> > -read_opts $*
> > +. test.sh
> > +. ftp_setup
> > +
> > +setup
> >   do_setup
> > +TST_CLEANUP=do_cleanup
> > +
> >   do_test
> > -end_testcase
> > +ret=$?
> > +if [ $ret -ne 0 ]; then
> 
> I would use "$?" inside if, don't need "ret" variable here and in other 
> places as well.
> 

Got it.

> > +	tst_resm TFAIL "Test $TCID FAIL"
> > +else
> > +	tst_resm TPASS "Test $TCID PASS"
> > +fi
> > +
> > +tst_exit
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp04 b/testcases/network/tcp_cmds/ftp/ftp04
> > index 8329eb0..c13614d 100755
> > --- a/testcases/network/tcp_cmds/ftp/ftp04
> > +++ b/testcases/network/tcp_cmds/ftp/ftp04
> > @@ -28,77 +28,66 @@
> >   #   03/04/03 Jerone Young (jeroney@us.ibm.com)
> >   #   09/21/05 Kris Wilson (krisw@us.ibm.com) Check if vsftpd is on system.
> >   
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  do_setup
> > -#-----------------------------------------------------------------------
> > -
> > -do_setup()
> > +setup()
> >   {
> > +	exists awk expect ftp vsftpd
> >   
> 
> Use tst_check_cmd()
> 

Got it.

> > -    tvar=${MACHTYPE%-*}
> > -    tvar=${tvar#*-}
> > -
> > -    RHOST=localhost
> > -    TEST_USER=root
> > -
> > -    tst_setup
> > +	TEST_USER=root
> >   
> > -    if [ -n "$PASSWD" ]; then
> > -        TEST_USER_PASSWORD=$PASSWD
> > -    else
> > -        end_testcase "You must set your password via the PASSWD variable."
> > -        exit 1
> > -    fi
> > +	tvar=${MACHTYPE%-*}
> > +	tvar=${tvar#*-}
> >   
> > -    exists awk expect ftp vsftpd
> > -
> > -    if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
> > -        echo "Verifying test user $TEST_USER is in /etc/vsftpd.ftpusers database..."
> > -        FTPUSERS=$(awk "/$TEST_USER/" /etc/vsftpd.ftpusers)
> > -    else
> > -        echo "Verifying test user $TEST_USER is in /etc/ftpusers database..."
> > -        FTPUSERS=$(awk "/$TEST_USER/" /etc/ftpusers)
> > -    fi
> > -    if [ -z "$FTPUSERS" ] ; then
> > -        end_testcase "Test user $TEST_USER not found in /etc/ftpusers unable to run TEST, exiting 0 ..."
> > -    fi
> > +	if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
> > +		ftpusers="/etc/vsftpd/ftpusers"
> > +	else
> > +		ftpusers="/etc/ftpusers"
> > +	fi
> > +	echo "Verifying test user $TEST_USER is in ${ftpusers} database..."
> > +	FTPUSERS=$(awk "/$TEST_USER/" ${ftpusers})
> > +	if [ -z "$FTPUSERS" ] ; then
> > +		tst_brkm TBROK "$TEST_USER not found in $ftpusers exiting 0 ..."
> > +	fi
> >   
> > +	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
> > +	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
> >   }
> >   
> > -#-----------------------------------------------------------------------
> > -# FUNCTION:  do_test
> > -#-----------------------------------------------------------------------
> >   do_test()
> >   {
> > -
> > -    tst_resm TINFO "Ftp should reject $TEST_USER from loging in successfully"
> > -    expect -c "
> > -        spawn ftp $RHOST
> > -        sleep 1
> > -        expect -re \": \"
> > -        send \"$TEST_USER\r\"
> > -        expect -re \"Password:\"
> > -        send \"$TEST_USER_PASSWD\r\"
> > -        expect {
> > -            # 230 - Login successful
> > -            \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
> > -            # 530 - Login failed
> > -            \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> > -        }
> > -        expect \"ftp> \"
> > -        send \"quit\r\"
> > -    "
> > -
> > -    [ $? -eq 0 ] || end_testcase "Testcase failed."
> > -
> > +	echo "Ftp should reject $TEST_USER from loging in successfully"
> > +	expect -c "
> > +		spawn ftp $RHOST
> > +		sleep 1
> > +		expect -re \": \"
> > +		send \"$TEST_USER\r\"
> > +		expect -re \"Password:\"
> > +		send \"$TEST_USER_PASSWD\r\"
> > +		expect {
> > +			# 230 - Login successful
> > +			\"230\" {send_user \"$FAIL_230\n\";exit 1}
> > +			# 530 - Login failed
> > +			\"530\" {send_user \"$PASS_530\n\";exit 0}
> > +		}
> > +		expect \"ftp> \"
> > +		send \"quit\r\"
> > +	"
> >   }
> >   
> > -#----------------------------------------------------------------------
> > -# FUNCTION: MAIN
> > -#----------------------------------------------------------------------
> > -. net_cmdlib.sh
> > +TCID="$0"
> > +TST_TOTAL=1
> > +
> > +. test.sh
> > +. ftp_setup
> >   
> > -read_opts $*
> > +setup
> >   do_setup
> > +
> >   do_test
> > -end_testcase
> > +ret=$?
> > +if [ $ret -ne 0 ]; then
> > +	tst_resm TFAIL "Test $TCID FAIL"
> > +else
> > +	tst_resm TPASS "Test $TCID PASS"
> > +fi
> > +
> > +tst_exit
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp05 b/testcases/network/tcp_cmds/ftp/ftp05
> > index 4f91334..746c87a 100755
> > --- a/testcases/network/tcp_cmds/ftp/ftp05
> > +++ b/testcases/network/tcp_cmds/ftp/ftp05
> > @@ -30,96 +30,87 @@
> >   #  NOTE:
> >   #	This version is intended for EAL certification, it will need modification
> >   #	to conform with LTP standards in the offical LTP tree.
> > +#
> > +# DESCRIPTION:
> > +#	The anonymous user will ftp in and create a directory in his/her
> > +#	home directory on the remote host.
> > +#
> >   
> > -do_setup()
> > +setup()
> >   {
> > -    RHOST="localhost"
> > -    TEST_USER="anonymous"
> > -    TEST_USER_PASSWD="noone@nowhere.com"
> > -    VSFTP_CONF=
> > -
> > -    tst_setup
> > -
> > -    exists expect ftp vsftpd
> > -
> > -    for vsftp_conf in /etc/vsftpd /etc; do
> > -
> > -        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
> > -            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
> > -            break
> > -        fi
> > -
> > -    done
> > -    if [ ! -r "$VSFTP_CONF" ] ; then
> > -        end_testcase "vsftpd.conf not found."
> > -    fi
> > -    ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
> > -    if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
> > -        ANONYMOUS_ENABLE="YES"
> > -    fi
> > +	exists expect ftp vsftpd
> > +	TEST_USER="anonymous"
> > +	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
> > +	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
> > +	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
> > +	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
> > +	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
> >   }
> >   
> > -#-----------------------------------------------------------------------
> > -# FUNCTION   : do_test
> > -#
> > -# DESCRIPTION: The anonymous user will ftp in and create a directory in his/her
> > -#              home directory on the remote host.
> > -#-----------------------------------------------------------------------
> > -
> >   do_test()
> >   {
> > -    tst_resm TINFO "Ftp into a remote host as anonymous user; ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
> > +	echo "Ftp into a remote host as anonymous user;"
> > +	echo "ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
> >   
> > -    if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
> > -        expect -c "
> > -            spawn ftp $RHOST
> > -            sleep 1
> > -            expect -re \": \"
> > -            send \"$TEST_USER\r\"
> > -            expect -re \"Password:\"
> > -            send \"$TEST_USER_PASSWD\r\"
> > -            expect {
> > -                # 530 - Login failed
> > -                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
> > -                # 230 - Login successful
> > -                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
> > -            }
> > -            expect \"ftp> \"
> > -            send \"quit\r\"
> > +	if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
> > +	expect -c "
> > +		spawn ftp $RHOST
> > +		sleep 1
> > +		expect -re \": \"
> > +		send \"$TEST_USER\r\"
> > +		expect -re \"Password:\"
> > +		send \"$TEST_USER_PASSWD\r\"
> > +		expect {
> > +			# 530 - Login failed
> > +			\"530\" {send_user \"$FAIL_530\n\";exit 1}
> > +			# 230 - Login successful
> > +			\"230\" {send_user \"$PASS_230\n\";exit 0}
> > +		}
> > +		expect \"ftp> \"
> > +		send \"quit\r\"
> >   	"
> > -    else
> > -        expect -c "
> > -            spawn ftp $RHOST
> > -            sleep 1
> > -            expect -re \": \"
> > -            send \"$TEST_USER\r\"
> > -            expect -re \"Password:\"
> > -            send \"$TEST_USER_PASSWD\r\"
> > -            expect {
> > -                # 230 - Login successful
> > -                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
> > -                # 500 - Login failed
> > -                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> > -                # 530 - Login failed
> > -                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
> > -            }
> > -            expect \"ftp> \"
> > -            send \"quit\r\"
> > -        "
> > -    fi
> > -
> > -    [ $? -eq 0 ] || end_testcase "Testcase failed."
> > +	else
> > +	expect -c "
> > +		spawn ftp $RHOST
> > +		sleep 1
> > +		expect -re \": \"
> > +		send \"$TEST_USER\r\"
> > +		expect -re \"Password:\"
> > +		send \"$TEST_USER_PASSWD\r\"
> > +		expect {
> > +			# 230 - Login successful
> > +			\"230\" {send_user \"$FAIL_230\n\";exit 1}
> > +			# 500 - Login failed
> > +			\"500\" {send_user \"$PASS_500\n\";exit 0}
> > +			# 530 - Login failed
> > +			\"530\" {send_user \"$PASS_530\n\";exit 0}
> > +		}
> > +		expect \"ftp> \"
> > +		send \"quit\r\"
> > +	"
> > +	fi
> >   
> > +	if [ $? -ne 0 ]; then
> > +		tst_exit TBROK "Testcase failed."
> 
> There is tst_brkm library function for that purpose, it includes tst_exit.
> 

I mean to delete these codes but I forgot, the returned value will be
checked in the main function not here.

> > +	fi
> >   }
> >   
> > -#----------------------------------------------------------------------
> > -# FUNCTION: MAIN
> > -# PURPOSE:  To invoke the functions to perform the tasks described in
> > -#           the prologue.
> > -#----------------------------------------------------------------------
> > -. net_cmdlib.sh
> > +TCID="$0"
> > +TST_TOTAL=1
> >   
> > -read_opts $*
> > +. test.sh
> > +. ftp_setup
> > +
> > +setup
> >   do_setup
> > +#TEST_USER_PASSWD="noone@nowhere.com"
> > +
> >   do_test
> > -end_testcase
> > +ret=$?
> > +if [ $ret -ne 0 ]; then
> > +	tst_resm TFAIL "Test $TCID FAIL"
> > +else
> > +	tst_resm TPASS "Test $TCID PASS"
> > +fi
> > +
> > +tst_exit
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp_set_passwd b/testcases/network/tcp_cmds/ftp/ftp_set_passwd
> > deleted file mode 100755
> > index 7c275c9..0000000
> > --- a/testcases/network/tcp_cmds/ftp/ftp_set_passwd
> > +++ /dev/null
> > @@ -1,28 +0,0 @@
> > -#!/usr/bin/expect
> > -#
> > -# Set Password for a specific new user
> > -# This script should be run as 'root'
> > -#
> > -# Example:
> > -#		./set_passwd USER PASSWD
> > -#
> > -
> > -if { [llength $argv] < 2} {
> > -    exit 1
> > -}
> > -
> > -set USER [lindex $argv 0]
> > -set PASSWD [lindex $argv 1]
> > -
> > -set timeout 30
> > -
> > -spawn passwd $USER
> > -expect "Enter new password: "
> > -sleep 1
> > -exp_send "$PASSWD\r"
> > -expect "Re-type new password: "
> > -sleep 1
> > -exp_send "$PASSWD\r"
> > -expect success
> > -
> > -exit 0
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup b/testcases/network/tcp_cmds/ftp/ftp_setup
> > new file mode 100644
> > index 0000000..7100736
> > --- /dev/null
> > +++ b/testcases/network/tcp_cmds/ftp/ftp_setup
> > @@ -0,0 +1,82 @@
> > +#!/bin/sh
> > +###############################################################################
> > +## Copyright (c) International Business Machines  Corp., 2003                ##
> > +##                                                                           ##
> > +## This program is free software;  you can redistribute it and/or modify     ##
> > +## it under the terms of the GNU General Public License as published by      ##
> > +## the Free Software Foundation; either version 2 of the License, or         ##
> > +## (at your option) any later version.                                       ##
> > +##                                                                           ##
> > +## This program is distributed in the hope that it will be useful,           ##
> > +## but WITHOUT ANY WARRANTY;  without even the implied warranty of           ##
> > +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                 ##
> > +## the GNU General Public License for more details.                          ##
> > +##                                                                           ##
> > +## You should have received a copy of the GNU General Public License         ##
> > +## along with this program;  if not, write to the Free Software Foundation,  ##
> > +## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          ##
> > +##                                                                           ##
> > +###############################################################################
> > +
> > +exists()
> > +{
> > +	for cmd in $*; do
> > +		if ! command -v $cmd > /dev/null 2>&1; then
> > +			tst_brkm TBROK "$cmd: command not found"
> > +		fi
> > +	done
> > +}
> 
> tst_check_cmd() replaces it.
> 

Got it.

> > +
> > +do_setup()
> > +{
> > +
> > +	export RHOST="localhost"
> > +	export TEST_USER_PASSWD="eal"
> > +	export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
> > +	export TEST_USER_HOMEDIR="/home/$TEST_USER"
> > +
> > +	for vsftp_confdir in /etc/vsftpd /etc; do
> > +		if [ -r "$vsftp_confdir/vsftpd.conf" ]; then
> > +			VSFTP_CONF="$vsftp_confdir/vsftpd.conf"
> > +			break
> > +		fi
> > +	done
> > +	if [ ! -r "$VSFTP_CONF" ] ; then
> > +		tst_brkm TBROK "vsftpd.conf not found."
> > +	fi
> > +
> > +	LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
> > +	if [ "$LOCAL_ENABLE" != "YES" ]; then
> > +		LOCAL_ENABLE="NO"
> > +	fi
> > +
> > +	ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
> > +	if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
> > +		ANONYMOUS_ENABLE="YES"
> > +	fi
> > +
> > +	if [ $TEST_USER = "root" -o $TEST_USER = "anonymous" ]; then
> > +		return
> > +	fi
> > +
> > +	userdel -r $TEST_USER
> > +	sleep 1
> > +
> > +	if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
> > +		tst_brkm TBROK "Could not add test user $TEST_USER to system $RHOST."
> > +	fi
> > +
> > +	# create users home diretory (SLES 8 does not do this, even when specified
> > +	# in adduser)
> > +	USER_UID=$(id -u $TEST_USER)
> > +	USER_GID=$(id -g $TEST_USER)
> > +	mkdir -p "$TEST_USER_HOMEDIR"
> > +	chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
> > +}
> > +
> > +do_cleanup()
> > +{
> > +	if [ $TEST_USER != "root" -a $TEST_USER != "anonymous" ]; then
> > +		userdel -r $TEST_USER
> > +	fi
> > +}
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf b/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
> > deleted file mode 100755
> > index 7e496f6..0000000
> > --- a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
> > +++ /dev/null
> > @@ -1,5 +0,0 @@
> > -#!/bin/sh
> > -
> > -grep -v "local_enable" /etc/vsftpd.conf > /tmp/vsftpd.conf
> > -mv -f /tmp/vsftpd.conf /etc/vsftpd.conf
> > -echo "local_enable=YES" >> /etc/vsftpd.conf
> 
> Also, the same comments apply to the 2nd ssh patch.
> 

Got it.
And thank you.

Best regards,
Zeng

> Thanks,
> Alexey
> 



------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 1/2] network ftp: some cleanup
  2014-07-31 11:55 ` [LTP] [PATCH 1/2] network ftp: " Alexey
  2014-08-01  1:25   ` Zeng Linggang
@ 2014-08-01  3:11   ` Zeng Linggang
  2014-08-01 13:23     ` Alexey Kodanev
  2014-08-01  3:12   ` [LTP] [PATCH v2 2/2] network ssh: " Zeng Linggang
  2 siblings, 1 reply; 8+ messages in thread
From: Zeng Linggang @ 2014-08-01  3:11 UTC (permalink / raw)
  To: Alexey; +Cc: ltp-list

* Move do_setup and do_cleanup into ftp_setup.

* Delete ftp02_s1 and add do_test function for it.

* Delete ftp_set_passwd and ftp_setup_vsftp_conf, since they are not be used.

* Use test.sh instead of net_cmdlib.sh

* Abandon trap and use tst_exit.

* Make the test like:
	(set TCID TST_TOTAL ...)
	setup
	do_test
	check_result
	tst_exit

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/tcp_cmds/ftp/ftp02               |  99 +++++++-----
 testcases/network/tcp_cmds/ftp/ftp02_s1            |  71 ---------
 testcases/network/tcp_cmds/ftp/ftp03               | 175 +++++++--------------
 testcases/network/tcp_cmds/ftp/ftp04               | 109 ++++++-------
 testcases/network/tcp_cmds/ftp/ftp05               | 146 ++++++++---------
 testcases/network/tcp_cmds/ftp/ftp_set_passwd      |  28 ----
 testcases/network/tcp_cmds/ftp/ftp_setup           |  73 +++++++++
 .../network/tcp_cmds/ftp/ftp_setup_vsftp_conf      |   5 -
 8 files changed, 304 insertions(+), 402 deletions(-)
 delete mode 100755 testcases/network/tcp_cmds/ftp/ftp02_s1
 delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_set_passwd
 create mode 100644 testcases/network/tcp_cmds/ftp/ftp_setup
 delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf

diff --git a/testcases/network/tcp_cmds/ftp/ftp02 b/testcases/network/tcp_cmds/ftp/ftp02
index 6d6e021..bb3139e 100755
--- a/testcases/network/tcp_cmds/ftp/ftp02
+++ b/testcases/network/tcp_cmds/ftp/ftp02
@@ -28,59 +28,72 @@
 #  NOTE:
 #       This version is intended for EAL certification, it will need modification
 #       to conform with LTP standards in the offical LTP tree.
+#
+# DESCRIPTION:
+#	Create Test User
+#	Make sure test user cannont log in with invalid password
+#	Cleanup Test User from system
+#	Exit with exit code of script called upon
+#
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
+	tst_check_cmds expect ftp useradd userdel
+	export TEST_USER="ftpuser2"
+}
 
-    export RHOST="localhost"
-    export TEST_USER="ftpuser2"
-    export TEST_USER_PASSWD="eal"
-    export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    # erase user if he may exist, so we can have a clean env
-    TCtmp="/home/$TEST_USER"
-
-    tst_setup
+do_test()
+{
+	CONNECTION_FAILED="Connection failed; test FAILED"
+	EXPECTED="Login failed as expected; test PASSED"
+	UNEXPECTED="Login succeeded unexpectedly; test FAILED"
 
-    exists expect ftp ftp02_s1 useradd userdel
+	set PASSWD "invaild_password?!!"
+	set timeout 90
 
-    userdel $TEST_USER
-    sleep 1
+	expect -c "
+		#ftp to host
+		spawn ftp $RHOST
+		sleep 1
+		# Check if connection succeeded.
+		expect {
+			\"Name\" {}
+			timeout {send_user \"\n$CONNECTION_FAILED\n\";exit 1}
+		}
 
-    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
+		send \"$RUSER\r\"
+		sleep 1
+		expect -re \"Password:\"
+		send \"$PASSWD\r\"
+		sleep 1
 
-    trap do_cleanup EXIT
+		expect {
+			# 530 - Login failed
+			\"530\" {send_user \"$EXPECTED\n\";exit 0}
+			# 230 - Login successful
+			\"230\" {send_user \"$UNEXPECTED\n\"; exit 1}
+		}
 
+		expect \"ftp>\"
+		send \"exit\r\"
+	"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel $TEST_USER
-    tst_cleanup
-}
-
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#              Call upon script to make sure test user cannont log in with invalid password
-#	       Cleanup Test User from system
-#              Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
+. test.sh
+. ftp_setup
 
-read_opts $*
+setup
 do_setup
-ftp02_s1 || end_testcase "Testcase failed."
-end_testcase
+TST_CLEANUP=do_cleanup
+
+do_test
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp02_s1 b/testcases/network/tcp_cmds/ftp/ftp02_s1
deleted file mode 100755
index 18b08da..0000000
--- a/testcases/network/tcp_cmds/ftp/ftp02_s1
+++ /dev/null
@@ -1,71 +0,0 @@
-#! /usr/bin/expect -f
-#*********************************************************************
-#   Copyright (c) International Business Machines  Corp., 2003, 2005
-#
-#   This program is free software;  you can redistribute it and/or modify
-#   it under the terms of the GNU General Public License as published by
-#   the Free Software Foundation; either version 2 of the License, or
-#   (at your option) any later version.
-#
-#   This program is distributed in the hope that it will be useful,
-#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#   the GNU General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public License
-#   along with this program;  if not, write to the Free Software
-#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-#
-#
-#  FILE   : ftp
-#
-#  PURPOSE: Test to see if ftp rejects a user with an invalid password
-#
-#  SETUP: The program `/usr/bin/expect' MUST be installed.
-#
-#  HISTORY:
-# 	03/04/03 Jerone Young (jeroney@us.ibm.com)
-#       09/21/05 Kris Wilson (krisw@us.ibm.com) Check for connection failure.
-#                (If WS system, no vsftpd; connection will fail.)
-
-set RHOST $env(RHOST)
-set TEST_USER $env(TEST_USER)
-set TEST_USER_PASSWD $env(TEST_USER_PASSWD)
-set TEST_USER_HOMEDIR $env(TEST_USER_HOMEDIR)
-
-#RUSER
-set RUSER $TEST_USER
-
-#set PASSWD to be an invalid Password
-set PASSWD "invaild_password?!!"
-
-set timeout 90
-
-#ftp to host
-spawn ftp $RHOST
-sleep 1
-# Check if connection succeeded.
-expect {
-    "Name" {}
-    timeout {send_user "\nConnection failed; test FAILED\n";exit 1}
-}
-
-send "$RUSER\r"
-sleep 1
-expect -re "Password:"
-send "$PASSWD\r"
-sleep 1
-
-expect {
-    # 530 - Login failed
-    "530" {send_user "Login failed as expected; test PASSED\n"}
-    # 230 - Login successful
-    "230" {send_user "Login succeeded unexpectedly; test FAILED\n"; exit 1}
-}
-
-expect "ftp>"
-send "exit\r"
-
-send_user "\nTest Successful\n\n"
-exit 0
diff --git a/testcases/network/tcp_cmds/ftp/ftp03 b/testcases/network/tcp_cmds/ftp/ftp03
index a99a1a0..5d0d1c6 100755
--- a/testcases/network/tcp_cmds/ftp/ftp03
+++ b/testcases/network/tcp_cmds/ftp/ftp03
@@ -31,130 +31,77 @@
 #	This version is intended for EAL certification, it will need modification
 #	to conform with LTP standards in the offical LTP tree.
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-
-    RHOST="localhost"
-    TEST_USER="ftpuser1"
-    TCtmp=/home/$TEST_USER
-    TEST_USER_PASSWD="eal"
-    TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
-    TEST_USER_HOMEDIR="/home/$TEST_USER"
-    VSFTP_CONF=
-
-    tst_setup
-
-    exists ftp useradd userdel vftpd
-
-    for vsftp_conf in /etc/vsftpd /etc; do
-
-        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
-            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
-            break
-        fi
-
-    done
-    if [ ! -r "$VSFTP_CONF" ] ; then
-        end_testcase "vsftpd.conf not found."
-    fi
-    LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
-
-    [ "$LOCAL_ENABLE" != "YES" ] && LOCAL_ENABLE="NO"
-
-    userdel $TEST_USER
-    sleep 1
-
-    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER on system $RHOST."
-    fi
-
-    trap do_cleanup QUIT
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    USER_UID=$(id -u $TEST_USER)
-    USER_GID=$(id -g $TEST_USER)
-    mkdir -p "$TEST_USER_HOMEDIR"
-    chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
-
+	tst_check_cmds ftp useradd userdel vsftpd
+	export TEST_USER="ftpuser3"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
-
-do_cleanup()
+do_test()
 {
-    userdel $TEST_USER
-    tst_cleanup
-}
+	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
+	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
+	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
+	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
+	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_test
-#
-# DESCRIPTION: The test user will ftp in and create a directory in his home directory on the remote host.
-#              The directory is then checked on the remote hosts to see if it is owned
-#	       by the test user.
-#-----------------------------------------------------------------------
-
-do_test(){
-    tst_resm TINFO "TEST: Ftp into a remote host as a local user (other than root), LOCAL_ENABLE=$LOCAL_ENABLE"
+	echo "TEST: Ftp into a remote host as a local user (other than root),"
+	echo "LOCAL_ENABLE=$LOCAL_ENABLE"
 
-    if [ "$LOCAL_ENABLE" = "YES" ]; then
+	if [ "$LOCAL_ENABLE" = "YES" ]; then
 	expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 530 - Login failed
+			\"530\" {send_user \"$FAIL_530\n\";exit 1}
+			# 230 - Login successful
+			\"230\" {send_user \"$PASS_230\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
 	"
-    else
-        expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
-                # 500 - Login failed
-                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
-        "
-    fi
-
-    if [ $? != 0 ]; then
-        end_testcase "Testcase failed"
-    fi
+	else
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 230 - Login successful
+			\"230\" {send_user \"$FAIL_230\n\";exit 1}
+			# 500 - Login failed
+			\"500\" {send_user \"$PASS_500\n\";exit 0}
+			# 530 - Login failed
+			\"530\" {send_user \"$PASS_530\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
+	"
+	fi
 }
 
-#----------------------------------------------------------------------
-# FUNCTION: MAIN
-# PURPOSE:  To invoke the functions to perform the tasks described in
-#           the prologue.
-#----------------------------------------------------------------------
-. net_cmdlib.sh
+TCID="$0"
+TST_TOTAL=1
+
+. test.sh
+. ftp_setup
 
-read_opts $*
+setup
 do_setup
+TST_CLEANUP=do_cleanup
+
 do_test
-end_testcase
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp04 b/testcases/network/tcp_cmds/ftp/ftp04
index 8329eb0..f3625d3 100755
--- a/testcases/network/tcp_cmds/ftp/ftp04
+++ b/testcases/network/tcp_cmds/ftp/ftp04
@@ -28,77 +28,64 @@
 #   03/04/03 Jerone Young (jeroney@us.ibm.com)
 #   09/21/05 Kris Wilson (krisw@us.ibm.com) Check if vsftpd is on system.
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
+	tst_check_cmds awk expect ftp vsftpd
 
-    tvar=${MACHTYPE%-*}
-    tvar=${tvar#*-}
-
-    RHOST=localhost
-    TEST_USER=root
-
-    tst_setup
+	TEST_USER=root
 
-    if [ -n "$PASSWD" ]; then
-        TEST_USER_PASSWORD=$PASSWD
-    else
-        end_testcase "You must set your password via the PASSWD variable."
-        exit 1
-    fi
-
-    exists awk expect ftp vsftpd
-
-    if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
-        echo "Verifying test user $TEST_USER is in /etc/vsftpd.ftpusers database..."
-        FTPUSERS=$(awk "/$TEST_USER/" /etc/vsftpd.ftpusers)
-    else
-        echo "Verifying test user $TEST_USER is in /etc/ftpusers database..."
-        FTPUSERS=$(awk "/$TEST_USER/" /etc/ftpusers)
-    fi
-    if [ -z "$FTPUSERS" ] ; then
-        end_testcase "Test user $TEST_USER not found in /etc/ftpusers unable to run TEST, exiting 0 ..."
-    fi
+	tvar=${MACHTYPE%-*}
+	tvar=${tvar#*-}
 
+	if [ $tvar = "redhat" -o $tvar = "redhat-linux" ]; then
+		ftpusers="/etc/vsftpd/ftpusers"
+	else
+		ftpusers="/etc/ftpusers"
+	fi
+	echo "Verifying test user $TEST_USER is in ${ftpusers} database..."
+	FTPUSERS=$(awk "/$TEST_USER/" ${ftpusers})
+	if [ -z "$FTPUSERS" ] ; then
+		tst_brkm TBROK "$TEST_USER not found in $ftpusers exiting 0 ..."
+	fi
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_test
-#-----------------------------------------------------------------------
 do_test()
 {
-
-    tst_resm TINFO "Ftp should reject $TEST_USER from loging in successfully"
-    expect -c "
-        spawn ftp $RHOST
-        sleep 1
-        expect -re \": \"
-        send \"$TEST_USER\r\"
-        expect -re \"Password:\"
-        send \"$TEST_USER_PASSWD\r\"
-        expect {
-            # 230 - Login successful
-            \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
-            # 530 - Login failed
-            \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-        }
-        expect \"ftp> \"
-        send \"quit\r\"
-    "
-
-    [ $? -eq 0 ] || end_testcase "Testcase failed."
-
+	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
+	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
+	echo "Ftp should reject $TEST_USER from loging in successfully"
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 230 - Login successful
+			\"230\" {send_user \"$FAIL_230\n\";exit 1}
+			# 530 - Login failed
+			\"530\" {send_user \"$PASS_530\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
+	"
 }
 
-#----------------------------------------------------------------------
-# FUNCTION: MAIN
-#----------------------------------------------------------------------
-. net_cmdlib.sh
+TCID="$0"
+TST_TOTAL=1
+
+. test.sh
+. ftp_setup
 
-read_opts $*
+setup
 do_setup
+
 do_test
-end_testcase
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp05 b/testcases/network/tcp_cmds/ftp/ftp05
index 4f91334..fcad182 100755
--- a/testcases/network/tcp_cmds/ftp/ftp05
+++ b/testcases/network/tcp_cmds/ftp/ftp05
@@ -30,96 +30,82 @@
 #  NOTE:
 #	This version is intended for EAL certification, it will need modification
 #	to conform with LTP standards in the offical LTP tree.
+#
+# DESCRIPTION:
+#	The anonymous user will ftp in and create a directory in his/her
+#	home directory on the remote host.
+#
 
-do_setup()
+setup()
 {
-    RHOST="localhost"
-    TEST_USER="anonymous"
-    TEST_USER_PASSWD="noone@nowhere.com"
-    VSFTP_CONF=
-
-    tst_setup
-
-    exists expect ftp vsftpd
-
-    for vsftp_conf in /etc/vsftpd /etc; do
-
-        if [ -r "$vsftp_confdir/vsftp.conf" ]; then
-            VSFTP_CONF="$vsftp_confdir/vsftp.conf"
-            break
-        fi
-
-    done
-    if [ ! -r "$VSFTP_CONF" ] ; then
-        end_testcase "vsftpd.conf not found."
-    fi
-    ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
-    if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
-        ANONYMOUS_ENABLE="YES"
-    fi
+	tst_check_cmds expect ftp vsftpd
+	TEST_USER="anonymous"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION   : do_test
-#
-# DESCRIPTION: The anonymous user will ftp in and create a directory in his/her
-#              home directory on the remote host.
-#-----------------------------------------------------------------------
-
 do_test()
 {
-    tst_resm TINFO "Ftp into a remote host as anonymous user; ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
-
-    if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
-        expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : FAIL (ftp rejected login attempt)\n\";exit 1}
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : PASS (ftp allowed login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
-	"
-    else
-        expect -c "
-            spawn ftp $RHOST
-            sleep 1
-            expect -re \": \"
-            send \"$TEST_USER\r\"
-            expect -re \"Password:\"
-            send \"$TEST_USER_PASSWD\r\"
-            expect {
-                # 230 - Login successful
-                \"230\" {send_user \"==> TEST \#$TEST : FAIL (ftp allowed login attempt)\n\";exit 1}
-                # 500 - Login failed
-                \"500\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-                # 530 - Login failed
-                \"530\" {send_user \"==> TEST \#$TEST : PASS (ftp rejected login attempt)\n\";exit 0}
-            }
-            expect \"ftp> \"
-            send \"quit\r\"
-        "
-    fi
+	FAIL_530="==> TEST : FAIL (ftp rejected login attempt)"
+	PASS_230="==> TEST : PASS (ftp allowed login attempt)"
+	FAIL_230="==> TEST : FAIL (ftp allowed login attempt)"
+	PASS_500="==> TEST : PASS (ftp rejected login attempt)"
+	PASS_530="==> TEST : PASS (ftp rejected login attempt)"
 
-    [ $? -eq 0 ] || end_testcase "Testcase failed."
+	echo "Ftp into a remote host as anonymous user;"
+	echo "ANONYMOUS_ENABLE=$ANONYMOUS_ENABLE"
 
+	if [ "$ANONYMOUS_ENABLE" = "YES" ]; then
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 530 - Login failed
+			\"530\" {send_user \"$FAIL_530\n\";exit 1}
+			# 230 - Login successful
+			\"230\" {send_user \"$PASS_230\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
+	"
+	else
+	expect -c "
+		spawn ftp $RHOST
+		sleep 1
+		expect -re \": \"
+		send \"$TEST_USER\r\"
+		expect -re \"Password:\"
+		send \"$TEST_USER_PASSWD\r\"
+		expect {
+			# 230 - Login successful
+			\"230\" {send_user \"$FAIL_230\n\";exit 1}
+			# 500 - Login failed
+			\"500\" {send_user \"$PASS_500\n\";exit 0}
+			# 530 - Login failed
+			\"530\" {send_user \"$PASS_530\n\";exit 0}
+		}
+		expect \"ftp> \"
+		send \"quit\r\"
+	"
+	fi
 }
 
-#----------------------------------------------------------------------
-# FUNCTION: MAIN
-# PURPOSE:  To invoke the functions to perform the tasks described in
-#           the prologue.
-#----------------------------------------------------------------------
-. net_cmdlib.sh
+TCID="$0"
+TST_TOTAL=1
+
+. test.sh
+. ftp_setup
 
-read_opts $*
+setup
 do_setup
+
 do_test
-end_testcase
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ftp/ftp_set_passwd b/testcases/network/tcp_cmds/ftp/ftp_set_passwd
deleted file mode 100755
index 7c275c9..0000000
--- a/testcases/network/tcp_cmds/ftp/ftp_set_passwd
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/expect
-#
-# Set Password for a specific new user
-# This script should be run as 'root'
-#
-# Example:
-#		./set_passwd USER PASSWD
-#
-
-if { [llength $argv] < 2} {
-    exit 1
-}
-
-set USER [lindex $argv 0]
-set PASSWD [lindex $argv 1]
-
-set timeout 30
-
-spawn passwd $USER
-expect "Enter new password: "
-sleep 1
-exp_send "$PASSWD\r"
-expect "Re-type new password: "
-sleep 1
-exp_send "$PASSWD\r"
-expect success
-
-exit 0
diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup b/testcases/network/tcp_cmds/ftp/ftp_setup
new file mode 100644
index 0000000..b7449ec
--- /dev/null
+++ b/testcases/network/tcp_cmds/ftp/ftp_setup
@@ -0,0 +1,73 @@
+#!/bin/sh
+###############################################################################
+## Copyright (c) International Business Machines  Corp., 2003                ##
+##                                                                           ##
+## This program is free software;  you can redistribute it and/or modify     ##
+## it under the terms of the GNU General Public License as published by      ##
+## the Free Software Foundation; either version 2 of the License, or         ##
+## (at your option) any later version.                                       ##
+##                                                                           ##
+## This program is distributed in the hope that it will be useful,           ##
+## but WITHOUT ANY WARRANTY;  without even the implied warranty of           ##
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                 ##
+## the GNU General Public License for more details.                          ##
+##                                                                           ##
+## You should have received a copy of the GNU General Public License         ##
+## along with this program;  if not, write to the Free Software Foundation,  ##
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          ##
+##                                                                           ##
+###############################################################################
+
+do_setup()
+{
+
+	export RHOST="localhost"
+	export TEST_USER_PASSWD="eal"
+	export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
+	export TEST_USER_HOMEDIR="/home/$TEST_USER"
+
+	for vsftp_confdir in /etc/vsftpd /etc; do
+		if [ -r "$vsftp_confdir/vsftpd.conf" ]; then
+			VSFTP_CONF="$vsftp_confdir/vsftpd.conf"
+			break
+		fi
+	done
+	if [ ! -r "$VSFTP_CONF" ] ; then
+		tst_brkm TBROK "vsftpd.conf not found."
+	fi
+
+	LOCAL_ENABLE=$(awk -F= '/^local_enable=/ {print $2}' "$VSFTP_CONF")
+	if [ "$LOCAL_ENABLE" != "YES" ]; then
+		LOCAL_ENABLE="NO"
+	fi
+
+	ANONYMOUS_ENABLE=$(awk -F= '/^anonymous_enable=/ {print $2}' "$VSFTP_CONF")
+	if [ "$ANONYMOUS_ENABLE" != "NO" ]; then
+		ANONYMOUS_ENABLE="YES"
+	fi
+
+	if [ $TEST_USER = "root" -o $TEST_USER = "anonymous" ]; then
+		return
+	fi
+
+	userdel -r $TEST_USER
+	sleep 1
+
+	if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
+		tst_brkm TBROK "Could not add test user $TEST_USER to system $RHOST."
+	fi
+
+	# create users home diretory (SLES 8 does not do this, even when specified
+	# in adduser)
+	USER_UID=$(id -u $TEST_USER)
+	USER_GID=$(id -g $TEST_USER)
+	mkdir -p "$TEST_USER_HOMEDIR"
+	chown -R $USER_UID:$USER_GID $TEST_USER_HOMEDIR
+}
+
+do_cleanup()
+{
+	if [ $TEST_USER != "root" -a $TEST_USER != "anonymous" ]; then
+		userdel -r $TEST_USER
+	fi
+}
diff --git a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf b/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
deleted file mode 100755
index 7e496f6..0000000
--- a/testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-grep -v "local_enable" /etc/vsftpd.conf > /tmp/vsftpd.conf
-mv -f /tmp/vsftpd.conf /etc/vsftpd.conf
-echo "local_enable=YES" >> /etc/vsftpd.conf
-- 
1.9.3




------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v2 2/2] network ssh: some cleanup
  2014-07-31 11:55 ` [LTP] [PATCH 1/2] network ftp: " Alexey
  2014-08-01  1:25   ` Zeng Linggang
  2014-08-01  3:11   ` [LTP] [PATCH v2 " Zeng Linggang
@ 2014-08-01  3:12   ` Zeng Linggang
  2 siblings, 0 replies; 8+ messages in thread
From: Zeng Linggang @ 2014-08-01  3:12 UTC (permalink / raw)
  To: Alexey; +Cc: ltp-list

* Move do_setup and do_cleanup into the file of ssh_setup.

* Use test.sh instead of net_cmdlib.sh

* Abandon trap and use tst_exit.

* Make the test like:
	(set TCID TST_TOTAL ...)
	setup
	do_test
	check_result
	tst_exit

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/tcp_cmds/ssh/ssh01     | 82 +++++++++-----------------------
 testcases/network/tcp_cmds/ssh/ssh01_s1  | 36 ++++++++------
 testcases/network/tcp_cmds/ssh/ssh02     | 82 +++++++++-----------------------
 testcases/network/tcp_cmds/ssh/ssh02_s1  | 36 ++++++++------
 testcases/network/tcp_cmds/ssh/ssh03     | 77 +++++++-----------------------
 testcases/network/tcp_cmds/ssh/ssh03_s1  | 36 +++++++-------
 testcases/network/tcp_cmds/ssh/ssh_setup | 54 +++++++++++++++++++++
 7 files changed, 180 insertions(+), 223 deletions(-)
 create mode 100755 testcases/network/tcp_cmds/ssh/ssh_setup

diff --git a/testcases/network/tcp_cmds/ssh/ssh01 b/testcases/network/tcp_cmds/ssh/ssh01
index a0c66f5..28ae11a 100755
--- a/testcases/network/tcp_cmds/ssh/ssh01
+++ b/testcases/network/tcp_cmds/ssh/ssh01
@@ -25,69 +25,33 @@
 #  HISTORY:
 #    03/03 Jerone Young (jeroney@us.ibm.com)
 #
+# DESCRIPTION:
+#	Create test user
+#	Make sure test user can't login with invalid password
+#	Cleanup test user from system
+#	Exit with exit code of script called upon
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-    export RHOST="localhost"
-    export TEST_USER="ssh_usr1"
-    export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    exists expect ssh ssh01_s1 useradd userdel
-
-    trap do_cleanup EXIT
-
-    # erase user if he/she already exists, so we can have a clean env
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    sleep 1
-
-    tst_setup
-
-    if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
-
-    echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    if [ ! -d "$TEST_USER_HOMEDIR" ]; then
-        USER_UID=$(id -u $TEST_USER)
-        USER_GID=$(id -g $TEST_USER)
-        if ! mkdir -p "$TEST_USER_HOMEDIR"; then
-            end_testcase "Failed to create $TEST_USER_HOMEDIR"
-        fi
-        chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
-    fi
+	tst_check_cmds ssh01_s1
+	export TEST_USER="ssh_usr1"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    tst_cleanup
-}
+. test.sh
+. ssh_setup
 
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#          Call upon script to make sure test user cannont log in with invalid password
-#          Cleanup Test User from system
-#          Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
+setup
 do_setup
-ssh01_s1 || end_testcase "Testcase failed"
-do_cleanup
+TST_CLEANUP=do_cleanup
+
+ssh01_s1
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ssh/ssh01_s1 b/testcases/network/tcp_cmds/ssh/ssh01_s1
index c1cc127..ab86e2a 100755
--- a/testcases/network/tcp_cmds/ssh/ssh01_s1
+++ b/testcases/network/tcp_cmds/ssh/ssh01_s1
@@ -45,22 +45,28 @@ set PASSWD "invalid_password!"
 spawn ssh -l $RUSER $RHOST whoami
 
 while 1 {
-    sleep 2
-    expect {
+	sleep 2
+	expect {
 
-        "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\r"}
-        "assword:" {exp_send "$PASSWD\r"}
-        -re "Permission denied (.*)\." {
-            send_user "SSH would not allow $RUSER to login with invalid password, Test Passed \n"
-            send_user "\nTEST_PASSED\n"
-            exit 0
-        }
-        "$RUSER" {
-            send_user "SSH allowed $RUSER to login with invalid pass, Test Failed \n"
-            exit 1
-        }
-    }
-    sleep 1
+		"Are you sure you want to continue connecting (yes/no)?" {
+			exp_send "yes\r"
+		}
+		"assword:" {
+			exp_send "$PASSWD\r"
+		}
+		-re "Permission denied (.*)\." {
+			send_user "SSH would not allow $RUSER to login with\
+				   invalid password, Test Passed \n"
+			send_user "\nTEST_PASSED\n"
+			exit 0
+		}
+		"$RUSER" {
+			send_user "SSH allowed $RUSER to login with invalid\
+				   pass, Test Failed \n"
+			exit 1
+		}
+	}
+	sleep 1
 }
 
 exit 1
diff --git a/testcases/network/tcp_cmds/ssh/ssh02 b/testcases/network/tcp_cmds/ssh/ssh02
index 2d82acb..9bb44e6 100755
--- a/testcases/network/tcp_cmds/ssh/ssh02
+++ b/testcases/network/tcp_cmds/ssh/ssh02
@@ -25,69 +25,33 @@
 #  HISTORY:
 #    03/03 Jerone Young (jeroney@us.ibm.com)
 #
+# DESCRIPTION:
+#	Create Test User
+#	Make sure an invalid user can not have access
+#	Cleanup Test User from system
+#	Exit with exit code of script called upon
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-    export RHOST="localhost"
-    export TEST_USER="ssh_usr2"
-    export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    exists expect ssh ssh02_s1 useradd userdel
-
-    trap do_cleanup EXIT
-
-    # erase user if he/she already exists, so we can have a clean env
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    sleep 1
-
-    tst_setup
-
-    if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
-
-    echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    if [ ! -d "$TEST_USER_HOMEDIR" ]; then
-        USER_UID=$(id -u $TEST_USER)
-        USER_GID=$(id -g $TEST_USER)
-        if ! mkdir -p "$TEST_USER_HOMEDIR"; then
-            end_testcase "Failed to create $TEST_USER_HOMEDIR"
-        fi
-        chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
-    fi
+	tst_check_cmds ssh02_s1
+	export TEST_USER="ssh_usr2"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    tst_cleanup
-}
+. test.sh
+. ssh_setup
 
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#          Call upon script to make sure an invalid user can not have access
-#          Cleanup Test User from system
-#          Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
+setup
 do_setup
-ssh02_s1 || end_testcase "Testcase failed"
-do_cleanup
+TST_CLEANUP=do_cleanup
+
+ssh02_s1
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ssh/ssh02_s1 b/testcases/network/tcp_cmds/ssh/ssh02_s1
index d49e1e9..cf95709 100755
--- a/testcases/network/tcp_cmds/ssh/ssh02_s1
+++ b/testcases/network/tcp_cmds/ssh/ssh02_s1
@@ -46,22 +46,28 @@ set RUSER "Invaild_User"
 spawn ssh -l $RUSER $RHOST whoami
 
 while 1 {
-    sleep 2
-    expect {
+	sleep 2
+	expect {
 
-        "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\r"}
-        "assword:" {exp_send "$PASSWD\r"}
-        -re "Permission denied (.*)\." {
-            send_user "SSH would not allow $RUSER to login with invalid password, Test Passed \n"
-            send_user "\nTEST_PASSED\n"
-            exit 0
-        }
-        "$RUSER" {
-            send_user "SSH allowed $RUSER to login with invalid pass, Test Failed \n"
-            exit 1
-        }
-    }
-    sleep 1
+		"Are you sure you want to continue connecting (yes/no)?" {
+			exp_send "yes\r"
+		}
+		"assword:" {
+			exp_send "$PASSWD\r"
+		}
+		-re "Permission denied (.*)\." {
+			send_user "SSH would not allow $RUSER to login with\
+				   invalid password, Test Passed \n"
+			send_user "\nTEST_PASSED\n"
+			exit 0
+		}
+		"$RUSER" {
+			send_user "SSH allowed $RUSER to login with invalid\
+				   pass, Test Failed \n"
+			exit 1
+		}
+	}
+	sleep 1
 }
 
 exit 1
diff --git a/testcases/network/tcp_cmds/ssh/ssh03 b/testcases/network/tcp_cmds/ssh/ssh03
index 49b6527..a8d3cd9 100755
--- a/testcases/network/tcp_cmds/ssh/ssh03
+++ b/testcases/network/tcp_cmds/ssh/ssh03
@@ -26,68 +26,27 @@
 #    03/03 Jerone Young (jeroney@us.ibm.com)
 #
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_setup
-#-----------------------------------------------------------------------
-
-do_setup()
+setup()
 {
-    export RHOST="localhost"
-    export TEST_USER="ssh_usr3"
-    export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
-    export TEST_USER_HOMEDIR="/home/$TEST_USER"
-
-    exists expect ssh ssh03_s1 useradd userdel
-
-    trap do_cleanup EXIT
-
-    # erase user if he/she already exists, so we can have a clean env
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    sleep 1
-
-    tst_setup
-
-    if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
-        end_testcase "Could not add test user $TEST_USER to system $RHOST."
-    fi
-
-    echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
-
-    # create users home diretory (SLES 8 does not do this, even when specified
-    # in adduser)
-    if [ ! -d "$TEST_USER_HOMEDIR" ]; then
-        USER_UID=$(id -u $TEST_USER)
-        USER_GID=$(id -g $TEST_USER)
-        if ! mkdir -p "$TEST_USER_HOMEDIR"; then
-            end_testcase "Failed to create $TEST_USER_HOMEDIR"
-        fi
-        chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
-    fi
+	tst_check_cmds ssh03_s1
+	export TEST_USER="ssh_usr3"
 }
 
-#-----------------------------------------------------------------------
-# FUNCTION:  do_cleanup
-#-----------------------------------------------------------------------
+TCID="$0"
+TST_TOTAL=1
 
-do_cleanup()
-{
-    userdel -r $TEST_USER
-    [ -d "$TEST_USER_HOMEDIR" ] && rm -rf "$TEST_USER_HOMEDIR"
-    tst_cleanup
-}
+. test.sh
+. ssh_setup
 
-#-----------------------------------------------------------------------
-# FUNCTION:  MAIN
-#
-# DESCRIPTION: Create Test User
-#          Call upon script to make sure a valid user can have access
-#          Cleanup Test User from system
-#          Exit with exit code of script called upon
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
+setup
 do_setup
-ssh03_s1 || end_testcase "Testcase failed"
-do_cleanup
+TST_CLEANUP=do_cleanup
+
+ssh03_s1
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Test $TCID FAIL"
+else
+	tst_resm TPASS "Test $TCID PASS"
+fi
+
+tst_exit
diff --git a/testcases/network/tcp_cmds/ssh/ssh03_s1 b/testcases/network/tcp_cmds/ssh/ssh03_s1
index bf6aada..e3f8ceb 100755
--- a/testcases/network/tcp_cmds/ssh/ssh03_s1
+++ b/testcases/network/tcp_cmds/ssh/ssh03_s1
@@ -39,25 +39,29 @@ set timeout 90
 
 send_user "TEST: SSH allow (non-root) valid User \n"
 
-
 spawn ssh -l $RUSER $RHOST whoami
 
 while 1 {
-    sleep 2
-    expect {
-
-        "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\r"}
-        "assword:" {exp_send "$PASSWD\r"}
-        -re "Permission denied (.*)\." {
-            send_user "\nSSH would not allow $RUSER to login, Test FAILED \n"
-            exit 1
-        }
-        "$RUSER" {
-            send_user "SSH allowed $RUSER to login, Test PASSED \n"
-            exit 0
-        }
-    }
-    sleep 1
+	sleep 2
+	expect {
+
+		"Are you sure you want to continue connecting (yes/no)?" {
+			exp_send "yes\r"
+		}
+		"assword:" {
+			exp_send "$PASSWD\r"
+		}
+		-re "Permission denied (.*)\." {
+			send_user "\nSSH would not allow $RUSER to login, Test\
+				   FAILED \n"
+			exit 1
+		}
+		"$RUSER" {
+			send_user "SSH allowed $RUSER to login, Test PASSED \n"
+			exit 0
+		}
+	}
+	sleep 1
 }
 
 exit 1
diff --git a/testcases/network/tcp_cmds/ssh/ssh_setup b/testcases/network/tcp_cmds/ssh/ssh_setup
new file mode 100755
index 0000000..5a55dd8
--- /dev/null
+++ b/testcases/network/tcp_cmds/ssh/ssh_setup
@@ -0,0 +1,54 @@
+#!/bin/sh
+################################################################################
+## Copyright (c) International Business Machines  Corp., 2000                 ##
+##                                                                            ##
+## This program is free software;  you can redistribute it and/or modify      ##
+## it under the terms of the GNU General Public License as published by       ##
+## the Free Software Foundation; either version 2 of the License, or          ##
+## (at your option) any later version.                                        ##
+##                                                                            ##
+## This program is distributed in the hope that it will be useful,            ##
+## but WITHOUT ANY WARRANTY;  without even the implied warranty of            ##
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  ##
+## the GNU General Public License for more details.                           ##
+##                                                                            ##
+## You should have received a copy of the GNU General Public License          ##
+## along with this program;  if not, write to the Free Software Foundation,   ##
+## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
+##                                                                            ##
+################################################################################
+
+do_setup()
+{
+	export RHOST="localhost"
+	export TEST_USER_PASSWD="now_this_is_a_good_ltp_test_password"
+	export TEST_USER_HOMEDIR="/home/$TEST_USER"
+
+	tst_check_cmds expect ssh useradd userdel
+
+	# erase user if he/she already exists, so we can have a clean env
+	do_cleanup
+	sleep 1
+
+	if ! useradd -m -d "$TEST_USER_HOMEDIR" $TEST_USER; then
+		tst_brkm TBROK "Failed to add user $TEST_USER to system $RHOST."
+	fi
+
+	echo "$TEST_USER_PASSWD" | passwd --stdin $TEST_USER
+
+	# create users home diretory (SLES 8 does not do this, even when
+	# specified in adduser)
+	if [ ! -d "$TEST_USER_HOMEDIR" ]; then
+		USER_UID=$(id -u $TEST_USER)
+		USER_GID=$(id -g $TEST_USER)
+		if ! mkdir -p "$TEST_USER_HOMEDIR"; then
+			tst_brkm TBROK "Failed to create $TEST_USER_HOMEDIR"
+		fi
+		chown -Rf $USER_UID.$USER_GID "$TEST_USER_HOMEDIR"
+	fi
+}
+
+do_cleanup()
+{
+	userdel -r $TEST_USER 2> /dev/null
+}
-- 
1.9.3




------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH v2 1/2] network ftp: some cleanup
  2014-08-01  3:11   ` [LTP] [PATCH v2 " Zeng Linggang
@ 2014-08-01 13:23     ` Alexey Kodanev
  2014-09-25 10:56       ` Alexey Kodanev
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey Kodanev @ 2014-08-01 13:23 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi Zeng!
On 08/01/2014 07:11 AM, Zeng Linggang wrote:
> * Move do_setup and do_cleanup into ftp_setup.
>
> * Delete ftp02_s1 and add do_test function for it.
>
> * Delete ftp_set_passwd and ftp_setup_vsftp_conf, since they are not be used.
>
> * Use test.sh instead of net_cmdlib.sh
>
> * Abandon trap and use tst_exit.
>
> * Make the test like:
> 	(set TCID TST_TOTAL ...)
> 	setup
> 	do_test
> 	check_result
> 	tst_exit
>
> * Some cleanup.
>
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> ---
>   testcases/network/tcp_cmds/ftp/ftp02               |  99 +++++++-----
>   testcases/network/tcp_cmds/ftp/ftp02_s1            |  71 ---------
>   testcases/network/tcp_cmds/ftp/ftp03               | 175 +++++++--------------
>   testcases/network/tcp_cmds/ftp/ftp04               | 109 ++++++-------
>   testcases/network/tcp_cmds/ftp/ftp05               | 146 ++++++++---------
>   testcases/network/tcp_cmds/ftp/ftp_set_passwd      |  28 ----
>   testcases/network/tcp_cmds/ftp/ftp_setup           |  73 +++++++++
>   .../network/tcp_cmds/ftp/ftp_setup_vsftp_conf      |   5 -
>   8 files changed, 304 insertions(+), 402 deletions(-)
>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp02_s1
>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_set_passwd
>   create mode 100644 testcases/network/tcp_cmds/ftp/ftp_setup
>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
>
> diff --git a/testcases/network/tcp_cmds/ftp/ftp02 b/testcases/network/tcp_cmds/ftp/ftp02
> index 6d6e021..bb3139e 100755
> --- a/testcases/network/tcp_cmds/ftp/ftp02
> +++ b/testcases/network/tcp_cmds/ftp/ftp02
> @@ -28,59 +28,72 @@
>   #  NOTE:
>   #       This version is intended for EAL certification, it will need modification
>   #       to conform with LTP standards in the offical LTP tree.
> +#
> +# DESCRIPTION:
> +#	Create Test User
> +#	Make sure test user cannont log in with invalid password
> +#	Cleanup Test User from system
> +#	Exit with exit code of script called upon
> +#
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_setup
> -#-----------------------------------------------------------------------
> -
> -do_setup()
> +setup()
>   {
> +	tst_check_cmds expect ftp useradd userdel
> +	export TEST_USER="ftpuser2"
> +}
>   
> -    export RHOST="localhost"
> -    export TEST_USER="ftpuser2"
> -    export TEST_USER_PASSWD="eal"
> -    export TEST_USER_ENCRYPTED_PASSWD="42VmxaOByKwlA"
> -    export TEST_USER_HOMEDIR="/home/$TEST_USER"
> -
> -    # erase user if he may exist, so we can have a clean env
> -    TCtmp="/home/$TEST_USER"
> -
> -    tst_setup
> +do_test()
> +{
> +	CONNECTION_FAILED="Connection failed; test FAILED"
> +	EXPECTED="Login failed as expected; test PASSED"
> +	UNEXPECTED="Login succeeded unexpectedly; test FAILED"
>   
> -    exists expect ftp ftp02_s1 useradd userdel
> +	set PASSWD "invaild_password?!!"
> +	set timeout 90
>   
> -    userdel $TEST_USER
> -    sleep 1
> +	expect -c "
> +		#ftp to host
> +		spawn ftp $RHOST
> +		sleep 1
> +		# Check if connection succeeded.
> +		expect {
> +			\"Name\" {}
> +			timeout {send_user \"\n$CONNECTION_FAILED\n\";exit 1}
> +		}
>   
> -    if ! useradd -m -p $TEST_USER_ENCRYPTED_PASSWD $TEST_USER; then
> -        end_testcase "Could not add test user $TEST_USER to system $RHOST."
> -    fi
> +		send \"$RUSER\r\"
> +		sleep 1
> +		expect -re \"Password:\"
> +		send \"$PASSWD\r\"
> +		sleep 1
>   
> -    trap do_cleanup EXIT
> +		expect {
> +			# 530 - Login failed
> +			\"530\" {send_user \"$EXPECTED\n\";exit 0}
> +			# 230 - Login successful
> +			\"230\" {send_user \"$UNEXPECTED\n\"; exit 1}
> +		}
>   
> +		expect \"ftp>\"
> +		send \"exit\r\"
> +	"
>   }
>   
> -#-----------------------------------------------------------------------
> -# FUNCTION:  do_cleanup
> -#-----------------------------------------------------------------------
> +TCID="$0"

May be we should just change it to ftp02, otherwise test name will 
depend on how you running it (e.g. running by full path, TCID becomes 
"/opt/ltp/testcases/bin/test_name".

Are you running these tests from runEALtests.sh?

Can we add them to networktests.sh, to "TCP/IP command tests" group as 
it already has ftp01?

Thanks,
Alexey


------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [LTP] [PATCH v2 1/2] network ftp: some cleanup
  2014-08-01 13:23     ` Alexey Kodanev
@ 2014-09-25 10:56       ` Alexey Kodanev
  0 siblings, 0 replies; 8+ messages in thread
From: Alexey Kodanev @ 2014-09-25 10:56 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
On 08/01/2014 05:23 PM, Alexey Kodanev wrote:
> Hi Zeng!
> On 08/01/2014 07:11 AM, Zeng Linggang wrote:
>> * Move do_setup and do_cleanup into ftp_setup.
>>
>> * Delete ftp02_s1 and add do_test function for it.
>>
>> * Delete ftp_set_passwd and ftp_setup_vsftp_conf, since they are not 
>> be used.
>>
>> * Use test.sh instead of net_cmdlib.sh
>>
>> * Abandon trap and use tst_exit.
>>
>> * Make the test like:
>>     (set TCID TST_TOTAL ...)
>>     setup
>>     do_test
>>     check_result
>>     tst_exit
>>
>> * Some cleanup.
>>
>> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
>> ---
>>   testcases/network/tcp_cmds/ftp/ftp02               |  99 +++++++-----
>>   testcases/network/tcp_cmds/ftp/ftp02_s1            |  71 ---------
>>   testcases/network/tcp_cmds/ftp/ftp03               | 175 
>> +++++++--------------
>>   testcases/network/tcp_cmds/ftp/ftp04               | 109 ++++++-------
>>   testcases/network/tcp_cmds/ftp/ftp05               | 146 
>> ++++++++---------
>>   testcases/network/tcp_cmds/ftp/ftp_set_passwd      |  28 ----
>>   testcases/network/tcp_cmds/ftp/ftp_setup           |  73 +++++++++
>>   .../network/tcp_cmds/ftp/ftp_setup_vsftp_conf      |   5 -
>>   8 files changed, 304 insertions(+), 402 deletions(-)
>>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp02_s1
>>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_set_passwd
>>   create mode 100644 testcases/network/tcp_cmds/ftp/ftp_setup
>>   delete mode 100755 testcases/network/tcp_cmds/ftp/ftp_setup_vsftp_conf
>>
...
>> -#-----------------------------------------------------------------------
>> -# FUNCTION:  do_cleanup
>> -#----------------------------------------------------------------------- 
>>
>> +TCID="$0"
>
> May be we should just change it to ftp02, otherwise test name will 
> depend on how you running it (e.g. running by full path, TCID becomes 
> "/opt/ltp/testcases/bin/test_name".
>

Pushed both patches, also changed TCID names.
Thanks.

> Are you running these tests from runEALtests.sh?
>
> Can we add them to networktests.sh, to "TCP/IP command tests" group as 
> it already has ftp01?
>
> Thanks,
> Alexey
>


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-09-25 10:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-29 11:42 [LTP] [PATCH 1/2] network ftp: some cleanup Zeng Linggang
2014-07-29 11:42 ` [LTP] [PATCH 2/2] network ssh: " Zeng Linggang
2014-07-31 11:55 ` [LTP] [PATCH 1/2] network ftp: " Alexey
2014-08-01  1:25   ` Zeng Linggang
2014-08-01  3:11   ` [LTP] [PATCH v2 " Zeng Linggang
2014-08-01 13:23     ` Alexey Kodanev
2014-09-25 10:56       ` Alexey Kodanev
2014-08-01  3:12   ` [LTP] [PATCH v2 2/2] network ssh: " Zeng Linggang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox