libproxy: fix handling of SOCKS in async API, add tests
[platform/upstream/glib-networking.git] / proxy / tests / gnome.c
index 69f43ac..578ac49 100644 (file)
@@ -20,6 +20,8 @@
 #include <gio/gio.h>
 #include <gdesktop-enums.h>
 
+#include "common.c"
+
 #define GNOME_PROXY_SETTINGS_SCHEMA       "org.gnome.system.proxy"
 #define GNOME_PROXY_MODE_KEY              "mode"
 #define GNOME_PROXY_AUTOCONFIG_URL_KEY    "autoconfig-url"
@@ -83,9 +85,6 @@ test_proxy_uri (gpointer      fixture,
                gconstpointer user_data)
 {
   GSettings *settings, *child;
-  GProxyResolver *resolver;
-  gchar **proxies;
-  GError *error = NULL;
 
   settings = g_settings_new (GNOME_PROXY_SETTINGS_SCHEMA);
   g_settings_set_enum (settings, GNOME_PROXY_MODE_KEY, G_DESKTOP_PROXY_MODE_MANUAL);
@@ -108,45 +107,7 @@ test_proxy_uri (gpointer      fixture,
 
   g_object_unref (settings);
 
-  resolver = g_proxy_resolver_get_default ();
-
-  proxies = g_proxy_resolver_lookup (resolver, "http://one.example.com/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 1);
-  g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
-  g_strfreev (proxies);
-
-  proxies = g_proxy_resolver_lookup (resolver, "HTTPS://uppercase.example.com/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 1);
-  g_assert_cmpstr (proxies[0], ==, "http://proxy-s.example.com:7070");
-  g_strfreev (proxies);
-
-  /* Because we set use_same_proxy = TRUE, unknown protocols will use
-   * the http proxy by default.
-   */
-  proxies = g_proxy_resolver_lookup (resolver, "htt://missing-letter.example.com/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 1);
-  g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
-  g_strfreev (proxies);
-
-  proxies = g_proxy_resolver_lookup (resolver, "ftps://extra-letter.example.com/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 1);
-  g_assert_cmpstr (proxies[0], ==, "http://proxy.example.com:8080");
-  g_strfreev (proxies);
-
-  proxies = g_proxy_resolver_lookup (resolver, "ftp://five.example.com/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 1);
-  g_assert_cmpstr (proxies[0], ==, "ftp://proxy-f.example.com:6060");
-  g_strfreev (proxies);
+  test_proxy_uri_common ();
 }
 
 static void
@@ -154,10 +115,7 @@ test_proxy_socks (gpointer      fixture,
                  gconstpointer user_data)
 {
   GSettings *settings, *child;
-  GProxyResolver *resolver;
   const gchar *ignore_hosts[2] = { "127.0.0.1", NULL };
-  gchar **proxies;
-  GError *error = NULL;
 
   settings = g_settings_new (GNOME_PROXY_SETTINGS_SCHEMA);
   g_settings_set_enum (settings, GNOME_PROXY_MODE_KEY, G_DESKTOP_PROXY_MODE_MANUAL);
@@ -170,107 +128,14 @@ test_proxy_socks (gpointer      fixture,
   g_object_unref (child);
   g_object_unref (settings);
 
-  resolver = g_proxy_resolver_get_default ();
-
-  proxies = g_proxy_resolver_lookup (resolver, "http://one.example.com/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 3);
-  g_assert_cmpstr (proxies[0], ==, "socks5://proxy.example.com:1234");
-  g_assert_cmpstr (proxies[1], ==, "socks4a://proxy.example.com:1234");
-  g_assert_cmpstr (proxies[2], ==, "socks4://proxy.example.com:1234");
-  g_strfreev (proxies);
-
-  proxies = g_proxy_resolver_lookup (resolver, "wednesday://two.example.com/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 3);
-  g_assert_cmpstr (proxies[0], ==, "socks5://proxy.example.com:1234");
-  g_assert_cmpstr (proxies[1], ==, "socks4a://proxy.example.com:1234");
-  g_assert_cmpstr (proxies[2], ==, "socks4://proxy.example.com:1234");
-  g_strfreev (proxies);
-
-  proxies = g_proxy_resolver_lookup (resolver, "http://127.0.0.1/",
-                                     NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (g_strv_length (proxies), ==, 1);
-  g_assert_cmpstr (proxies[0], ==, "direct://");
-  g_strfreev (proxies);
+  test_proxy_socks_common ();
 }
 
-static const char *ignore_hosts[] = {
-  ".bbb.xx",
-  "*.ccc.xx",
-  "ddd.xx",
-  "*.eee.xx:8000",
-  "127.0.0.0/24",
-  "10.0.0.1:8000",
-  "::1",
-  "fe80::/10"
-};
-static const int n_ignore_hosts = G_N_ELEMENTS (ignore_hosts);
-
-static const struct {
-  const char *uri;
-  const char *proxy;
-} ignore_tests[] = {
-  { "http://aaa.xx/",                   "http://localhost:8080" },
-  { "http://aaa.xx:8000/",              "http://localhost:8080" },
-  { "http://www.aaa.xx/",               "http://localhost:8080" },
-  { "http://www.aaa.xx:8000/",          "http://localhost:8080" },
-  { "https://aaa.xx/",                  "http://localhost:8080" },
-  { "http://bbb.xx/",                   "direct://" },
-  { "http://www.bbb.xx/",               "direct://" },
-  { "http://bbb.xx:8000/",              "direct://" },
-  { "http://www.bbb.xx:8000/",          "direct://" },
-  { "https://bbb.xx/",                  "direct://" },
-  { "http://nobbb.xx/",          "http://localhost:8080" },
-  { "http://www.nobbb.xx/",      "http://localhost:8080" },
-  { "http://nobbb.xx:8000/",     "http://localhost:8080" },
-  { "http://www.nobbb.xx:8000/", "http://localhost:8080" },
-  { "https://nobbb.xx/",         "http://localhost:8080" },
-  { "http://ccc.xx/",                   "direct://" },
-  { "http://www.ccc.xx/",               "direct://" },
-  { "http://ccc.xx:8000/",              "direct://" },
-  { "http://www.ccc.xx:8000/",          "direct://" },
-  { "https://ccc.xx/",                  "direct://" },
-  { "http://ddd.xx/",                   "direct://" },
-  { "http://ddd.xx:8000/",              "direct://" },
-  { "http://www.ddd.xx/",               "direct://" },
-  { "http://www.ddd.xx:8000/",          "direct://" },
-  { "https://ddd.xx/",                  "direct://" },
-  { "http://eee.xx/",                   "http://localhost:8080" },
-  { "http://eee.xx:8000/",              "direct://" },
-  { "http://www.eee.xx/",               "http://localhost:8080" },
-  { "http://www.eee.xx:8000/",          "direct://" },
-  { "https://eee.xx/",                  "http://localhost:8080" },
-  { "http://1.2.3.4/",                  "http://localhost:8080" },
-  { "http://127.0.0.1/",                "direct://" },
-  { "http://127.0.0.2/",                "direct://" },
-  { "http://127.0.0.255/",              "direct://" },
-  { "http://127.0.1.0/",                "http://localhost:8080" },
-  { "http://10.0.0.1/",                 "http://localhost:8080" },
-  { "http://10.0.0.1:8000/",            "direct://" },
-  { "http://[::1]/",                    "direct://" },
-  { "http://[::1]:80/",                 "direct://" },
-  { "http://[::1:1]/",                  "http://localhost:8080" },
-  { "http://[::1:1]:80/",               "http://localhost:8080" },
-  { "http://[fe80::1]/",                "direct://" },
-  { "http://[fe80::1]:80/",             "direct://" },
-  { "http://[fec0::1]/",                "http://localhost:8080" },
-  { "http://[fec0::1]:80/",             "http://localhost:8080" }
-};
-static const int n_ignore_tests = G_N_ELEMENTS (ignore_tests);
-
 static void
 test_proxy_ignore (gpointer      fixture,
                   gconstpointer user_data)
 {
   GSettings *settings, *http;
-  GProxyResolver *resolver;
-  GError *error = NULL;
-  char **proxies;
-  int i;
 
   settings = g_settings_new (GNOME_PROXY_SETTINGS_SCHEMA);
   g_settings_set_enum (settings, GNOME_PROXY_MODE_KEY, G_DESKTOP_PROXY_MODE_MANUAL);
@@ -284,17 +149,7 @@ test_proxy_ignore (gpointer      fixture,
   g_object_unref (http);
   g_object_unref (settings);
 
-  resolver = g_proxy_resolver_get_default ();
-
-  for (i = 0; i < n_ignore_tests; i++)
-    {
-      proxies = g_proxy_resolver_lookup (resolver, ignore_tests[i].uri,
-                                        NULL, &error);
-      g_assert_no_error (error);
-
-      g_assert_cmpstr (proxies[0], ==, ignore_tests[i].proxy);
-      g_strfreev (proxies);
-    }
+  test_proxy_ignore_common (FALSE);
 }
 
 int