Blame SOURCES/unsup_url_handling_1232631.patch

fd2bce
From 6f444b269f48dd3fa4e92d5ff8c17892558f7d63 Mon Sep 17 00:00:00 2001
fd2bce
From: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
Date: Mon, 6 Jul 2015 14:31:36 +0200
fd2bce
Subject: [PATCH 7/9] Better handle unsupported URL types (#1232631)
fd2bce
fd2bce
If a URL that is not supported by the addon is given, it needs to report that as
fd2bce
an issue instead of crashing.
fd2bce
fd2bce
Unsupported URLs are either incomplete or not starting with a recognized and
fd2bce
supported protocol type.
fd2bce
fd2bce
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
---
fd2bce
 org_fedora_oscap/gui/spokes/oscap.py | 15 +++++++++++++++
fd2bce
 org_fedora_oscap/ks/oscap.py         |  8 +++++++-
fd2bce
 2 files changed, 22 insertions(+), 1 deletion(-)
fd2bce
fd2bce
diff --git a/org_fedora_oscap/gui/spokes/oscap.py b/org_fedora_oscap/gui/spokes/oscap.py
fd2bce
index 5e5a43e..46b742b 100644
fd2bce
--- a/org_fedora_oscap/gui/spokes/oscap.py
fd2bce
+++ b/org_fedora_oscap/gui/spokes/oscap.py
fd2bce
@@ -41,6 +41,8 @@ from pyanaconda.ui.communication import hubQ
fd2bce
 from pyanaconda.ui.gui.utils import gtk_action_wait, really_hide, really_show
fd2bce
 from pyanaconda.ui.gui.utils import set_treeview_selection, fire_gtk_action
fd2bce
 
fd2bce
+from pykickstart.errors import KickstartValueError
fd2bce
+
fd2bce
 # pylint: disable-msg=E0611
fd2bce
 from gi.repository import Gdk
fd2bce
 
fd2bce
@@ -287,6 +289,11 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
                 with self._fetch_flag_lock:
fd2bce
                     self._fetching = False
fd2bce
                 return
fd2bce
+            except KickstartValueError:
fd2bce
+                self._invalid_url()
fd2bce
+                with self._fetch_flag_lock:
fd2bce
+                    self._fetching = False
fd2bce
+                return
fd2bce
 
fd2bce
         # pylint: disable-msg=E1101
fd2bce
         hubQ.send_message(self.__class__.__name__,
fd2bce
@@ -620,6 +627,14 @@ class OSCAPSpoke(NormalSpoke):
fd2bce
         self._wrong_content()
fd2bce
 
fd2bce
     @gtk_action_wait
fd2bce
+    def _invalid_url(self):
fd2bce
+        """Callback for informing user about provided URL invalidity."""
fd2bce
+
fd2bce
+        self._progress_label.set_markup("%s" % _("Invalid or unsupported content "
fd2bce
+                                                        "URL, please enter a different one."))
fd2bce
+        self._wrong_content()
fd2bce
+
fd2bce
+    @gtk_action_wait
fd2bce
     def _data_fetch_failed(self):
fd2bce
         """Adapts the UI if fetching data from entered URL failed"""
fd2bce
 
fd2bce
diff --git a/org_fedora_oscap/ks/oscap.py b/org_fedora_oscap/ks/oscap.py
fd2bce
index 1b44913..d0c39b8 100644
fd2bce
--- a/org_fedora_oscap/ks/oscap.py
fd2bce
+++ b/org_fedora_oscap/ks/oscap.py
fd2bce
@@ -275,7 +275,13 @@ class OSCAPdata(AddonData):
fd2bce
         if self.content_type == "scap-security-guide":
fd2bce
             raise ValueError("Using scap-security-guide, no single content file")
fd2bce
 
fd2bce
-        parts = self.content_url.rsplit("/", 1)
fd2bce
+        rest = "/anonymous_content"
fd2bce
+        for prefix in SUPPORTED_URL_PREFIXES:
fd2bce
+            if self.content_url.startswith(prefix):
fd2bce
+                rest = self.content_url[len(prefix):]
fd2bce
+                break
fd2bce
+
fd2bce
+        parts = rest.rsplit("/", 1)
fd2bce
         if len(parts) != 2:
fd2bce
             msg = "Unsupported url '%s' in the %s addon" % (self.content_url,
fd2bce
                                                             self.name)
fd2bce
-- 
fd2bce
2.4.3
fd2bce