| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import os |
| 7 |
from import_handler import oscap, result2str, get_path |
| 8 |
|
| 9 |
|
| 10 |
''' |
| 11 |
Import and browse benchmark results |
| 12 |
|
| 13 |
''' |
| 14 |
|
| 15 |
benchmark = oscap.xccdf.benchmark_import(get_path("samples/xccdf_sample_results.xml")) |
| 16 |
if benchmark.instance is None: |
| 17 |
raise Exception("Cannot import the benchmark {0}" |
| 18 |
.format(get_path("samples/xccdf_sample_results.xml"))) |
| 19 |
else: |
| 20 |
print("Benchmark id: ", benchmark.get_id()) |
| 21 |
results = benchmark.get_results() |
| 22 |
test_result = results.pop() |
| 23 |
print(test_result.get_id()) |
| 24 |
|
| 25 |
for rs in test_result.get_rule_results(): |
| 26 |
idref, result = rs.get_idref(), rs.get_result() |
| 27 |
print(idref, result2str(result)) |
| 28 |
|
| 29 |
if (idref == "R-SHOULD_PASS" and |
| 30 |
result != oscap.xccdf.XCCDF_RESULT_PASS): |
| 31 |
|
| 32 |
raise Exception("Rule result for {0} should be PASS but is currently {1}." |
| 33 |
.format(idref, |
| 34 |
result2str(result))) |
| 35 |
|
| 36 |
elif (idref == "R-SHOULD_FAIL" and |
| 37 |
result != oscap.xccdf.XCCDF_RESULT_FAIL): |
| 38 |
|
| 39 |
raise Exception("Rule result for {0} should be FAIL but is currently {1}." |
| 40 |
.format(idref, |
| 41 |
result2str(result))) |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
benchmark = oscap.xccdf.benchmark_import("../../oval_details/file_doesnt_exists.xml") |
| 47 |
if benchmark.instance is not None: |
| 48 |
raise Exception("benchmark_import should return None if it can't open the file") |
| 49 |
else: |
| 50 |
print("benchmark_import on a non existing file returns None.") |