From d255920f5a20cc4c5e38a515f69a836bfc43a7e0 Mon Sep 17 00:00:00 2001 From: Steve Barnes Date: Jun 11 2011 07:39:36 +0000 Subject: Added revised p_openssh tests (Bash vs Python) provided by Athmane. --- diff --git a/tests/p_nfs/0-install_nfs.sh b/tests/p_nfs/0-install_nfs.sh old mode 100644 new mode 100755 diff --git a/tests/p_nfs/nfs_share_rw.sh b/tests/p_nfs/nfs_share_rw.sh old mode 100644 new mode 100755 diff --git a/tests/p_openssh/0-install_sshd.sh b/tests/p_openssh/0-install_sshd.sh index a3ede2f..cf9b478 100755 --- a/tests/p_openssh/0-install_sshd.sh +++ b/tests/p_openssh/0-install_sshd.sh @@ -1,7 +1,7 @@ #!/bin/bash # Author: Athmane Madjoudj -# SSH -t_InstallPackage openssh-server +# expect is needed by the test +t_InstallPackage openssh-server expect chkconfig sshd on t_ServiceControl sshd start diff --git a/tests/p_openssh/_helper_sshd_user_login.expect b/tests/p_openssh/_helper_sshd_user_login.expect new file mode 100755 index 0000000..802f7b7 --- /dev/null +++ b/tests/p_openssh/_helper_sshd_user_login.expect @@ -0,0 +1,10 @@ +#!/usr/bin/expect -f +# Author: Athmane Madjoudj + +set timeout 2 +spawn ssh -o StrictHostKeyChecking=no sshtest@localhost /bin/ls +match_max 6000 +expect "*?assword:*" +send -- "sshtest\r" +send -- "\r" +expect eof diff --git a/tests/p_openssh/sshd_user_login.py b/tests/p_openssh/sshd_user_login.py deleted file mode 100755 index acf6a37..0000000 --- a/tests/p_openssh/sshd_user_login.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/python -# Author: Athmane Madjoudj - -import os,sys - -def install_pexpect(): - if os.system("rpm -q pexpect") == 0: - return 0 - else: - return os.system("yum -y install pexpect") - -def ssh_command (user, host, password, command): - import pexpect - ssh_newkey = 'Are you sure you want to continue connecting' - child = pexpect.spawn('ssh -l %s %s %s'%(user, host, command)) - i = child.expect([pexpect.TIMEOUT, ssh_newkey, 'password: ']) - if i == 0: # Timeout - print child.before, child.after - return None - if i == 1: # SSH does not have the public key. Just accept it. - child.sendline ('yes') - child.expect ('password: ') - i = child.expect([pexpect.TIMEOUT, 'password: ']) - if i == 0: # Timeout - print child.before, child.after - return None - child.sendline(password) - child.expect(pexpect.EOF) - print child.before - return child.before - -if __name__ == '__main__': - if not os.geteuid()==0: - sys.exit("root privileges are required to run this script") - else: - print "[INFO] Trying to install pexpect ..." - if install_pexpect() != 0: - sys.exit("[FAIL] pexpect installation failed") - print "[INFO] Adding new user ..." - if os.system("userdel -rf sshtest; useradd sshtest && echo sshtest | passwd --stdin sshtest") != 0: - sys.exit("[FAIL] can't add new user") - try: - ssh_command('sshtest','localhost','sshtest','/bin/ls') - except Exception, e: - sys.exit("[FAIL] SSH could not login") - else: - print "[INFO] SSH user login test: PASS" - - - diff --git a/tests/p_openssh/sshd_user_login.sh b/tests/p_openssh/sshd_user_login.sh new file mode 100755 index 0000000..3cef17f --- /dev/null +++ b/tests/p_openssh/sshd_user_login.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# Author: Athmane Madjoudj + +userdel -rf sshtest; useradd sshtest && echo sshtest | passwd --stdin sshtest + +# Create a test file +touch /home/sshtest/ssh_test_file + +t_Log "Running $0 - SSH user login test." + +./tests/p_openssh/_helper_sshd_user_login.expect | grep "ssh_test_file" + > /dev/null 2>&1 + +t_CheckExitStatus $? +