From 6ebd5a882251a6255f39145843a95974b9dd0797 Mon Sep 17 00:00:00 2001
From: Jan-Michael Brummer <jan.brummer@tabos.org>
Date: Thu, 26 Oct 2023 20:50:44 +0200
Subject: [PATCH 1/2] Improve test coverage (#256)

Co-authored-by: Jan-Michael Brummer <jan-michael.brummer1@volkswagen.de>
---
 src/backend/plugins/config-env/config-env.c   |  7 ---
 .../plugins/config-gnome/config-gnome.c       | 13 +----
 src/backend/plugins/config-kde/config-kde.c   | 16 -------
 src/backend/plugins/config-osx/config-osx.c   |  9 +---
 .../config-sysconfig/config-sysconfig.c       | 16 -------
 .../plugins/config-windows/config-windows.c   |  9 +---
 src/backend/px-manager.c                      | 22 ++++-----
 src/backend/px-manager.h                      |  6 +--
 src/backend/px-plugin-config.h                |  1 -
 src/libproxy/proxy.c                          |  6 +--
 tests/config-env-test.c                       |  5 +-
 tests/config-gnome-test.c                     | 47 +++++++++++++++----
 tests/config-kde-test.c                       | 20 ++++----
 tests/config-osx-test.c                       |  4 +-
 tests/config-sysconfig-test.c                 | 42 ++++++++++++++++-
 tests/config-windows-test.c                   |  4 +-
 tests/data/px-manager-sample.pac              |  4 ++
 tests/data/sample-sysconfig-proxy-invalid     |  1 +
 tests/libproxy-test.c                         | 18 +++++++
 tests/px-manager-test.c                       | 38 +++++++++------
 20 files changed, 158 insertions(+), 130 deletions(-)
 create mode 100644 tests/data/sample-sysconfig-proxy-invalid

diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c
index 8ef886e..deb80ec 100644
--- a/src/backend/plugins/config-env/config-env.c
+++ b/src/backend/plugins/config-env/config-env.c
@@ -90,12 +90,6 @@ px_config_env_class_init (PxConfigEnvClass *klass)
   g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
 }
 
-static gboolean
-px_config_env_is_available (PxConfig *self)
-{
-  return TRUE;
-}
-
 static void
 px_config_env_get_config (PxConfig     *config,
                           GUri         *uri,
@@ -142,6 +136,5 @@ px_config_iface_init (PxConfigInterface *iface)
 {
   iface->name = "config-env";
   iface->priority = PX_CONFIG_PRIORITY_FIRST;
-  iface->is_available = px_config_env_is_available;
   iface->get_config = px_config_env_get_config;
 }
diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c
index 820827b..52e812e 100644
--- a/src/backend/plugins/config-gnome/config-gnome.c
+++ b/src/backend/plugins/config-gnome/config-gnome.c
@@ -58,7 +58,7 @@ static void
 px_config_gnome_init (PxConfigGnome *self)
 {
   GSettingsSchemaSource *source;
-  GSettingsSchema *proxy_schema;
+  g_autoptr (GSettingsSchema) proxy_schema = NULL;
   const char *desktops;
 
   self->available = FALSE;
@@ -80,8 +80,6 @@ px_config_gnome_init (PxConfigGnome *self)
   proxy_schema = g_settings_schema_source_lookup (source, "org.gnome.system.proxy", TRUE);
 
   self->available = proxy_schema != NULL;
-  g_clear_pointer (&proxy_schema, g_settings_schema_unref);
-
   if (!self->available)
     return;
 
@@ -135,14 +133,6 @@ px_config_gnome_class_init (PxConfigGnomeClass *klass)
   g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
 }
 
-static gboolean
-px_config_gnome_is_available (PxConfig *config)
-{
-  PxConfigGnome *self = PX_CONFIG_GNOME (config);
-
-  return self->available;
-}
-
 static void
 store_response (GStrvBuilder *builder,
                 const char   *type,
@@ -244,6 +234,5 @@ px_config_iface_init (PxConfigInterface *iface)
 {
   iface->name = "config-gnome";
   iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
-  iface->is_available = px_config_gnome_is_available;
   iface->get_config = px_config_gnome_get_config;
 }
diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c
index 3b1bb6b..e370728 100644
--- a/src/backend/plugins/config-kde/config-kde.c
+++ b/src/backend/plugins/config-kde/config-kde.c
@@ -103,11 +103,6 @@ px_config_kde_set_config_file (PxConfigKde *self,
   self->config_file = proxy_file ? g_strdup (proxy_file) : g_build_filename (g_get_user_config_dir (), "kioslaverc", NULL);
 
   file = g_file_new_for_path (self->config_file);
-  if (!file) {
-    g_debug ("%s: Could not create file for %s", __FUNCTION__, self->config_file);
-    return;
-  }
-
   istr = g_file_read (file, NULL, NULL);
   if (!istr) {
     g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file);
@@ -115,8 +110,6 @@ px_config_kde_set_config_file (PxConfigKde *self,
   }
 
   dstr = g_data_input_stream_new (G_INPUT_STREAM (istr));
-  if (!dstr)
-    return;
 
   g_clear_object (&self->monitor);
   self->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error);
@@ -237,14 +230,6 @@ px_config_kde_class_init (PxConfigKdeClass *klass)
   g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
 }
 
-static gboolean
-px_config_kde_is_available (PxConfig *config)
-{
-  PxConfigKde *self = PX_CONFIG_KDE (config);
-
-  return self->available;
-}
-
 static void
 px_config_kde_get_config (PxConfig     *config,
                           GUri         *uri,
@@ -301,6 +286,5 @@ px_config_iface_init (PxConfigInterface *iface)
 {
   iface->name = "config-kde";
   iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
-  iface->is_available = px_config_kde_is_available;
   iface->get_config = px_config_kde_get_config;
 }
diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c
index 16813a0..224f8a4 100644
--- a/src/backend/plugins/config-osx/config-osx.c
+++ b/src/backend/plugins/config-osx/config-osx.c
@@ -88,12 +88,6 @@ px_config_osx_class_init (PxConfigOsXClass *klass)
   g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
 }
 
-static gboolean
-px_config_osx_is_available (PxConfig *self)
-{
-  return TRUE;
-}
-
 static CFNumberRef
 getobj (CFDictionaryRef  settings,
         char            *key)
@@ -309,7 +303,7 @@ px_config_osx_get_config (PxConfig     *self,
   if (getbool (proxies, "ProxyAutoConfigEnable")) {
     CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString");
     g_autofree char *tmp = str (ref);
-    GUri *tmp_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL);
+    GUri *tmp_uri = g_uri_parse (tmp, G_URI_FLAGS_NONE, NULL);
 
     if (tmp_uri) {
       g_autofree char *ret = g_strdup_printf ("pac+%s", g_uri_to_string (tmp_uri));
@@ -336,6 +330,5 @@ px_config_iface_init (PxConfigInterface *iface)
 {
   iface->name = "config-osx";
   iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
-  iface->is_available = px_config_osx_is_available;
   iface->get_config = px_config_osx_get_config;
 }
diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c
index c640f1c..18daa61 100644
--- a/src/backend/plugins/config-sysconfig/config-sysconfig.c
+++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c
@@ -85,11 +85,6 @@ px_config_sysconfig_set_config_file (PxConfigSysConfig *self,
   self->available = FALSE;
 
   file = g_file_new_for_path (self->config_file);
-  if (!file) {
-    g_debug ("%s: Could not create file for %s", __FUNCTION__, self->config_file);
-    return;
-  }
-
   istr = g_file_read (file, NULL, NULL);
   if (!istr) {
     g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file);
@@ -97,8 +92,6 @@ px_config_sysconfig_set_config_file (PxConfigSysConfig *self,
   }
 
   dstr = g_data_input_stream_new (G_INPUT_STREAM (istr));
-  if (!dstr)
-    return;
 
   g_clear_object (&self->monitor);
   self->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error);
@@ -207,14 +200,6 @@ px_config_sysconfig_class_init (PxConfigSysConfigClass *klass)
   g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
 }
 
-static gboolean
-px_config_sysconfig_is_available (PxConfig *config)
-{
-  PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (config);
-
-  return self->available;
-}
-
 static void
 px_config_sysconfig_get_config (PxConfig     *config,
                                 GUri         *uri,
@@ -247,6 +232,5 @@ px_config_iface_init (PxConfigInterface *iface)
 {
   iface->name = "config-sysconfig";
   iface->priority = PX_CONFIG_PRIORITY_LAST;
-  iface->is_available = px_config_sysconfig_is_available;
   iface->get_config = px_config_sysconfig_get_config;
 }
diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c
index cc9c92d..5b55f1c 100644
--- a/src/backend/plugins/config-windows/config-windows.c
+++ b/src/backend/plugins/config-windows/config-windows.c
@@ -94,12 +94,6 @@ px_config_windows_class_init (PxConfigWindowsClass *klass)
   g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
 }
 
-static gboolean
-px_config_windows_is_available (PxConfig *self)
-{
-  return TRUE;
-}
-
 static gboolean
 get_registry (const char  *key,
               const char  *name,
@@ -213,7 +207,7 @@ px_config_windows_get_config (PxConfig     *self,
   /* PAC */
   if (is_enabled (W32REG_OFFSET_PAC) && get_registry (W32REG_BASEKEY, "AutoConfigURL", &tmp, NULL, NULL)) {
     g_autofree char *pac_uri = g_strconcat ("pac+", tmp, NULL);
-    GUri *ac_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL);
+    GUri *ac_uri = g_uri_parse (tmp, G_URI_FLAGS_NONE, NULL);
 
     if (ac_uri) {
       px_strv_builder_add_proxy (builder, pac_uri);
@@ -247,6 +241,5 @@ px_config_iface_init (PxConfigInterface *iface)
 {
   iface->name = "config-windows";
   iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
-  iface->is_available = px_config_windows_is_available;
   iface->get_config = px_config_windows_get_config;
 }
diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c
index dc63b37..83d2fb6 100644
--- a/src/backend/px-manager.c
+++ b/src/backend/px-manager.c
@@ -440,16 +440,14 @@ px_manager_pac_download (PxManager  *self,
  * px_manager_get_configuration:
  * @self: a px manager
  * @uri: PAC uri
- * @error: a #GError
  *
  * Get raw proxy configuration for gien @uri.
  *
  * Returns: (transfer full) (nullable): a newly created `GStrv` containing configuration data for @uri.
  */
 char **
-px_manager_get_configuration (PxManager  *self,
-                              GUri       *uri,
-                              GError    **error)
+px_manager_get_configuration (PxManager *self,
+                              GUri      *uri)
 {
   g_autoptr (GStrvBuilder) builder = g_strv_builder_new ();
 
@@ -494,7 +492,7 @@ px_manager_run_pac (PxPacRunner  *pacrunner,
       server = word_split[1];
 
       uri_string = g_strconcat ("http://", server, NULL);
-      proxy_uri = g_uri_parse (uri_string, G_URI_FLAGS_PARSE_RELAXED, NULL);
+      proxy_uri = g_uri_parse (uri_string, G_URI_FLAGS_NONE, NULL);
       if (!proxy_uri)
         continue;
 
@@ -535,7 +533,7 @@ px_manager_expand_wpad (PxManager *self,
     }
 
     if (!self->pac_data) {
-      GUri *wpad_url = g_uri_parse ("http://wpad/wpad.dat", G_URI_FLAGS_PARSE_RELAXED, NULL);
+      GUri *wpad_url = g_uri_parse ("http://wpad/wpad.dat", G_URI_FLAGS_NONE, NULL);
 
       g_debug ("%s: Trying to find the PAC using WPAD...", __FUNCTION__);
       self->pac_url = g_uri_to_string (wpad_url);
@@ -621,18 +619,18 @@ px_manager_expand_pac (PxManager *self,
  * Returns: (transfer full) (nullable): a newly created `GStrv` containing proxy related information.
  */
 char **
-px_manager_get_proxies_sync (PxManager   *self,
-                             const char  *url,
-                             GError     **error)
+px_manager_get_proxies_sync (PxManager  *self,
+                             const char *url)
 {
   g_autoptr (GStrvBuilder) builder = NULL;
   g_autoptr (GUri) uri = NULL;
   g_auto (GStrv) config = NULL;
+  g_autoptr (GError) error = NULL;
 
   g_mutex_lock (&self->mutex);
 
   builder = g_strv_builder_new ();
-  uri = g_uri_parse (url, G_URI_FLAGS_PARSE_RELAXED, error);
+  uri = g_uri_parse (url, G_URI_FLAGS_NONE, &error);
 
   g_debug ("%s: url=%s online=%d", __FUNCTION__, url ? url : "?", self->online);
   if (!uri || !self->online) {
@@ -641,10 +639,10 @@ px_manager_get_proxies_sync (PxManager   *self,
     return g_strv_builder_end (builder);
   }
 
-  config = px_manager_get_configuration (self, uri, error);
+  config = px_manager_get_configuration (self, uri);
 
   for (int idx = 0; idx < g_strv_length (config); idx++) {
-    GUri *conf_url = g_uri_parse (config[idx], G_URI_FLAGS_PARSE_RELAXED, NULL);
+    GUri *conf_url = g_uri_parse (config[idx], G_URI_FLAGS_NONE, NULL);
 
     g_debug ("%s: Config[%d] = %s", __FUNCTION__, idx, config[idx]);
 
diff --git a/src/backend/px-manager.h b/src/backend/px-manager.h
index 558ddba..9a1815a 100644
--- a/src/backend/px-manager.h
+++ b/src/backend/px-manager.h
@@ -41,15 +41,13 @@ PxManager *px_manager_new (void);
 PxManager *px_manager_new_with_options (const char *optname1, ...);
 
 char **px_manager_get_proxies_sync (PxManager   *self,
-                                    const char  *url,
-                                    GError     **error);
+                                    const char  *url);
 
 GBytes *px_manager_pac_download (PxManager  *self,
                                  const char *uri);
 
 char **px_manager_get_configuration (PxManager  *self,
-                                     GUri       *uri,
-                                     GError    **error);
+                                     GUri       *uri);
 
 void px_strv_builder_add_proxy (GStrvBuilder *builder,
                                 const char   *value);
diff --git a/src/backend/px-plugin-config.h b/src/backend/px-plugin-config.h
index 6958df6..6a16e7b 100644
--- a/src/backend/px-plugin-config.h
+++ b/src/backend/px-plugin-config.h
@@ -41,7 +41,6 @@ struct _PxConfigInterface
   const char *name;
   gint priority;
 
-  gboolean (*is_available) (PxConfig *self);
   void (*get_config) (PxConfig *self, GUri *uri, GStrvBuilder *builder);
 };
 
diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c
index 6cf7974..6b959f1 100644
--- a/src/libproxy/proxy.c
+++ b/src/libproxy/proxy.c
@@ -56,12 +56,8 @@ px_proxy_factory_get_proxies (pxProxyFactory *self,
                               const char     *url)
 {
   g_auto (GStrv) result = NULL;
-  g_autoptr (GError) error = NULL;
-
-  result = px_manager_get_proxies_sync (self->manager, url, &error);
-  if (error)
-    g_warning ("Could not query proxy: %s", error->message);
 
+  result = px_manager_get_proxies_sync (self->manager, url);
   return g_steal_pointer (&result);
 }
 
diff --git a/tests/config-env-test.c b/tests/config-env-test.c
index f1be1a3..31f37fb 100644
--- a/tests/config-env-test.c
+++ b/tests/config-env-test.c
@@ -54,6 +54,7 @@ static const ConfigEnvTest config_env_test_set[] = {
   { "HTTPS_PROXY", "http://127.0.0.1:8080", NULL, "http://www.example.com", FALSE},
   { "HTTPS_PROXY", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", FALSE},
   { "https_proxy", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", FALSE},
+  { "https_proxy", "http://127.0.0.1:8080", NULL, "https://www.example.com", TRUE},
   { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "https://www.example.com", FALSE},
   { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "http://www.example.com", FALSE},
   { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", TRUE},
@@ -88,8 +89,8 @@ test_config_env (void)
     manager = px_test_manager_new ("config-env", NULL);
     g_clear_error (&error);
 
-    uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error);
-    config = px_manager_get_configuration (manager, uri, &error);
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
+    config = px_manager_get_configuration (manager, uri);
     if (test.config_is_proxy)
       g_assert_cmpstr (config[0], ==, test.proxy);
     else
diff --git a/tests/config-gnome-test.c b/tests/config-gnome-test.c
index f80914a..677a3e9 100644
--- a/tests/config-gnome-test.c
+++ b/tests/config-gnome-test.c
@@ -73,6 +73,34 @@ fixture_teardown (Fixture       *fixture,
 {
 }
 
+static void
+test_config_gnome_none (Fixture    *self,
+                        const void *user_data)
+{
+  g_autoptr (PxManager) manager = NULL;
+  g_autoptr (GError) error = NULL;
+  g_autoptr (GUri) uri = NULL;
+  g_auto (GStrv) config = NULL;
+
+  g_settings_set_strv (self->proxy_settings, "ignore-hosts", NULL);
+  g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_NONE);
+
+  manager = px_test_manager_new ("config-gnome", NULL);
+  g_clear_error (&error);
+
+  uri = g_uri_parse ("https://127.0.0.1", G_URI_FLAGS_NONE, &error);
+  if (!uri) {
+    g_warning ("Could not parse url: %s", error ? error->message : "");
+    g_assert_not_reached ();
+  }
+
+  config = px_manager_get_configuration (manager, uri);
+  g_assert_nonnull (config);
+  g_assert_null (config[0]);
+
+  g_clear_object (&manager);
+}
+
 static void
 test_config_gnome_manual (Fixture    *self,
                           const void *user_data)
@@ -100,13 +128,13 @@ test_config_gnome_manual (Fixture    *self,
     manager = px_test_manager_new ("config-gnome", NULL);
     g_clear_error (&error);
 
-    uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error);
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
     if (!uri) {
       g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : "");
       g_assert_not_reached ();
     }
 
-    config = px_manager_get_configuration (manager, uri, &error);
+    config = px_manager_get_configuration (manager, uri);
     g_assert_cmpstr (config[0], ==, test.expected_return);
 
     g_clear_object (&manager);
@@ -132,9 +160,9 @@ test_config_gnome_manual_auth (Fixture    *self,
   manager = px_test_manager_new ("config-gnome", NULL);
   g_clear_error (&error);
 
-  uri = g_uri_parse ("http://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
+  uri = g_uri_parse ("http://www.example.com", G_URI_FLAGS_NONE, &error);
 
-  config = px_manager_get_configuration (manager, uri, &error);
+  config = px_manager_get_configuration (manager, uri);
   g_assert_cmpstr (config[0], ==, "http://test:pwd@127.0.0.1:9876");
 }
 
@@ -151,12 +179,12 @@ test_config_gnome_auto (Fixture    *self,
   g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO);
   g_settings_set_string (self->proxy_settings, "autoconfig-url", "");
 
-  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
-  config = px_manager_get_configuration (manager, uri, &error);
+  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);
+  config = px_manager_get_configuration (manager, uri);
   g_assert_cmpstr (config[0], ==, "wpad://");
 
   g_settings_set_string (self->proxy_settings, "autoconfig-url", "http://127.0.0.1:3435");
-  config = px_manager_get_configuration (manager, uri, &error);
+  config = px_manager_get_configuration (manager, uri);
   g_assert_cmpstr (config[0], ==, "pac+http://127.0.0.1:3435");
 }
 
@@ -179,8 +207,8 @@ test_config_gnome_fail (Fixture    *self,
   g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO);
   g_settings_set_string (self->proxy_settings, "autoconfig-url", "");
 
-  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
-  config = px_manager_get_configuration (manager, uri, &error);
+  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);
+  config = px_manager_get_configuration (manager, uri);
   g_assert_null (config[0]);
 }
 
@@ -192,6 +220,7 @@ main (int    argc,
 
   g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
 
+  g_test_add ("/config/gnome/none", Fixture, NULL, fixture_setup, test_config_gnome_none, fixture_teardown);
   g_test_add ("/config/gnome/manual", Fixture, NULL, fixture_setup, test_config_gnome_manual, fixture_teardown);
   g_test_add ("/config/gnome/manual_auth", Fixture, NULL, fixture_setup, test_config_gnome_manual_auth, fixture_teardown);
   g_test_add ("/config/gnome/auto", Fixture, NULL, fixture_setup, test_config_gnome_auto, fixture_teardown);
diff --git a/tests/config-kde-test.c b/tests/config-kde-test.c
index 07f83f9..84e9795 100644
--- a/tests/config-kde-test.c
+++ b/tests/config-kde-test.c
@@ -67,13 +67,13 @@ test_config_kde_disabled (void)
     manager = px_test_manager_new ("config-kde", path);
     g_clear_error (&error);
 
-    uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error);
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
     if (!uri) {
       g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : "");
       g_assert_not_reached ();
     }
 
-    config = px_manager_get_configuration (manager, uri, &error);
+    config = px_manager_get_configuration (manager, uri);
     g_assert_cmpstr (config[0], !=, test.proxy);
 
     g_clear_object (&manager);
@@ -96,13 +96,13 @@ test_config_kde_manual (void)
     manager = px_test_manager_new ("config-kde", path);
     g_clear_error (&error);
 
-    uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error);
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
     if (!uri) {
       g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : "");
       g_assert_not_reached ();
     }
 
-    config = px_manager_get_configuration (manager, uri, &error);
+    config = px_manager_get_configuration (manager, uri);
     if (test.success)
       g_assert_cmpstr (config[0], ==, test.proxy);
     else
@@ -128,13 +128,13 @@ test_config_kde_wpad (void)
     manager = px_test_manager_new ("config-kde", path);
     g_clear_error (&error);
 
-    uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error);
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
     if (!uri) {
       g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : "");
       g_assert_not_reached ();
     }
 
-    config = px_manager_get_configuration (manager, uri, &error);
+    config = px_manager_get_configuration (manager, uri);
     if (test.success)
       g_assert_cmpstr (config[0], ==, "wpad://");
     else
@@ -160,13 +160,13 @@ test_config_kde_pac (void)
     manager = px_test_manager_new ("config-kde", path);
     g_clear_error (&error);
 
-    uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error);
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
     if (!uri) {
       g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : "");
       g_assert_not_reached ();
     }
 
-    config = px_manager_get_configuration (manager, uri, &error);
+    config = px_manager_get_configuration (manager, uri);
     if (test.success)
       g_assert_cmpstr (config[0], ==, "pac+http://127.0.0.1/px-manager-sample.pac");
     else
@@ -190,9 +190,9 @@ test_config_kde_fail (void)
 
   manager = px_test_manager_new ("config-kde", path);
 
-  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
+  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);
 
-  config = px_manager_get_configuration (manager, uri, &error);
+  config = px_manager_get_configuration (manager, uri);
   g_print ("%s", config[0]);
   g_assert_null (config[0]);
 }
diff --git a/tests/config-osx-test.c b/tests/config-osx-test.c
index cdb8a72..25e66ad 100644
--- a/tests/config-osx-test.c
+++ b/tests/config-osx-test.c
@@ -34,8 +34,8 @@ test_config_osx (void)
   manager = px_test_manager_new ("config-osx", NULL);
   g_clear_error (&error);
 
-  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
-  config = px_manager_get_configuration (manager, uri, &error);
+  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);
+  config = px_manager_get_configuration (manager, uri);
   g_assert_nonnull (config);
   g_assert_null (config[0]);
 }
diff --git a/tests/config-sysconfig-test.c b/tests/config-sysconfig-test.c
index 40c0b92..70e81b6 100644
--- a/tests/config-sysconfig-test.c
+++ b/tests/config-sysconfig-test.c
@@ -34,6 +34,11 @@ static const ConfigSysConfigTest config_sysconfig_test_set[] = {
   { "http://www.example.com", "http://127.0.0.1:8080", TRUE},
   { "ftp://www.example.com", "http://127.0.0.1:8080", TRUE},
   { "http://localhost:1234", "http://127.0.0.1:8080", FALSE},
+  { "tcp://localhost:1234", "http://127.0.0.1:8080", FALSE},
+};
+
+static const ConfigSysConfigTest config_sysconfig_test_invalid_set[] = {
+  { "https://www.example.com", "http://127.0.0.1:8080", FALSE},
 };
 
 static void
@@ -52,13 +57,45 @@ test_config_sysconfig (void)
     manager = px_test_manager_new ("config-sysconfig", path);
     g_clear_error (&error);
 
-    uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error);
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
+    if (!uri) {
+      g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : "");
+      g_assert_not_reached ();
+    }
+
+    config = px_manager_get_configuration (manager, uri);
+    if (test.success)
+      g_assert_cmpstr (config[0], ==, test.proxy);
+    else
+      g_assert_cmpstr (config[0], !=, test.proxy);
+
+    g_clear_object (&manager);
+  }
+}
+
+static void
+test_config_sysconfig_invalid (void)
+{
+  int idx;
+
+  for (idx = 0; idx < G_N_ELEMENTS (config_sysconfig_test_invalid_set); idx++) {
+    g_autoptr (PxManager) manager = NULL;
+    g_autoptr (GError) error = NULL;
+    g_autoptr (GUri) uri = NULL;
+    g_auto (GStrv) config = NULL;
+    ConfigSysConfigTest test = config_sysconfig_test_invalid_set[idx];
+    g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-sysconfig-proxy-invalid", NULL);
+
+    manager = px_test_manager_new ("config-sysconfig", path);
+    g_clear_error (&error);
+
+    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
     if (!uri) {
       g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : "");
       g_assert_not_reached ();
     }
 
-    config = px_manager_get_configuration (manager, uri, &error);
+    config = px_manager_get_configuration (manager, uri);
     if (test.success)
       g_assert_cmpstr (config[0], ==, test.proxy);
     else
@@ -75,6 +112,7 @@ main (int    argc,
   g_test_init (&argc, &argv, NULL);
 
   g_test_add_func ("/config/sysconfig", test_config_sysconfig);
+  g_test_add_func ("/config/sysconfig/invalid", test_config_sysconfig_invalid);
 
   return g_test_run ();
 }
diff --git a/tests/config-windows-test.c b/tests/config-windows-test.c
index 10d4b21..10d3d3d 100644
--- a/tests/config-windows-test.c
+++ b/tests/config-windows-test.c
@@ -34,8 +34,8 @@ test_config_windows (void)
   manager = px_test_manager_new ("config-windows", NULL);
   g_clear_error (&error);
 
-  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error);
-  config = px_manager_get_configuration (manager, uri, &error);
+  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);
+  config = px_manager_get_configuration (manager, uri);
   g_assert_nonnull (config);
   g_assert_nonnull (config[0]);
 }
diff --git a/tests/data/px-manager-sample.pac b/tests/data/px-manager-sample.pac
index d623f22..ee038f9 100644
--- a/tests/data/px-manager-sample.pac
+++ b/tests/data/px-manager-sample.pac
@@ -23,5 +23,9 @@ function FindProxyForURL(url, host)
   if (dnsDomainIs(host, "www.example.com"))
     return "PROXY 127.0.0.1:1983"
 
+  /* Invalid return */
+  if (dnsDomainIs(host, "192.168.10.8"))
+    return "PROXY !"
+
   return "PROXY 127.0.0.1:1981"
 }
diff --git a/tests/data/sample-sysconfig-proxy-invalid b/tests/data/sample-sysconfig-proxy-invalid
new file mode 100644
index 0000000..1f2b24e
--- /dev/null
+++ b/tests/data/sample-sysconfig-proxy-invalid
@@ -0,0 +1 @@
+PROXY_ENABLED="yes"
\ No newline at end of file
diff --git a/tests/libproxy-test.c b/tests/libproxy-test.c
index 00aac45..c024ed3 100644
--- a/tests/libproxy-test.c
+++ b/tests/libproxy-test.c
@@ -62,6 +62,22 @@ test_libproxy_setup (Fixture    *self,
   /* px_proxy_factory_free_proxies (proxies); */
 }
 
+static void
+test_libproxy_dup (Fixture    *self,
+                   const void *user_data)
+{
+  pxProxyFactory *dup = g_boxed_copy (PX_TYPE_PROXY_FACTORY, &self->pf);
+
+  g_assert_nonnull (dup);
+}
+
+static void
+test_libproxy_illegal_free (Fixture    *self,
+                            const void *user_data)
+{
+  px_proxy_factory_free_proxies (NULL);
+}
+
 int
 main (int    argc,
       char **argv)
@@ -69,6 +85,8 @@ main (int    argc,
   g_test_init (&argc, &argv, NULL);
 
   g_test_add ("/libproxy/setup", Fixture, NULL, fixture_setup, test_libproxy_setup, fixture_teardown);
+  g_test_add ("/libproxy/dup", Fixture, NULL, fixture_setup, test_libproxy_dup, fixture_teardown);
+  g_test_add ("/libproxy/illegal_free", Fixture, NULL, fixture_setup, test_libproxy_illegal_free, fixture_teardown);
 
   return g_test_run ();
 }
diff --git a/tests/px-manager-test.c b/tests/px-manager-test.c
index 311e632..e6935f8 100644
--- a/tests/px-manager-test.c
+++ b/tests/px-manager-test.c
@@ -199,15 +199,15 @@ test_get_proxies_direct (Fixture    *self,
 {
   g_auto (GStrv) config = NULL;
 
-  config = px_manager_get_proxies_sync (self->manager, "", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "direct://");
 
-  config = px_manager_get_proxies_sync (self->manager, "nonsense", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "nonsense");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "direct://");
 
-  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "direct://");
 }
@@ -218,7 +218,7 @@ test_get_proxies_nonpac (Fixture    *self,
 {
   g_auto (GStrv) config = NULL;
 
-  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "http://127.0.0.1:1983");
 }
@@ -229,26 +229,36 @@ get_proxies_pac (gpointer data)
   Fixture *self = data;
   g_auto (GStrv) config = NULL;
 
-  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "http://127.0.0.1:1983");
 
-  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.4", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.4");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "socks://127.0.0.1:1983");
 
-  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.5", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.5");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "socks4://127.0.0.1:1983");
 
-  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.6", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.6");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "socks4a://127.0.0.1:1983");
 
-  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.7", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.7");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "socks5://127.0.0.1:1983");
 
+  /* Invalid return URI */
+  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.8");
+  g_assert_nonnull (config);
+  g_assert_cmpstr (config[0], ==, "direct://");
+
+  /* Invalid input url */
+  config = px_manager_get_proxies_sync (self->manager, "invalid");
+  g_assert_nonnull (config);
+  g_assert_cmpstr (config[0], ==, "direct://");
+
   g_main_loop_quit (self->loop);
 
   return NULL;
@@ -270,7 +280,7 @@ get_wpad (gpointer data)
   Fixture *self = data;
   g_auto (GStrv) config = NULL;
 
-  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL);
+  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com");
   g_assert_nonnull (config);
   g_assert_cmpstr (config[0], ==, "direct://");
 
@@ -293,7 +303,7 @@ static void
 test_ignore_domain (Fixture    *self,
                     const void *user_data)
 {
-  g_autoptr (GUri) uri = g_uri_parse("http://10.10.1.12", G_URI_FLAGS_PARSE_RELAXED, NULL);
+  g_autoptr (GUri) uri = g_uri_parse("http://10.10.1.12", G_URI_FLAGS_NONE, NULL);
   char **ignore_list = g_malloc0 (sizeof (char *) * 2);
   gboolean ret;
 
@@ -319,7 +329,7 @@ static void
 test_ignore_domain_port (Fixture    *self,
                          const void *user_data)
 {
-  g_autoptr (GUri) uri = g_uri_parse("http://10.10.1.12:22", G_URI_FLAGS_PARSE_RELAXED, NULL);
+  g_autoptr (GUri) uri = g_uri_parse("http://10.10.1.12:22", G_URI_FLAGS_NONE, NULL);
   char **ignore_list = g_malloc0 (sizeof (char *) * 2);
   gboolean ret;
 
@@ -354,7 +364,7 @@ static void
 test_ignore_hostname (Fixture    *self,
                       const void *user_data)
 {
-  g_autoptr (GUri) uri = g_uri_parse("http://18.10.1.12", G_URI_FLAGS_PARSE_RELAXED, NULL);
+  g_autoptr (GUri) uri = g_uri_parse("http://18.10.1.12", G_URI_FLAGS_NONE, NULL);
   char **ignore_list = g_malloc0 (sizeof (char *) * 2);
   gboolean ret;
 
@@ -367,7 +377,7 @@ test_ignore_hostname (Fixture    *self,
   g_uri_unref (uri);
 
   /* Valid test */
-  uri = g_uri_parse("http://127.0.0.1", G_URI_FLAGS_PARSE_RELAXED, NULL);
+  uri = g_uri_parse("http://127.0.0.1", G_URI_FLAGS_NONE, NULL);
   ret = px_manager_is_ignore (uri, ignore_list);
   g_assert_false (ret);
 
-- 
2.34.1

