Skip to content

Commit

Permalink
Increased robustness of content handling.
Browse files Browse the repository at this point in the history
- Multiple OVAL files in an archive cause no longer an error.
- Multiple instances of other filetypes result in a content-related error.
- Unexpected errors don't crash the addon.
  • Loading branch information
matejak committed Jun 17, 2021
1 parent ac7c2ba commit 01e7afd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 6 additions & 5 deletions org_fedora_oscap/content_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def __init__(self, root):
self.labelled_files = dict()
self.datastream = ""
self.xccdf = ""
self.oval = ""
self.ovals = []
self.tailoring = ""
self.archive = ""
self.verified = ""
Expand Down Expand Up @@ -289,7 +289,7 @@ def _assign_content_type(self, attribute_name, new_value):
msg = (
f"When dealing with {attribute_name}, "
f"there was already the {old_value.name} when setting the new {new_value.name}")
raise RuntimeError(msg)
raise content_handling.ContentHandlingError(msg)
setattr(self, attribute_name, new_value)

def add_file(self, fname, label):
Expand All @@ -299,7 +299,7 @@ def add_file(self, fname, label):
elif label == content_handling.CONTENT_TYPES["DATASTREAM"]:
self._assign_content_type("datastream", path)
elif label == content_handling.CONTENT_TYPES["OVAL"]:
self._assign_content_type("oval", path)
self.ovals.append(path)
elif label == content_handling.CONTENT_TYPES["XCCDF_CHECKLIST"]:
self._assign_content_type("xccdf", path)
self.labelled_files[path] = label
Expand All @@ -312,9 +312,10 @@ def _datastream_content(self):
return self.datastream

def _xccdf_content(self):
if not self.xccdf or not self.oval:
if not self.xccdf or not self.ovals:
return None
if not (self.xccdf.exists() and self.oval.exists()):
some_ovals_exist = any([path.exists() for path in self.ovals])
if not (self.xccdf.exists() and some_ovals_exist):
return None
return self.xccdf

Expand Down
8 changes: 7 additions & 1 deletion org_fedora_oscap/gui/spokes/oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def _handle_error(self, exception):
elif isinstance(exception, content_handling.ContentCheckError):
self._integrity_check_failed()
else:
raise exception
self._general_content_problem()

def _end_fetching(self, fetched_content):
# stop the spinner in any case
Expand Down Expand Up @@ -762,6 +762,12 @@ def _set_error(self, msg):
self._error = None
self.clear_info()

@async_action_wait
def _general_content_problem(self):
msg = _("There was an unexpected problem with the supplied content.")
self._progress_label.set_markup("<b>%s</b>" % msg)
self._wrong_content(msg)

@async_action_wait
def _invalid_content(self):
"""Callback for informing user about provided content invalidity."""
Expand Down
3 changes: 2 additions & 1 deletion org_fedora_oscap/ks/oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ def _handle_error(self, exception):
self._terminate(msg)

else:
raise exception
msg = _("There was an unexpected problem with the supplied content.")
self._terminate(msg)

def setup(self, storage, ksdata, payload):
"""
Expand Down

0 comments on commit 01e7afd

Please sign in to comment.