Skip to content

Commit

Permalink
Merge pull request OpenSCAP#380 from NonerKao/maint-1.2
Browse files Browse the repository at this point in the history
Reuse existing function during the check
  • Loading branch information
isimluk committed Apr 9, 2016
2 parents 71ac62d + ca8c39b commit 7bffe59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 70 deletions.
42 changes: 12 additions & 30 deletions tests/API/XCCDF/applicability/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,43 @@ function test_api_xccdf_cpe_eval {
local CPE_DICT=$srcdir/$2
local EXPECTED_NA=$3

local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --cpe $CPE_DICT --results $TMP_RESULTS $INPUT
result=`mktemp`
$OSCAP xccdf eval --cpe $CPE_DICT --results $result $INPUT
if [ "$?" != "0" ]; then
return 1
fi

local NOTAPPLICABLE_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="notapplicable"])')
rm -f $TMP_RESULTS

if [ "$NOTAPPLICABLE_COUNT" == "$EXPECTED_NA" ]; then
return 0
fi

return 1
assert_exists $EXPECTED_NA '//result[text()="notapplicable"]'
rm -f $result
}

function test_api_xccdf_cpe2_eval {
local INPUT=$srcdir/$1
local CPE_DICT=$srcdir/$2
local EXPECTED_NA=$3

local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --cpe $CPE_DICT --results $TMP_RESULTS $INPUT
result=`mktemp`
$OSCAP xccdf eval --cpe $CPE_DICT --results $result $INPUT
if [ "$?" != "0" ]; then
return 1
fi

local NOTAPPLICABLE_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="notapplicable"])')
rm -f $TMP_RESULTS

if [ "$NOTAPPLICABLE_COUNT" == "$EXPECTED_NA" ]; then
return 0
fi

return 1
assert_exists $EXPECTED_NA '//result[text()="notapplicable"]'
rm -f $result
}

function test_api_xccdf_embedded_cpe_eval {
local INPUT=$srcdir/$1
local EXPECTED_NA=$2

local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --results $TMP_RESULTS $INPUT
result=`mktemp`
$OSCAP xccdf eval --results $result $INPUT
if [ "$?" != "0" ]; then
return 1
fi

local NOTAPPLICABLE_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="notapplicable"])')
rm -f $TMP_RESULTS

if [ "$NOTAPPLICABLE_COUNT" == "$EXPECTED_NA" ]; then
return 0
fi

return 1
assert_exists $EXPECTED_NA '//result[text()="notapplicable"]'
rm -f $result
}
# Testing.

Expand Down
56 changes: 16 additions & 40 deletions tests/API/XCCDF/tailoring/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ function test_api_xccdf_tailoring {
local PROFILE=$3
local EXPECTED_PASS=$4

local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --tailoring-file $TAILORING --profile $PROFILE --results $TMP_RESULTS $INPUT
result=`mktemp`
$OSCAP xccdf eval --tailoring-file $TAILORING --profile $PROFILE --results $result $INPUT
if [ "$?" != "0" ]; then
return 1
fi

local PASS_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="pass"])')
rm -f $TMP_RESULTS

if [ "$PASS_COUNT" == "$EXPECTED_PASS" ]; then
return 0
fi

return 1
assert_exists $EXPECTED_PASS '//result[text()="pass"]'
rm -f $result
}

function test_api_xccdf_tailoring_ds {
Expand All @@ -35,20 +29,14 @@ function test_api_xccdf_tailoring_ds {
local PROFILE=$3
local EXPECTED_PASS=$4

local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --tailoring-id $TAILORING_ID --profile $PROFILE --results $TMP_RESULTS $INPUT
result=`mktemp`
$OSCAP xccdf eval --tailoring-id $TAILORING_ID --profile $PROFILE --results $result $INPUT
if [ "$?" != "0" ]; then
return 1
fi

local PASS_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="pass"])')
rm -f $TMP_RESULTS

if [ "$PASS_COUNT" == "$EXPECTED_PASS" ]; then
return 0
fi

return 1
assert_exists $EXPECTED_PASS '//result[text()="pass"]'
rm -f $result
}

function test_api_xccdf_tailoring_ds_hybrid {
Expand All @@ -57,20 +45,14 @@ function test_api_xccdf_tailoring_ds_hybrid {
local PROFILE=$3
local EXPECTED_PASS=$4

local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --tailoring-file $TAILORING --profile $PROFILE --results $TMP_RESULTS $INPUT
result=`mktemp`
$OSCAP xccdf eval --tailoring-file $TAILORING --profile $PROFILE --results $result $INPUT
if [ "$?" != "0" ]; then
return 1
fi

local PASS_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="pass"])')
rm -f $TMP_RESULTS

if [ "$PASS_COUNT" == "$EXPECTED_PASS" ]; then
return 0
fi

return 1
assert_exists $EXPECTED_PASS '//result[text()="pass"]'
rm -f $result
}

function test_api_xccdf_tailoring_oscap_info {
Expand All @@ -92,20 +74,14 @@ function test_api_xccdf_tailoring_autonegotiation {
local PROFILE=$2
local EXPECTED_PASS=$3

local TMP_RESULTS=`mktemp`
$OSCAP xccdf eval --profile $PROFILE --results $TMP_RESULTS $TAILORING
result=`mktemp`
$OSCAP xccdf eval --profile $PROFILE --results $result $TAILORING
if [ "$?" != "0" ]; then
return 1
fi

local PASS_COUNT=$($XPATH $TMP_RESULTS 'count(//result[text()="pass"])')
rm -f $TMP_RESULTS

if [ "$PASS_COUNT" == "$EXPECTED_PASS" ]; then
return 0
fi

return 1
assert_exists $EXPECTED_PASS '//result[text()="pass"]'
rm -f $result
}

# Testing.
Expand Down

0 comments on commit 7bffe59

Please sign in to comment.