1111import xml .etree .ElementTree as ET
1212
1313from vulnerabilities .importers .suse_oval import SuseOvalImporter
14+ from vulnerabilities .oval_parser import OvalParser
1415from vulnerabilities .tests import util_tests
1516
1617BASE_DIR = os .path .dirname (os .path .abspath (__file__ ))
1718TEST_DATA = os .path .join (BASE_DIR , "test_data/suse_oval" )
1819
1920
20- # TODO: How can we test a .gz file? This would be like running one .gz through _fetch().
21+ # TODO: How can we test a .gz file?
2122
2223
23- # TODO: How are the packages identified?
24+ # TODO: A question for all these tests and the code more generally: how are the packages
25+ # associated with definitions/aliases/CVEs?
2426def test_suse_oval_importer_leap_micro_5_3 ():
2527 importer = SuseOvalImporter ()
2628 advisories = importer .get_data_from_xml_doc (
@@ -33,7 +35,9 @@ def test_suse_oval_importer_leap_micro_5_3():
3335 )
3436
3537
36- # TODO: How do we handle multiple CVEs in a single section? Is this only in patch files?
38+ # TODO: All 80 affected packages (1 for each alias) in the expected JSON are `openSUSE-release`.
39+ # What about the other 54 or so packages identified in the XML file's `object` element?
40+ # See lines 1668-1834.
3741def test_suse_oval_importer_leap_micro_5_3_patch ():
3842 importer = SuseOvalImporter ()
3943 advisories = importer .get_data_from_xml_doc (
@@ -46,7 +50,8 @@ def test_suse_oval_importer_leap_micro_5_3_patch():
4650 )
4751
4852
49- # TODO: This creates 2 identical packages -- why?
53+ # TODO: This creates an 'opera' package in the expected JSON. Should it also create a
54+ # 'openSUSE-release' package? See line 64 of the XML file.
5055def test_suse_oval_importer_CVE_2008_5679 ():
5156 importer = SuseOvalImporter ()
5257 advisories = importer .get_data_from_xml_doc (
@@ -57,3 +62,40 @@ def test_suse_oval_importer_CVE_2008_5679():
5762 util_tests .check_results_against_json (
5863 [advisory .to_dict () for advisory in advisories ], expected_file
5964 )
65+
66+
67+ # Explore parsing inspired by /vulnerablecode/vulnerabilities/tests/test_suse.py
68+ def test_suse_oval_parse_CVE_2008_5679 ():
69+ # xml_doc = ET.parse(os.path.join(TEST_DATA, "org.opensuse.CVE-2008-5679.xml"))
70+ xml_doc = ET .parse (os .path .join (TEST_DATA , "opensuse.leap.micro.5.3.xml" ))
71+ translations = {"less than" : "<" , "equals" : "=" , "greater than or equal" : ">=" }
72+
73+ parsed_oval = OvalParser (translations , xml_doc )
74+ print ("\n \n type(parsed_oval) = {}\n " .format (type (parsed_oval )))
75+
76+ print ("parsed_oval.all_definitions = {}" .format (parsed_oval .all_definitions ))
77+ print ("len(parsed_oval.all_definitions) = {}" .format (len (parsed_oval .all_definitions )))
78+
79+ definition_1 = parsed_oval .all_definitions [0 ]
80+ print ("\n definition_1 = {}" .format (definition_1 ))
81+ print ("definition_1.getId() = {}\n " .format (definition_1 .getId ()))
82+
83+ # if parsed_oval.all_definitions[1]:
84+ # definition_2 = parsed_oval.all_definitions[1]
85+ # print("definition_2 = {}".format(definition_2))
86+ # print("definition_2.getId() = {}".format(definition_2.getId()))
87+
88+ # For each definition, we can get tests for that definition
89+ # i.getId() for i in self.parsed_oval.get_tests_of_definition(self.definition_1)
90+ test_id_1 = {i .getId () for i in parsed_oval .get_tests_of_definition (definition_1 )}
91+ print ("\n test_id_1 = {}\n " .format (test_id_1 ))
92+
93+ try :
94+ definition_2 = parsed_oval .all_definitions [1 ]
95+ print ("definition_2 = {}" .format (definition_2 ))
96+ print ("definition_2.getId() = {}" .format (definition_2 .getId ()))
97+
98+ test_id_2 = {i .getId () for i in parsed_oval .get_tests_of_definition (definition_2 )}
99+ print ("\n test_id_2 = {}\n " .format (test_id_2 ))
100+ except IndexError :
101+ pass
0 commit comments