mirror of https://github.com/CISOfy/lynis.git
features/testcases (#161)
* Implemented equal test case. * Implemented not-equal test case. * Implemented greater-than test case. * Implemented greater-or-equal test case. * Implemented less-than test case. * Implemented less-or-eqal test case. Added some improvements and unifications. * Added more unifications. * Added more logs. * Unified not-equal test.
This commit is contained in:
parent
066f562365
commit
2465556567
|
@ -68,6 +68,13 @@
|
|||
# TestValue Evaluate a value in a string or key
|
||||
# ViewCategories Display tests categories
|
||||
# WaitForKeypress Wait for user to press a key to continue
|
||||
|
||||
# TestCase_Equal Test case for checking if value is equal to something
|
||||
# TestCase_NotEqual Test case for checking if value is not equal to something
|
||||
# TestCase_GreaterThan Test case for checking if value is greater than something
|
||||
# TestCase_GreaterOrEqual Test case for checking if value is greater or equal to something
|
||||
# TestCase_LessThan Test case for checking if value is less than something
|
||||
# TestCase_LessOrEqual Test case for checking if value is less or equal to something
|
||||
#
|
||||
#################################################################################
|
||||
|
||||
|
@ -148,6 +155,159 @@
|
|||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Name : TestCase_Equal()
|
||||
# Description : Test case for checking if value whether value is equal to value
|
||||
# Returns : (0 - SUCCESS; 1 - MEDIUM-VALUED; 2 - FAIL)
|
||||
################################################################################
|
||||
|
||||
TestCase_Equal()
|
||||
{
|
||||
local RETVAL=2
|
||||
|
||||
if [ "$#" -lt "2" ]; then
|
||||
ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}"
|
||||
else
|
||||
LogText "${FUNCNAME}: checking value for application ${APP}"
|
||||
LogText "${FUNCNAME}: ${OPTION} is set to ${1}"
|
||||
|
||||
|
||||
LogText "${FUNCNAME}: check if ${1} is equal to ${2}"
|
||||
|
||||
if [ "$1" == "$2" ]; then
|
||||
LogText "${FUNCNAME}: ${1} is equal to ${2}"
|
||||
RETVAL=0
|
||||
fi
|
||||
|
||||
if ! [ -z ${3+x} ]; then
|
||||
LogText "${FUNCNAME}: ${1} is equal to ${3}"
|
||||
if [ "$2" == "$3" ]; then
|
||||
LogText "${FUNCNAME}: ${OPTION} is equal to ${3}"
|
||||
RETVAL=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
return ${RETVAL}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Name : TestCase_ValueNotEqual()
|
||||
# Description : Test case for checking if value is not equal to something
|
||||
# Returns : (0 - SUCCESS; 1 - FAIL)
|
||||
################################################################################
|
||||
TestCase_NotEqual()
|
||||
{
|
||||
local RETVAL=1
|
||||
if [ "$#" -ne "2" ]; then
|
||||
ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}"
|
||||
else
|
||||
LogText "${FUNCNAME}: checking value for application ${APP}"
|
||||
LogText "${FUNCNAME}: ${OPTION} is set to ${1}"
|
||||
|
||||
if [ "$1" != "$2" ]; then
|
||||
LogText "${FUNCNAME}: ${1} is not equal to ${2}"
|
||||
RETVAL=0
|
||||
else
|
||||
LogText "${FUNCNAME}: ${1} is equal to ${2}"
|
||||
fi
|
||||
fi
|
||||
|
||||
return ${RETVAL}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Name : TestCase_GreaterThan()
|
||||
# Description : Test case for checking if value is greater than something
|
||||
# Returns : (0 - SUCCESS; 1 - FAIL)
|
||||
################################################################################
|
||||
TestCase_GreaterThan()
|
||||
{
|
||||
local RETVAL=1
|
||||
if [ "$#" -ne "2" ]; then
|
||||
ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}"
|
||||
else
|
||||
LogText "${FUNCNAME}: checking value for application ${APP}"
|
||||
LogText "${FUNCNAME}: ${OPTION} is set to ${1}"
|
||||
|
||||
LogText "${FUNCNAME}: checking if ${1} is greater than ${2}"
|
||||
if [ "$1" > "$2" ]; then
|
||||
LogText "${FUNCNAME}: ${1} is greater than ${2}"
|
||||
RETVAL=0
|
||||
else
|
||||
LogText "${FUNCNAME}: ${1} is not greater than ${2}"
|
||||
fi
|
||||
fi
|
||||
|
||||
return ${RETVAL}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Name : TestCase_GreaterOrEqual()
|
||||
# Description : Test case for checking if value is greater than something
|
||||
# Returns : (0 - SUCCESS; 1 - FAIL)
|
||||
################################################################################
|
||||
TestCase_GreaterOrEqual()
|
||||
{
|
||||
local RETVAL=1
|
||||
if [ "$#" -ne "2" ]; then
|
||||
ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}"
|
||||
else
|
||||
LogText "${FUNCNAME}: checking value for application ${APP}"
|
||||
LogText "${FUNCNAME}: ${OPTION} is set to ${1}"
|
||||
|
||||
LogText "${FUNCNAME}: checking if ${1} is greater or equal ${2}"
|
||||
if [ TestCase_Equal "${1}" "${2}" ] || [ TestCase_GreaterThan "${1}" "${2}" ]; then
|
||||
RETVAL=0
|
||||
fi
|
||||
fi
|
||||
return ${RETVAL}
|
||||
}
|
||||
################################################################################
|
||||
# Name : TestCase_LessThan()
|
||||
# Description : Test case for checking if value is greater than something
|
||||
# Returns : (0 - SUCCESS; 1 - FAIL)
|
||||
################################################################################
|
||||
TestCase_LessThan()
|
||||
{
|
||||
local RETVAL=1
|
||||
if [ "$#" -ne "2" ]; then
|
||||
ReportException "${TEST_NO}" "Error in function call to TestCase_GreaterOrEqual"
|
||||
else
|
||||
LogText "${FUNCNAME}: checking value for application ${APP}"
|
||||
LogText "${FUNCNAME}: ${OPTION} is set to ${1}"
|
||||
|
||||
LogText "${FUNCNAME}: checking if ${1} is less than ${2}"
|
||||
if ! [ TestCase_GreaterOrEqual "${1}" "${2}" ]; then
|
||||
LogText "${FUNCNAME}: ${1} is less than ${2}"
|
||||
RETVAL=0
|
||||
fi
|
||||
fi
|
||||
return ${RETVAL}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Name : TestCase_LessOrEqual()
|
||||
# Description : Test case for checking if value is less or equal something
|
||||
# Returns : (0 - SUCCESS; 1 - FAIL)
|
||||
################################################################################
|
||||
TestCase_LessOrEqual()
|
||||
{
|
||||
local RETVAL=1
|
||||
if [ "$#" -ne "2" ]; then
|
||||
ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}"
|
||||
else
|
||||
LogText "${FUNCNAME}: checking value for application ${APP}"
|
||||
LogText "${FUNCNAME}: ${OPTION} is set to ${1}"
|
||||
|
||||
LogText "${FUNCNAME}: checking if ${1} is less or equal ${2}"
|
||||
if [ TestCase_Equal "${1}" "${2}" ] || [ TestCase_LessThan "${1}" "${2}" ]; then
|
||||
LogText "${FUNCNAME}: ${1} is less than ${2}"
|
||||
RETVAL=0
|
||||
fi
|
||||
fi
|
||||
return ${RETVAL}
|
||||
}
|
||||
|
||||
# Check updates
|
||||
CheckUpdates()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue