diff --git a/testcases/SOP/secadm/02-setsebool-secadm.sh b/testcases/SOP/secadm/02-setsebool-secadm.sh new file mode 100755 index 0000000000000000000000000000000000000000..873d1b257ddbdcae0c184339b2991ff2c170b9cf --- /dev/null +++ b/testcases/SOP/secadm/02-setsebool-secadm.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# ---------------------------------------------------------------------- +# Filename : 02-setsebool-secadm.sh +# Version : 1.0 +# Date : 2020/05/28 +# Author : Lz +# Email : lz843723683@gmail.com +# History : +# Version 1.0, 2020/05/28 +# Function : 测试三权分立secadm-修改Selinux bool变量 +# Out : +# 0 => TPASS +# 1 => TFAIL +# other=> TCONF +# ---------------------------------------------------------------------- + +# 测试主题 +Title_Env_LTFLIB="三权分立(secadm) - 修改Selinux bool变量" + +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(){ + SshAuto_CmdLocalSec_LTFLIB "sudo semanage boolean -l | tail -n 5" "no" "no" + SshAuto_CmdLocalSec_LTFLIB "sudo semanage boolean -l" "yes" "no" + TestRetParse_LTFLIB "可以查看到所有SE布尔变量 (日志太多仅显示最后5条)" "False" + + # 布尔变量 + local tmpvar="httpd_use_nfs" + local tmplog="" + tmplog="$(SshAuto_CmdLocalSec_LTFLIB "sudo getsebool ${tmpvar}" "no" "no")" + SshAuto_CmdLocalSec_LTFLIB "sudo getsebool ${tmpvar}" "no" "no" + TestRetParse_LTFLIB "可以查看到 ${tmpvar} 布尔变量的当前值" "False" + + echo $tmplog | grep -q -e "--> off" + if [ $? -eq 0 ];then + # 当前开关关闭 + # 打开布尔值 + SshAuto_CmdLocalSec_LTFLIB "sudo setsebool ${tmpvar}=on" "no" "no" + tmplog="$(SshAuto_CmdLocalSec_LTFLIB "sudo getsebool ${tmpvar}" "no" "no")" + echo $tmplog | grep -q -e "--> on" + if [ $? -eq 0 ];then + OutputRet_LTFLIB "$TPASS" + TestRetParse_LTFLIB "设置 ${tmpvar} 布尔变量为 on" "False" + else + OutputRet_LTFLIB "$TFAIL" + TestRetParse_LTFLIB "设置 ${tmpvar} 布尔变量为 on" "False" + fi + + # 获取设置后的布尔变量值 + SshAuto_CmdLocalSec_LTFLIB "sudo getsebool ${tmpvar}" "no" "no" + TestRetParse_LTFLIB "修改后 ${tmpvar} 为 on" "False" + + # 复原 + SshAuto_CmdLocalSec_LTFLIB "sudo setsebool ${tmpvar}=off" "yes" "no" + else + # 打开布尔值 + SshAuto_CmdLocalSec_LTFLIB "sudo setsebool ${tmpvar}=off" "no" "no" + tmplog="$(SshAuto_CmdLocalSec_LTFLIB "sudo getsebool ${tmpvar}" "no" "no")" + echo $tmplog | grep -q -e "--> off" + if [ $? -eq 0 ];then + OutputRet_LTFLIB "$TPASS" + TestRetParse_LTFLIB "设置 ${tmpvar} 布尔变量为 off" "False" + else + OutputRet_LTFLIB "$TFAIL" + TestRetParse_LTFLIB "设置 ${tmpvar} 布尔变量为 off" "False" + fi + + # 获取设置后的布尔变量值 + SshAuto_CmdLocalSec_LTFLIB "sudo getsebool ${tmpvar}" "no" "no" + TestRetParse_LTFLIB "修改后 ${tmpvar} 为 off" "False" + + # 复原 + SshAuto_CmdLocalSec_LTFLIB "sudo setsebool ${tmpvar}=on" "yes" "no" + fi +} + +## TODO : 测试用例集 +# Out : 0=>TPASS +# 1=>TFAIL +# 2=>TCONF +Testsuite_LTFLIB(){ + testcase_1 + + return $TPASS +} + + +#----------------------------------------------# + +source "${LIB_LTFLIB}" +Main_LTFLIB $@