#! /usr/bin/expect -f
#*********************************************************************
#   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 pronram;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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)
#

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
expect -re "Name"
send "$RUSER\r"
sleep 1
expect -re "Password:"
send "$PASSWD\r"
sleep 1

expect {
	# 530 - Login failed
	"530" {send_user "Ftp invalid password, login test PASSED\n"}
	# 230 - Login successful
	"230" {send_user "Ftp invalid password, login test FAILED \n";exit 1}
}

expect "ftp>"
send "exit\r"


send_user "\nTest Successful\n\n"
exit 0
