-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix count_oval_object get wrong count #4427
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,31 @@ def load_xml(file_name): | |
try: | ||
it = ET.iterparse(file_name) | ||
for _, el in it: | ||
el.tag = el.tag.split('}', 1)[1] # strip all namespaces | ||
if '}'in el.tag: | ||
el.tag = el.tag.split('}', 1)[1] # strip all namespaces | ||
root = it.root | ||
return root | ||
except: | ||
sys.stderr.write("Error while loading file " + file_name + ".\n") | ||
exit(-1) | ||
|
||
|
||
def get_ext_def_tests(oval_root, def_refs): | ||
t = [] | ||
for d in oval_root.findall(".//definition"): | ||
if d.attrib.get('id') == def_refs: | ||
definition = d | ||
break | ||
if definition is not None: | ||
for criterion in definition.findall(".//criterion"): | ||
test_ref = criterion.attrib["test_ref"] | ||
t.append(test_ref) | ||
for extend_def in definition.findall(".//extend_definition"): | ||
extend_ref = extend_def.attrib["definition_ref"] | ||
t = t + (get_ext_def_tests(oval_root, extend_ref)) | ||
return t | ||
|
||
|
||
def find_oval_objects(oval_refs): | ||
''' Finds OVAL objects according to definitions ID ''' | ||
tests = [] | ||
|
@@ -54,29 +71,38 @@ def find_oval_objects(oval_refs): | |
definition = d | ||
break | ||
if definition is not None: | ||
extend_refs = [] | ||
for criterion in definition.findall(".//criterion"): | ||
test_ref = criterion.attrib["test_ref"] | ||
tests.append(test_ref) | ||
for extend_def in definition.findall(".//extend_definition"): | ||
extend_ref = extend_def.attrib["definition_ref"] | ||
t = get_ext_def_tests(oval_root, extend_ref) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well, name the variable more significantly. |
||
tests += t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I know, there shouldn't be difference under the hood, but lets be consistent and use |
||
|
||
# find references to objects in tests | ||
for test in tests: | ||
test_element = None | ||
for t in oval_root.findall("tests/*"): | ||
if t.attrib.get('id') == test: | ||
test_element = t | ||
break | ||
if test_element is not None: | ||
for object_element in test_element.findall(".//*"): | ||
if 'object_ref' in object_element.attrib: | ||
object_ref = object_element.attrib['object_ref'] | ||
object_refs.append(object_ref) | ||
for key in oval_files: | ||
oval_root = oval_files[key] | ||
for test in tests: | ||
test_element = None | ||
for t in oval_root.findall("tests/*"): | ||
if t.attrib.get('id') == test: | ||
test_element = t | ||
break | ||
if test_element is not None: | ||
for object_element in test_element.findall(".//*"): | ||
if 'object_ref' in object_element.attrib: | ||
object_ref = object_element.attrib['object_ref'] | ||
object_refs.append(object_ref) | ||
|
||
# find objects | ||
for r in object_refs: | ||
for obj in oval_root.findall("objects/*"): | ||
if obj.attrib.get('id') == r: | ||
objects.append(obj.tag) | ||
break | ||
for key in oval_files: | ||
oval_root = oval_files[key] | ||
for r in object_refs: | ||
for obj in oval_root.findall("objects/*"): | ||
if obj.attrib.get('id') == r: | ||
objects.append(obj.tag) | ||
break | ||
|
||
return set(objects) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please name the variable clearly, for example
extended_tests
.