def test_get_rule_dict():
    src = 'test_data/ssg-fedora-ds-arf.xml'
    parser = XmlParser(tests.any_test_help.get_src(src))
    rule_dict = parser.get_rule_dict(
        'xccdf_org.ssgproject.content_rule_dconf_gnome_session_idle_user_locks')
    src = 'test_data/rule_dict.json'
    with open(tests.any_test_help.get_src(src), 'r') as f:
        data = json.load(f)
    assert data == rule_dict
Exemplo n.º 2
0
def any_test_transformation_tree_to_Json_for_JsTree(
        src, test_data_src, rule_id):
    test_data = any_get_test_data_json(test_data_src)

    parser = XmlParser(get_src(src))
    oval_tree = parser.get_oval_tree(rule_id)

    assert oval_tree.node_id == rule_id
    out_data = Converter(oval_tree).to_js_tree_dict()
    assert out_data == test_data
from oval_graph.xml_parser import XmlParser
import time

rule = 'xccdf_org.ssgproject.content_rule_enable_fips_mode'
src = 'tests/test_data/[email protected]'

print("Benchmark xml to oval_tree")
print("Start process rule: ", rule)
print("report-xml: ", src)
start_time = time.time()

xml_parser = XmlParser(src)
oval_tree = xml_parser.get_oval_tree(rule)

print(
    "rule xccdf_org.ssgproject.content_rule_enable_fips_mode --- %s seconds ---"
    % (time.time() - start_time))

print("Start process all rules")
print("report-xml: ", src)
start_time_all_rules = time.time()

xml_parser_all_rules = XmlParser(src)
try:
    for rule in xml_parser_all_rules.used_rules:
        oval_tree = xml_parser_all_rules.get_oval_tree(rule['id_rule'])
    print("%d rules --- %s seconds ---" % (len(
        xml_parser_all_rules.used_rules), time.time() - start_time_all_rules))
except AttributeError:
    for rule in xml_parser_all_rules.get_used_rules():
        oval_tree = xml_parser_all_rules.get_oval_tree(rule['id_rule'])
Exemplo n.º 4
0
from oval_graph.xml_parser import XmlParser
import time

rule = 'xccdf_org.ssgproject.content_rule_enable_fips_mode'
src = 'tests/test_data/[email protected]'

print("Benchmark xml to oval_tree")
print("Start process rule: ", rule)
print("report-xml: ", src)
start_time = time.time()

xml_parser = XmlParser(src)
oval_tree = xml_parser.get_oval_tree(rule)

print(
    "rule xccdf_org.ssgproject.content_rule_enable_fips_mode --- %s seconds ---"
    % (time.time() - start_time))

print("Start process all rules")
print("report-xml: ", src)
start_time_all_rules = time.time()

xml_parser_all_rules = XmlParser(src)

for rule in xml_parser_all_rules.used_rules:
    oval_tree = xml_parser_all_rules.get_oval_tree(rule)
print(
    "%d rules --- %s seconds ---" %
    (len(xml_parser_all_rules.used_rules), time.time() - start_time_all_rules))
Exemplo n.º 5
0
def test_get_def_id_by_rule_id():
    src = 'test_data/ssg-fedora-ds-arf.xml'
    parser = XmlParser(tests.any_test_help.get_src(src))

    with pytest.raises(Exception, match='404 rule "hello" not found!'):
        assert parser._get_definition_of_rule('hello')
Exemplo n.º 6
0
def any_test_parsing_and_evaluate_scan_rule(src, rule_id, result):
    parser = XmlParser(get_src(src))
    oval_tree = parser.get_oval_tree(rule_id)
    any_test_treeEvaluation(oval_tree, result)
Exemplo n.º 7
0
def get_parser(src):
    return XmlParser(get_src(src))
def test_get_def_id_by_rule_id():
    src = 'test_data/ssg-fedora-ds-arf.xml'
    parser = XmlParser(tests.any_test_help.get_src(src))

    with pytest.raises(Exception, match="err- 404 rule not found!"):
        assert parser.get_def_id_by_rule_id('hello')