[libsoup/wip/ci-pkcs11] WIP




commit e205fd15e0cb449e31639bf258a8f031ab5998f7
Author: Patrick Griffis <pgriffis igalia com>
Date:   Sat May 1 18:58:21 2021 -0500

    WIP

 tests/ssl-test.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
---
diff --git a/tests/ssl-test.c b/tests/ssl-test.c
index 4f1828c6..8c9b6e46 100644
--- a/tests/ssl-test.c
+++ b/tests/ssl-test.c
@@ -1,6 +1,8 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
 
 #include "test-utils.h"
+#include "soup-connection.h"
+#include "soup-message-private.h"
 #include "soup-server-message-private.h"
 
 #if HAVE_GNUTLS
@@ -298,10 +300,41 @@ request_certificate_password_async_cb (SoupMessage  *msg,
         return TRUE;
 }
 
+static void
+run_loop_until_connection_destroyed (SoupConnection *conn)
+{
+        GSocket *socket;
+        GWeakRef socket_ref;
+        GObject *object;
+
+        /* The mock pkcs11 module only supports one session at a time so
+         * this will ensure the GTlsClientConnection is fully closed before
+         * continuing. */
+
+        socket = soup_connection_get_socket (conn);
+        g_weak_ref_init (&socket_ref, socket);
+
+        soup_connection_disconnect (conn);
+        while ((object = g_weak_ref_get (&socket_ref))) {
+                g_object_unref (object);
+                g_main_context_iteration (g_main_context_default (), FALSE);
+        }
+
+        g_weak_ref_clear (&socket_ref);
+}
+
+static void
+on_got_headers (SoupMessage *msg, SoupConnection **connection)
+{
+        *connection = soup_message_get_connection (msg);
+        g_assert_nonnull (*connection);
+}
+
 static void
 do_tls_interaction_msg_test (gconstpointer data)
 {
         SoupServer *server = (SoupServer *)data;
+        SoupConnection *connection = NULL;
         SoupSession *session;
         SoupMessage *msg;
         GBytes *body;
@@ -419,7 +452,10 @@ do_tls_interaction_msg_test (gconstpointer data)
         g_signal_connect (msg, "request-certificate-password",
                           G_CALLBACK (request_certificate_password_cb),
                           "ABC123");
+        g_signal_connect (msg, "got-headers", G_CALLBACK (on_got_headers),
+                          &connection);
         body = soup_test_session_async_send (session, msg, NULL, &error);
+        run_loop_until_connection_destroyed (connection);
         g_assert_no_error (error);
         g_clear_error (&error);
         g_bytes_unref (body);
@@ -434,7 +470,10 @@ do_tls_interaction_msg_test (gconstpointer data)
         g_signal_connect (msg, "request-certificate-password",
                           G_CALLBACK (request_certificate_password_async_cb),
                           "ABC123");
+        g_signal_connect (msg, "got-headers", G_CALLBACK (on_got_headers),
+                          &connection);
         body = soup_test_session_async_send (session, msg, NULL, &error);
+        run_loop_until_connection_destroyed (connection);
         g_assert_no_error (error);
         g_clear_error (&error);
         g_bytes_unref (body);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]