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 password
     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 #
     28 #
     29 set RHOST $env(RHOST)
     30 set TEST_USER $env(TEST_USER)
     31 set TEST_USER_PASSWD $env(TEST_USER_PASSWD)
     32 
     33 set RUSER $TEST_USER
     34 set PASSWD $TEST_USER_PASSWD
     35 
     36 set timeout 90
     37 
     38 #test invalid password
     39 
     40 send_user "TEST: SSH Test Invalid Password \n"
     41 
     42 # Set PASSWD to an invalid password
     43 set PASSWD "invalid_password!"
     44 
     45 spawn ssh -l $RUSER $RHOST whoami
     46 
     47 while 1 {
     48 	sleep 2
     49 	expect {
     50 
     51 		"Are you sure you want to continue connecting (yes/no)?" {
     52 			exp_send "yes\r"
     53 		}
     54 		"assword:" {
     55 			exp_send "$PASSWD\r"
     56 		}
     57 		-re "Permission denied (.*)\." {
     58 			send_user "SSH would not allow $RUSER to login with\
     59 				   invalid password, Test Passed \n"
     60 			send_user "\nTEST_PASSED\n"
     61 			exit 0
     62 		}
     63 		"$RUSER" {
     64 			send_user "SSH allowed $RUSER to login with invalid\
     65 				   pass, Test Failed \n"
     66 			exit 1
     67 		}
     68 	}
     69 	sleep 1
     70 }
     71 
     72 exit 1
     73