Blob Blame History Raw
From 6f444b269f48dd3fa4e92d5ff8c17892558f7d63 Mon Sep 17 00:00:00 2001
From: Vratislav Podzimek <vpodzime@redhat.com>
Date: Mon, 6 Jul 2015 14:31:36 +0200
Subject: [PATCH 7/9] Better handle unsupported URL types (#1232631)

If a URL that is not supported by the addon is given, it needs to report that as
an issue instead of crashing.

Unsupported URLs are either incomplete or not starting with a recognized and
supported protocol type.

Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
---
 org_fedora_oscap/gui/spokes/oscap.py | 15 +++++++++++++++
 org_fedora_oscap/ks/oscap.py         |  8 +++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/org_fedora_oscap/gui/spokes/oscap.py b/org_fedora_oscap/gui/spokes/oscap.py
index 5e5a43e..46b742b 100644
--- a/org_fedora_oscap/gui/spokes/oscap.py
+++ b/org_fedora_oscap/gui/spokes/oscap.py
@@ -41,6 +41,8 @@ from pyanaconda.ui.communication import hubQ
 from pyanaconda.ui.gui.utils import gtk_action_wait, really_hide, really_show
 from pyanaconda.ui.gui.utils import set_treeview_selection, fire_gtk_action
 
+from pykickstart.errors import KickstartValueError
+
 # pylint: disable-msg=E0611
 from gi.repository import Gdk
 
@@ -287,6 +289,11 @@ class OSCAPSpoke(NormalSpoke):
                 with self._fetch_flag_lock:
                     self._fetching = False
                 return
+            except KickstartValueError:
+                self._invalid_url()
+                with self._fetch_flag_lock:
+                    self._fetching = False
+                return
 
         # pylint: disable-msg=E1101
         hubQ.send_message(self.__class__.__name__,
@@ -620,6 +627,14 @@ class OSCAPSpoke(NormalSpoke):
         self._wrong_content()
 
     @gtk_action_wait
+    def _invalid_url(self):
+        """Callback for informing user about provided URL invalidity."""
+
+        self._progress_label.set_markup("<b>%s</b>" % _("Invalid or unsupported content "
+                                                        "URL, please enter a different one."))
+        self._wrong_content()
+
+    @gtk_action_wait
     def _data_fetch_failed(self):
         """Adapts the UI if fetching data from entered URL failed"""
 
diff --git a/org_fedora_oscap/ks/oscap.py b/org_fedora_oscap/ks/oscap.py
index 1b44913..d0c39b8 100644
--- a/org_fedora_oscap/ks/oscap.py
+++ b/org_fedora_oscap/ks/oscap.py
@@ -275,7 +275,13 @@ class OSCAPdata(AddonData):
         if self.content_type == "scap-security-guide":
             raise ValueError("Using scap-security-guide, no single content file")
 
-        parts = self.content_url.rsplit("/", 1)
+        rest = "/anonymous_content"
+        for prefix in SUPPORTED_URL_PREFIXES:
+            if self.content_url.startswith(prefix):
+                rest = self.content_url[len(prefix):]
+                break
+
+        parts = rest.rsplit("/", 1)
         if len(parts) != 2:
             msg = "Unsupported url '%s' in the %s addon" % (self.content_url,
                                                             self.name)
-- 
2.4.3