Home | History | Annotate | Download | only in ssh
      1 #! /usr/bin/expect -f
      2 #*********************************************************************
      3 #   Copyright (c) International Business Machines  Corp., 2000
      4 #
      5 #   This program is free software;  you can redistribute it and/or modify
      6 #   it under the terms of the GNU General Public License as published by
      7 #   the Free Software Foundation; either version 2 of the License, or
      8 #   (at your option) any later version.
      9 #
     10 #   This program is distributed in the hope that it will be useful,
     11 #   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13 #   the GNU General Public License for more details.
     14 #
     15 #   You should have received a copy of the GNU General Public License
     16 #   along with this program;  if not, write to the Free Software
     17 #   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18 #
     19 #  FILE   : ssh
     20 #
     21 #  PURPOSE: Tests to see that ssh rejects an invalid username
     22 #
     23 #  SETUP: The program `/usr/bin/expect' MUST be installed.
     24 #
     25 #  HISTORY:
     26 #    03/03 Jerone Young (jeroney (at] us.ibm.com)
     27 #    05/03 Dustin Kirkland (k1rkland (at] us.ibm.com)
     28 #
     29 #
     30 set RHOST $env(RHOST)
     31 set TEST_USER $env(TEST_USER)
     32 set TEST_USER_PASSWD $env(TEST_USER_PASSWD)
     33 
     34 set RUSER $TEST_USER
     35 set PASSWD $TEST_USER_PASSWD
     36 
     37 set timeout 90
     38 
     39 #test invalid username
     40 
     41 send_user "TEST: Test to see if ssh rejects Invalid User \n"
     42 
     43 # Set RUSER to an invalid user
     44 set RUSER "Invaild_User"
     45 
     46 spawn ssh -l $RUSER $RHOST whoami
     47 
     48 while 1 {
     49 	sleep 2
     50 	expect {
     51 
     52 		"Are you sure you want to continue connecting (yes/no)?" {
     53 			exp_send "yes\r"
     54 		}
     55 		"assword:" {
     56 			exp_send "$PASSWD\r"
     57 		}
     58 		-re "Permission denied (.*)\." {
     59 			send_user "SSH would not allow $RUSER to login with\
     60 				   invalid password, Test Passed \n"
     61 			send_user "\nTEST_PASSED\n"
     62 			exit 0
     63 		}
     64 		"$RUSER" {
     65 			send_user "SSH allowed $RUSER to login with invalid\
     66 				   pass, Test Failed \n"
     67 			exit 1
     68 		}
     69 	}
     70 	sleep 1
     71 }
     72 
     73 exit 1
     74