#! /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   : ssh 
#
#  PURPOSE: Tests to see that ssh rejects an invalid username
#
#  SETUP: The program `/usr/bin/expect' MUST be installed.
#
#  HISTORY:
#    03/03 Jerone Young (jeroney@us.ibm.com)
#    05/03 Dustin Kirkland (k1rkland@us.ibm.com)
#
#
set RHOST $env(RHOST)
set TEST_USER $env(TEST_USER)
set TEST_USER_PASSWD $env(TEST_USER_PASSWD)

set RUSER $TEST_USER

set timeout 90

#test invalid username

send_user "TEST: Test to see if ssh rejects Invalid User \n"

# Set RUSER to an invalid user
set RUSER "Invaild_User"
set PASSWD $TEST_USER_PASSWD


spawn ssh -l $RUSER $RHOST

while 1 {
    sleep 2 
    expect {

        "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\r"}
        "assword:" {exp_send "$PASSWD\r"}
        "Permission denied" {
            send_user "SSH would not allow $RUSER to login with invalid password, Test Passed \n"
            send_user "\nTEST_PASSED\n"
            break
        }
            "#" {send_user "SSH allowed $RUSER to login with invalid pass, Test
Failed \n" ;exit 1}
    }
    sleep 1
}

exit 0
