• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 accepts a valid user (non-root)
22#
23#  SETUP: The program `/usr/bin/expect' MUST be installed.
24#
25#  HISTORY:
26#    03/03 Jerone Young (jeroney@us.ibm.com)
27#
28#
29set RHOST $env(RHOST)
30set TEST_USER $env(TEST_USER)
31set TEST_USER_PASSWD $env(TEST_USER_PASSWD)
32
33set RUSER $TEST_USER
34set PASSWD $TEST_USER_PASSWD
35
36set timeout 90
37
38#test valid username
39
40send_user "TEST: SSH allow (non-root) valid User \n"
41
42spawn ssh -l $RUSER $RHOST whoami
43
44while 1 {
45	sleep 2
46	expect {
47
48		"Are you sure you want to continue connecting (yes/no)?" {
49			exp_send "yes\r"
50		}
51		"assword:" {
52			exp_send "$PASSWD\r"
53		}
54		-re "Permission denied (.*)\." {
55			send_user "\nSSH would not allow $RUSER to login, Test\
56				   FAILED \n"
57			exit 1
58		}
59		"$RUSER" {
60			send_user "SSH allowed $RUSER to login, Test PASSED \n"
61			exit 0
62		}
63	}
64	sleep 1
65}
66
67exit 1
68