diff --git a/testcases/SOP/sop.sh b/testcases/SOP/sop.sh new file mode 100755 index 0000000000000000000000000000000000000000..22dd07192a01b487078527b64c743711f5ee5cf4 --- /dev/null +++ b/testcases/SOP/sop.sh @@ -0,0 +1,218 @@ +#!/usr/bin/env bash + +# ---------------------------------------------------------------------- +# Filename : sop.sh +# Version : 1.0 +# Date : 2020/05/26 +# Author : Lz +# Email : lz843723683@gmail.com +# History : +# Version 1.0, 2020/05/26 +# Function : 调用不同版本形态测试程序 +# In : Features testcase name(testcase dir name) +# Out : +# 0=> TPASS +# 1=> TFAIL +# other=> TCONF +# ---------------------------------------------------------------------- + + +## TODO : 测试前的初始化验证 +# In : $1=>testcase dir name +# Out : +# 0=> TPASS +# 1=> TFAIL +# other=> TCONF +Init_SOP(){ + local testdir="$1" + # 加载ltf库函数 + local ltflibfile="${LIB_LTFLIB}" + if [ -f "$ltflibfile" ];then + source $ltflibfile + else + echo "$ltflibfile : Can't found file !" + return 1 + fi + + # 判断是否打开SE + SEEnable_SOP + if [ $? -ne ${TPASS} ];then + exit $TFAIL + fi + + # 判断是否存在免密登录库 + local sshautofile="${LIB_SSHAUTO}" + if [ -f "$sshautofile" ];then + source $sshautofile + else + echo "$sshautofile : Can't found file !" + return $TFAIL + fi + + # 判断免密登录配置文件是否存在 + local sshautoconfigfile="${AUTOTEST_ROOT}/config/ssh-auto.conf" + if [ ! -f "$sshautoconfigfile" ];then + echo "$sshautoconfigfile : Can't found file !" + return $TFAIL + fi + + # 初始化免密登录函数 + SshAuto_Init_LTFLIB "${sshautoconfigfile}" + if [ $? -ne ${TPASS} ];then + echo "免密登录函数初始化失败..." + return $TFAIL + fi + + # 配置免密登录 + SshAuto_Config_LTFLIB + if [ $? -ne ${TPASS} ];then + echo "免密登录设置失败..." + return $TFAIL + fi + + return ${TPASS} +} + + +## TODO :需要默认打开SE +# +SEEnable_SOP(){ + local flag="Enforcing" + + # 使用getenforce判断 + getenforce | grep -q -i "${flag}" + if [ $? -eq 0 ];then + return $TPASS + else + echo "FAIL : SELINUX = `getenforce`" + echo "Must be SELIUNX = enforcing" + return $TFAIL + fi +} + + +## TODO :运行当前目录中所有的可执行文件,Run Current Dir File,前提必须进入当前目录 +# In : +# $1 => 目录名 +# Out : +# 0=> TPASS +# 1=> TFAIL +# other=> TCONF +RunCurDirFile_SOP(){ + local testdir="$1" + # 测试文件路径 + local testfile="" + local flag="${TPASS}" + local ret="${TPASS}" + + # 测试文件,通过数组保存 + local testfilelist=($(find ./ -maxdepth 1 -type f | sort)) + + for testfile in ${testfilelist[*]} + do + [[ "$testfile" =~ "readme"|"swp" ]] && continue + if [ -x "$testfile" ];then + bash $testfile + flag=$? + else + OverallLog_LLE "${TCONF}" "${testfile#*/} : No executable permissions" + # printf "\t\033[1m\033[;33m%s: %s\t[ TCONF ]\033[0m\n\n" "${testdir}/${testfile#*/}" "Permission denied" + + # 禁止降级 + if [ $ret -ne $TFAIL ];then + ret=${TCONF} + fi + + continue + fi + + OverallLog_LLE "${flag}" "${testdir}/${testfile#*/}" + RetToFlag_LLE "${flag}" "${ret}" + ret=$? + + done + + return $ret +} + + +## TODO : 执行测试 +# In : $1=>testcase dir name +# Out : +# 0=> TPASS +# 1=> TFAIL +# other=> TCONF +Run_SOP(){ + # 测试文件目录 + local testdir="$1" + local ret_1="${TPASS}" + local ret_2="${TPASS}" + + # 运行当前目录下的程序,如果运行当前目录,一定要判断去除sop.sh脚本 + #RunCurDirFile_SOP "$(basename $(pwd))" + #ret_1=$? + + # 进入测试目录 + cd ${testdir} + RunCurDirFile_SOP "${testdir}" + ret_2=$? + + # 结果过滤 + if [ $ret_1 -eq ${TFAIL} ];then + return $ret_1 + elif [ $ret_1 -eq ${TPASS} ];then + return $ret_2 + else + if [ $ret_2 -eq ${TFAIL} ];then + return $ret_2 + fi + + return $ret_1 + fi +} + + +## TODO : 解析函数返回值,不为TPASS则退出 +# Exit : +# 0=> TPASS +# 1=> TFAIL +# other=> TCONF +RetParse_SOP(){ + local ret=$? + if [ $ret -ne ${TPASS} ];then + Clear_SOP + exit $ret + fi +} + + + +## TODO : 清理函数 +Clear_SOP(){ + # 删除免密登录 + SshAuto_ClearConfig_LTFLIB +} + +## TODO : Main_SOP +# In : $1=>testcase dir name +# Out : +# 0=> TPASS +# 1=> TFAIL +# other=> TCONF +Main_SOP(){ + local testdir=$(basename $1) + cd $(dirname $1) + + Init_SOP ${testdir} + RetParse_SOP + + Run_SOP ${testdir} + RetParse_SOP + + Clear_SOP + + return ${TPASS} +} + +Main_SOP $* +exit $? diff --git a/testcases/SOP/sysadm/01-UID-sysadm.sh b/testcases/SOP/sysadm/01-UID-sysadm.sh new file mode 100755 index 0000000000000000000000000000000000000000..7fc3c78a3ff63472834b0da250a20fb3db880de3 --- /dev/null +++ b/testcases/SOP/sysadm/01-UID-sysadm.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash + +# ---------------------------------------------------------------------- +# Filename : 01-UID-sysadm.sh +# Version : 1.0 +# Date : 2020/05/28 +# Author : Lz +# Email : lz843723683@gmail.com +# History : +# Version 1.0, 2020/05/28 +# Function : 测试三权分立-用户标识 +# Out : +# 0 => TPASS +# 1 => TFAIL +# other=> TCONF +# ---------------------------------------------------------------------- + +# 测试主题 +Title_Env_LTFLIB="三权分立(sysadm) - 用户标识" + +HeadFile_Source_LTFLIB="${LIB_SSHAUTO}" + +## TODO : 个性化,初始化 +# Out : 0=>TPASS +# 1=>TFAIL +# 2=>TCONF +TestInit_LTFLIB(){ + return ${TPASS} +} + + +## TODO : 清理函数 +# Out : 0=>TPASS +# 1=>TFAIL +# 2=>TCONF +TestClean_LTFLIB(){ + return ${TPASS} +} + + +## TODO : 测试用例 +testcase_1(){ + # 临时用户 + local tmpuser_uid="ltfuidsysadm" + # UID号 + local uid_1="" + local uid_2="" + + # 如果存在用户则删除 + SshAuto_CmdLocalSys_LTFLIB "sudo userdel -rf $tmpuser_uid" "no" "no" &>/dev/null + SshAuto_CmdLocalSys_LTFLIB "sudo useradd $tmpuser_uid" "no" "no" + + # 获取UID + uid_1=$(id -u ${tmpuser_uid}) + echo "新建用户 ${tmpuser_uid} 的UID: $uid_1" + + SshAuto_CmdLocalSys_LTFLIB "sudo userdel -rf $tmpuser_uid" "no" "no" + SshAuto_CmdLocalSys_LTFLIB "sudo useradd $tmpuser_uid" "no" "no" + # 获取UID + uid_2=$(id -u ${tmpuser_uid}) + echo "删除后重建用户 ${tmpuser_uid} 的UID: $uid_2" + + SshAuto_CmdLocalSys_LTFLIB "sudo userdel -rf $tmpuser_uid" "no" "no" + + if [ "Z$uid_1" != "Z$uid_2" ];then + # UID不一致 + OutputRet_LTFLIB ${TPASS} + TestRetParse_LTFLIB "要求两次UID 不一致" "False" + else + OutputRet_LTFLIB ${TFAIL} + TestRetParse_LTFLIB "要求两次UID 不一致" "False" + fi +} + +## TODO : 测试用例集 +# Out : 0=>TPASS +# 1=>TFAIL +# 2=>TCONF +Testsuite_LTFLIB(){ + testcase_1 + + return $TPASS +} + + +#----------------------------------------------# + +source "${LIB_LTFLIB}" +Main_LTFLIB $@