tests: souphttpsrc: Avoid deprecated ssl-ca-file property
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Tue, 20 Jun 2017 14:39:36 +0000 (16:39 +0200)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 29 Jun 2017 19:32:30 +0000 (15:32 -0400)
SoupSession's ssl-ca-file property is deprecated. Use the recommended
tls-database property.

This is a bit more complex as it requires creating a GTlsFileDatabase
object for an absolute (!) path to the CA certificates file.

https://bugzilla.gnome.org/show_bug.cgi?id=784005

tests/check/elements/souphttpsrc.c

index d5eefb9..40d4dbb 100644 (file)
@@ -125,8 +125,29 @@ run_test (gboolean use_https, const gchar * path, gint expected)
   g_object_set (src, "location", url, NULL);
   g_free (url);
 
+  if (use_https) {
+    GTlsDatabase *tlsdb;
+    GError *error = NULL;
+    gchar *path;
+
+    /* GTlsFileDatabase needs an absolute path. Using a relative one
+     * causes a warning from GLib-Net followed by a segfault in GnuTLS */
+    if (g_path_is_absolute (ssl_cert_file)) {
+      path = g_strdup (ssl_cert_file);
+    } else {
+      path = g_build_filename (g_get_current_dir (), ssl_cert_file, NULL);
+    }
+
+    tlsdb = g_tls_file_database_new (path, &error);
+    fail_unless (tlsdb, "Failed to load certificate: %s", error->message);
+
+    g_object_set (src, "tls-database", tlsdb, NULL);
+
+    g_object_unref (tlsdb);
+    g_free (path);
+  }
+
   g_object_set (src, "automatic-redirect", redirect, NULL);
-  g_object_set (src, "ssl-ca-file", ssl_cert_file, NULL);
   if (cookies != NULL)
     g_object_set (src, "cookies", cookies, NULL);
   g_object_set (sink, "signal-handoffs", TRUE, NULL);