[evolution-ews] Use uhttpmock 0.9 for internal tests



commit 6a8a481a5954ada12094198496a788d28258eb35
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jul 21 17:23:58 2022 +0200

    Use uhttpmock 0.9 for internal tests
    
    The uhttpmock 0.9 uses libsoup3. Also modify sources to satisfy
    the tests requirements.

 CMakeLists.txt                             |  6 ++---
 src/EWS/calendar/e-cal-backend-ews-utils.c |  9 ++++---
 src/EWS/calendar/e-cal-backend-ews.c       |  8 ++++++
 src/EWS/common/e-ews-connection.c          | 43 ++++++++++++++++++++++++++++++
 src/EWS/common/e-ews-connection.h          |  5 ++++
 tests/CMakeLists.txt                       |  2 +-
 tests/ews-test-camel.c                     |  5 +---
 tests/ews-test-common.c                    | 12 ++-------
 tests/ews-test-timezones.c                 |  7 ++---
 9 files changed, 72 insertions(+), 25 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6479fa04..44a8d3a1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,7 @@ set(evo_minimum_version ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJ
 set(mspack_minimum_version 0.4)
 set(libical_glib_minimum_version 3.0.5)
 set(json_glib_minimum_version 1.0.4)
+set(uhttpmock_minimum_version 0.9)
 
 # Load modules from the source tree
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
@@ -175,7 +176,7 @@ unset(CMAKE_REQUIRED_LIBRARIES)
 add_printable_option(ENABLE_TESTS "Enable low level tests for EwsConnection" OFF)
 
 if(ENABLE_TESTS)
-       pkg_check_modules_for_option(ENABLE_TESTS "low level tests" UHTTPMOCK libuhttpmock-0.0)
+       pkg_check_modules_for_option(ENABLE_TESTS "low level tests" UHTTPMOCK 
libuhttpmock-1.0>=${uhttpmock_minimum_version})
 endif(ENABLE_TESTS)
 
 # ******************************
@@ -287,6 +288,5 @@ add_subdirectory(po)
 add_subdirectory(src)
 
 if(ENABLE_TESTS)
-       message(WARNING "tests are disabled until uhttpmock is ported to libsoup3")
-       #add_subdirectory(tests)
+       add_subdirectory(tests)
 endif(ENABLE_TESTS)
diff --git a/src/EWS/calendar/e-cal-backend-ews-utils.c b/src/EWS/calendar/e-cal-backend-ews-utils.c
index 5889549e..c06cd607 100644
--- a/src/EWS/calendar/e-cal-backend-ews-utils.c
+++ b/src/EWS/calendar/e-cal-backend-ews-utils.c
@@ -47,7 +47,7 @@ static GHashTable *ical_to_msdn = NULL;
 static GHashTable *msdn_to_ical = NULL;
 static guint tables_counter = 0;
 
-void
+G_MODULE_EXPORT void
 e_cal_backend_ews_populate_windows_zones (void)
 {
        const gchar *xpath_eval_exp;
@@ -165,7 +165,7 @@ e_cal_backend_ews_unref_windows_zones (void)
        g_rec_mutex_unlock (&tz_mutex);
 }
 
-const gchar *
+G_MODULE_EXPORT const gchar *
 e_cal_backend_ews_tz_util_get_msdn_equivalent (const gchar *ical_tz_location)
 {
        const gchar *msdn_tz_location = NULL;
@@ -1256,7 +1256,8 @@ convert_vevent_calcomp_to_xml (ESoapRequest *request,
        msdn_location_end = e_cal_backend_ews_tz_util_get_msdn_equivalent (ical_location_end);
        satisfies = e_ews_connection_satisfies_server_version (convert_data->connection, E_EWS_EXCHANGE_2010);
 
-       if (satisfies && msdn_location_start != NULL && msdn_location_end != NULL) {
+       if (satisfies && msdn_location_start != NULL && msdn_location_end != NULL &&
+           !e_ews_connection_get_testing_sources (convert_data->connection)) {
                GSList *msdn_locations = NULL;
                GSList *tzds = NULL;
 
@@ -1426,7 +1427,7 @@ convert_vjournal_calcomp_to_xml (ESoapRequest *request,
        return TRUE;
 }
 
-gboolean
+G_MODULE_EXPORT gboolean
 e_cal_backend_ews_convert_calcomp_to_xml (ESoapRequest *request,
                                          gpointer user_data,
                                          GError **error)
diff --git a/src/EWS/calendar/e-cal-backend-ews.c b/src/EWS/calendar/e-cal-backend-ews.c
index 3ab00a1e..5ff9ca95 100644
--- a/src/EWS/calendar/e-cal-backend-ews.c
+++ b/src/EWS/calendar/e-cal-backend-ews.c
@@ -4741,3 +4741,11 @@ e_cal_backend_ews_class_init (ECalBackendEwsClass *klass)
        object_class->dispose = ecb_ews_dispose;
        object_class->finalize = ecb_ews_finalize;
 }
+
+GType e_cal_backend_ews_get_type_for_testing_sources (void);
+
+G_MODULE_EXPORT GType
+e_cal_backend_ews_get_type_for_testing_sources (void)
+{
+       return e_cal_backend_ews_get_type ();
+}
diff --git a/src/EWS/common/e-ews-connection.c b/src/EWS/common/e-ews-connection.c
index 5f02ecca..bf463d3d 100644
--- a/src/EWS/common/e-ews-connection.c
+++ b/src/EWS/common/e-ews-connection.c
@@ -92,6 +92,7 @@ struct _EEwsConnectionPrivate {
 
        /* Set to TRUE when this connection had been disconnected and cannot be used anymore */
        gboolean disconnected_flag;
+       gboolean testing_sources;
 
        gboolean ssl_info_set;
        gchar *ssl_certificate_pem;
@@ -272,6 +273,25 @@ ews_connection_credentials_failed (EEwsConnection *connection,
        return expired;
 }
 
+static gboolean
+e_ews_connection_accept_certificate_for_testing_sources_cb (SoupMessage *message,
+                                                           GTlsCertificate *tls_peer_certificate,
+                                                           GTlsCertificateFlags tls_peer_errors,
+                                                           gpointer user_data)
+{
+       return TRUE;
+}
+
+static void
+e_ews_connection_maybe_prepare_message_for_testing_sources (EEwsConnection *cnc,
+                                                           SoupMessage *message)
+{
+       if (e_ews_connection_get_testing_sources (cnc)) {
+               g_signal_connect (message, "accept-certificate",
+                       G_CALLBACK (e_ews_connection_accept_certificate_for_testing_sources_cb), NULL);
+       }
+}
+
 typedef struct _ProcessData {
        GMutex mutex;
        GCond cond;
@@ -398,6 +418,8 @@ e_ews_connection_process_request_sync (EEwsConnection *cnc,
        if (!pd.message)
                return NULL;
 
+       e_ews_connection_maybe_prepare_message_for_testing_sources (cnc, pd.message);
+
        g_mutex_lock (&cnc->priv->property_lock);
        if (cnc->priv->credentials_changed) {
                cnc->priv->credentials_changed = FALSE;
@@ -1781,6 +1803,23 @@ e_ews_connection_new_for_backend (EBackend *backend,
        return cnc;
 }
 
+void
+e_ews_connection_set_testing_sources (EEwsConnection *cnc,
+                                     gboolean testing_sources)
+{
+       g_return_if_fail (E_IS_EWS_CONNECTION (cnc));
+
+       cnc->priv->testing_sources = testing_sources;
+}
+
+gboolean
+e_ews_connection_get_testing_sources (EEwsConnection *cnc)
+{
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
+
+       return cnc->priv->testing_sources;
+}
+
 void
 e_ews_connection_update_credentials (EEwsConnection *cnc,
                                     const ENamedParameters *credentials)
@@ -7850,6 +7889,8 @@ e_ews_connection_query_auth_methods_sync (EEwsConnection *cnc,
                return FALSE;
        }
 
+       e_ews_connection_maybe_prepare_message_for_testing_sources (cnc, message);
+
        amd.cancellable = g_cancellable_new ();
        amd.out_auth_methods = out_auth_methods;
 
@@ -9677,6 +9718,8 @@ e_ews_connection_prepare_streaming_events_sync (EEwsConnection *cnc,
                return NULL;
        }
 
+       e_ews_connection_maybe_prepare_message_for_testing_sources (cnc, *out_message);
+
        g_mutex_lock (&cnc->priv->property_lock);
        e_soup_session_set_credentials (*out_session, cnc->priv->credentials);
        g_mutex_unlock (&cnc->priv->property_lock);
diff --git a/src/EWS/common/e-ews-connection.h b/src/EWS/common/e-ews-connection.h
index f178ce30..d993dd83 100644
--- a/src/EWS/common/e-ews-connection.h
+++ b/src/EWS/common/e-ews-connection.h
@@ -419,6 +419,11 @@ EEwsConnection *e_ews_connection_new_for_backend(EBackend *backend,
                                                 ESourceRegistry *registry,
                                                 const gchar *uri,
                                                 CamelEwsSettings *settings);
+void           e_ews_connection_set_testing_sources
+                                               (EEwsConnection *cnc,
+                                                gboolean testing_sources);
+gboolean       e_ews_connection_get_testing_sources
+                                               (EEwsConnection *cnc);
 void           e_ews_connection_update_credentials
                                                (EEwsConnection *cnc,
                                                 const ENamedParameters *credentials);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 35089dd8..eea14374 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -20,7 +20,7 @@ macro(add_ews_test _name)
        target_compile_definitions(${_name} PRIVATE
                -DG_LOG_DOMAIN=\"${_name}\"
                -DTEST_FILE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"
-               -DCALENDAR_MODULE_DIR=\"${CMAKE_BINARY_DIR}/src/calendar/\"
+               -DCALENDAR_MODULE_DIR=\"${CMAKE_BINARY_DIR}/src/EWS/calendar/\"
        )
 
        target_compile_options(${_name} PUBLIC
diff --git a/tests/ews-test-camel.c b/tests/ews-test-camel.c
index 6e54e852..58a4aa87 100644
--- a/tests/ews-test-camel.c
+++ b/tests/ews-test-camel.c
@@ -164,10 +164,7 @@ test_create_folder_with_invalid_distinguished_parent_id (gconstpointer user_data
                NULL, &error);
 
        if (error != NULL) {
-               parent_folder_not_found = g_error_matches (
-                       error,
-                       SOUP_HTTP_ERROR,
-                       SOUP_STATUS_IO_ERROR);
+               parent_folder_not_found = g_error_matches (error, E_SOUP_SESSION_ERROR, 
SOUP_STATUS_INTERNAL_SERVER_ERROR);
 
                if (!parent_folder_not_found)
                        g_printerr ("\n%s\n", error->message);
diff --git a/tests/ews-test-common.c b/tests/ews-test-common.c
index cd3adc29..f9198710 100644
--- a/tests/ews-test-common.c
+++ b/tests/ews-test-common.c
@@ -231,7 +231,6 @@ ews_test_init (gint argc,
                etd = g_new0 (EwsTestData, 1);
                if (write_traces) {
                        CamelEwsSettings *settings = NULL;
-                       SoupSession *session;
 
                        settings = g_object_new (
                                CAMEL_TYPE_EWS_SETTINGS,
@@ -240,13 +239,10 @@ ews_test_init (gint argc,
 
                        etd->version = g_list_nth_data (versions, i);
                        etd->connection = e_ews_connection_new (NULL, g_list_nth_data (server_uris, i), 
settings);
+                       e_ews_connection_set_testing_sources (etd->connection, TRUE);
                        e_ews_connection_set_password (etd->connection, g_list_nth_data (passwords, i));
                        e_ews_connection_set_server_version_from_string (etd->connection, etd->version);
 
-                       session = e_ews_connection_ref_soup_session (etd->connection);
-                       g_object_set (G_OBJECT (session), SOUP_SESSION_SSL_STRICT, FALSE, NULL);
-                       g_object_unref (session);
-
                        g_object_unref (settings);
                } else {
                        etd->version = g_list_nth_data (fake_versions, i);
@@ -305,7 +301,6 @@ ews_test_set_https_port (UhmServer *server,
                         EwsTestData *etd)
 {
        CamelEwsSettings *ews_settings;
-       SoupSession *session;
        guint16 port;
        gchar *uri;
        gchar **tokens;
@@ -321,13 +316,10 @@ ews_test_set_https_port (UhmServer *server,
                NULL);
 
        etd->connection = e_ews_connection_new (NULL, uri, ews_settings);
+       e_ews_connection_set_testing_sources (etd->connection, TRUE);
        e_ews_connection_set_password (etd->connection, "bar");
        e_ews_connection_set_server_version_from_string (etd->connection, etd->version);
 
-       session = e_ews_connection_ref_soup_session (etd->connection);
-       g_object_set (G_OBJECT (session), SOUP_SESSION_SSL_STRICT, FALSE, NULL);
-       g_object_unref (session);
-
        g_free (uri);
        g_strfreev (tokens);
        g_object_unref (ews_settings);
diff --git a/tests/ews-test-timezones.c b/tests/ews-test-timezones.c
index 34c7ed8a..5cefdbb6 100644
--- a/tests/ews-test-timezones.c
+++ b/tests/ews-test-timezones.c
@@ -13,7 +13,9 @@
 
 void (* populate_windows_zones) (void);
 const gchar * (* ical_to_msdn_equivalent) (const gchar *);
-gboolean (* convert_calcomp_to_xml) (ESoapMessage *, gpointer, GError **);
+gboolean (* convert_calcomp_to_xml) (ESoapRequest *request,
+                                    gpointer user_data,
+                                    GError **error);
 GType (* cal_backend_ews_get_type) (void);
 
 const gchar *str_comp =
@@ -403,7 +405,7 @@ int main (int argc,
 
        convert_calcomp_to_xml = symbol;
 
-       if (!g_module_symbol (module, "e_cal_backend_ews_get_type", &symbol)) {
+       if (!g_module_symbol (module, "e_cal_backend_ews_get_type_for_testing_sources", &symbol)) {
                g_printerr ("\n%s\n", g_module_error ());
                retval = 6;
                goto exit;
@@ -425,7 +427,6 @@ int main (int argc,
                if (!uhm_server_get_enable_online (server))
                        g_signal_connect (server, "notify::resolver", (GCallback) server_notify_resolver_cb, 
etd);
 
-               /* Create folder */
                if (e_ews_debug_get_server_version_from_string (etd->version) >= E_EWS_EXCHANGE_2010) {
                        message = g_strdup_printf ("/%s/calendar/timezones/ical_compatibility", etd->version);
                        g_test_add_data_func (message, etd, test_libical_timezones_compatibility);


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