| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import os |
| 10 |
from import_handler import oscap, result2str, get_path |
| 11 |
|
| 12 |
|
| 13 |
print("opening ./samples/xccdf_sample.xml ...") |
| 14 |
sess = oscap.xccdf.session_new(get_path("samples/xccdf_sample.xml")) |
| 15 |
|
| 16 |
res = sess.load() |
| 17 |
|
| 18 |
if not res == 0: |
| 19 |
raise ValueError("Return value of xccdf_session_load isn't 0 but {0} !".format(res)) |
| 20 |
|
| 21 |
''' |
| 22 |
rules to test whith desired return value |
| 23 |
''' |
| 24 |
|
| 25 |
rules = {"R-SHOULD_PASS": oscap.common.XCCDF_RESULT_PASS, |
| 26 |
"R-SHOULD_FAIL": oscap.common.XCCDF_RESULT_FAIL} |
| 27 |
|
| 28 |
res = sess.evaluate() |
| 29 |
|
| 30 |
if not res == 0: |
| 31 |
raise ValueError("Return value of xccdf_session_evaluate isn't 0 but {0} !".format(res)) |
| 32 |
|
| 33 |
if sess.get_base_score() != 50: |
| 34 |
raise ValueError("base score should be 50 but is {0} ", sess.get_base_score()) |
| 35 |
|
| 36 |
for rs in sess.get_xccdf_policy().get_results(): |
| 37 |
for rr in rs.get_rule_results(): |
| 38 |
print("Rule {0} evaluated as {1}" |
| 39 |
.format(rr.get_idref(), result2str(rr.get_result()))) |
| 40 |
|
| 41 |
if rules[rr.get_idref()] != rr.get_result(): |
| 42 |
raise ValueError("Result value of {0} should be {1} but is {2}" |
| 43 |
.format(rr.get_idref(), rules[rr.get_idref()], rr.get_result())) |
| 44 |
|
| 45 |
sess.free() |