From fbbf6d854cacab0a481d513fc80534c2d4d88ecc Mon Sep 17 00:00:00 2001 From: tytan652 Date: Sat, 22 Aug 2026 09:47:46 +0200 Subject: [PATCH] tests/discoverer: Add file variations Enables testing properly the ICS header check which is ignored if content-type is text/calendar. Part-of: --- tests/gcal-simple-server.c | 43 +++++++++++++++++++++++++++++++++----- tests/gcal-simple-server.h | 9 +++++--- tests/test-discoverer.c | 42 ++++++++++++++++++++++++++----------- tests/test-server.c | 4 ++-- 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/tests/gcal-simple-server.c b/tests/gcal-simple-server.c index 28d08c0a..624d714d 100644 --- a/tests/gcal-simple-server.c +++ b/tests/gcal-simple-server.c @@ -49,17 +49,50 @@ process_get (SoupServerMessage *message, const gchar *prefix, const gchar *path) { - g_autofree gchar *calendar_path = g_strdup_printf ("%s/calendar", prefix); + g_autofree gchar *crlf_calendar_path = g_strdup_printf ("%s/crlf-calendar", prefix); + g_autofree gchar *crlf_calendar_stream_path = g_strdup_printf ("%s/crlf-calendar-stream", prefix); + g_autofree gchar *lf_calendar_path = g_strdup_printf ("%s/lf-calendar", prefix); + g_autofree gchar *lf_calendar_stream_path = g_strdup_printf ("%s/lf-calendar-stream", prefix); g_autofree gchar *calendar_file = g_strdup_printf ("%s/calendar.ics", prefix); - if (g_strcmp0 (path, calendar_path) == 0) + if (g_strcmp0 (path, crlf_calendar_path) == 0) { - g_debug ("Serving empty calendar"); + g_debug ("Serving empty CRLF calendar as text/calendar"); soup_server_message_set_response (message, "text/calendar", SOUP_MEMORY_STATIC, - GCAL_TEST_SERVER_EMPTY_CALENDAR, - strlen (GCAL_TEST_SERVER_EMPTY_CALENDAR)); + GCAL_TEST_SERVER_EMPTY_CRLF_CALENDAR, + strlen (GCAL_TEST_SERVER_EMPTY_CRLF_CALENDAR)); + } + + if (g_strcmp0 (path, crlf_calendar_stream_path) == 0) + { + g_debug ("Serving empty CRLF calendar as application/octet-stream"); + soup_server_message_set_response (message, + "application/octet-stream", + SOUP_MEMORY_STATIC, + GCAL_TEST_SERVER_EMPTY_CRLF_CALENDAR, + strlen (GCAL_TEST_SERVER_EMPTY_CRLF_CALENDAR)); + } + + if (g_strcmp0 (path, lf_calendar_path) == 0) + { + g_debug ("Serving empty LF calendar as text/calendar"); + soup_server_message_set_response (message, + "text/calendar", + SOUP_MEMORY_STATIC, + GCAL_TEST_SERVER_EMPTY_LF_CALENDAR, + strlen (GCAL_TEST_SERVER_EMPTY_LF_CALENDAR)); + } + + if (g_strcmp0 (path, lf_calendar_stream_path) == 0) + { + g_debug ("Serving empty LF calendar as application/octet-stream"); + soup_server_message_set_response (message, + "application/octet-stream", + SOUP_MEMORY_STATIC, + GCAL_TEST_SERVER_EMPTY_LF_CALENDAR, + strlen (GCAL_TEST_SERVER_EMPTY_LF_CALENDAR)); } if (g_strcmp0 (path, calendar_file) == 0) diff --git a/tests/gcal-simple-server.h b/tests/gcal-simple-server.h index a0b52ed9..db93aaef 100644 --- a/tests/gcal-simple-server.h +++ b/tests/gcal-simple-server.h @@ -25,11 +25,14 @@ G_BEGIN_DECLS +#define _GCAL_TEST_SERVER_CALENDAR_BEGIN "BEGIN:VCALENDAR" +#define _GCAL_TEST_SERVER_CALENDAR_END "END:VCALENDAR" -#define GCAL_TEST_SERVER_EMPTY_CALENDAR \ -"BEGIN:VCALENDAR\n" \ -"END:VCALENDAR" +#define GCAL_TEST_SERVER_EMPTY_CRLF_CALENDAR \ + _GCAL_TEST_SERVER_CALENDAR_BEGIN "\r\n" _GCAL_TEST_SERVER_CALENDAR_END +#define GCAL_TEST_SERVER_EMPTY_LF_CALENDAR \ + _GCAL_TEST_SERVER_CALENDAR_BEGIN "\n" _GCAL_TEST_SERVER_CALENDAR_END #define GCAL_TYPE_SIMPLE_SERVER (gcal_simple_server_get_type()) G_DECLARE_FINAL_TYPE (GcalSimpleServer, gcal_simple_server, GCAL, SIMPLE_SERVER, GObject) diff --git a/tests/test-discoverer.c b/tests/test-discoverer.c index 307d5c3e..64d90c6a 100644 --- a/tests/test-discoverer.c +++ b/tests/test-discoverer.c @@ -57,27 +57,45 @@ discovered_file_cb (GObject *source_object, static void discoverer_file (void) { + const gchar *const paths[] = { + /* content-type: text-calendar - CRLF line break - ICS header check result ignored */ + "/public/crlf-calendar", + /* content-type: text-calendar - LF line break - ICS header check result ignored */ + "/public/lf-calendar", + /* content-type: application/octet-stream - CRLF line break - ICS header check result used */ + "/public/crlf-calendar-stream", + /* content-type: application/octet-stream - LF line break - ICS header check result used */ + "/public/lf-calendar-stream", + }; g_autoptr (GcalSimpleServer) server = NULL; g_autoptr (GMainLoop) mainloop = NULL; g_autoptr (GUri) uri = NULL; - g_autofree gchar *uri_str = NULL; + guint i; + + g_test_bug ("1274"); server = init_server (); uri = gcal_simple_server_get_uri (server); - e_util_change_uri_component (&uri, SOUP_URI_PATH, "/public/calendar"); - - uri_str = g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD); mainloop = g_main_loop_new (NULL, FALSE); - gcal_discover_sources_from_uri (uri_str, - NULL, - NULL, - NULL, - discovered_file_cb, - mainloop); + for (i = 0; i < G_N_ELEMENTS (paths); i++) + { + g_autofree gchar *uri_str = NULL; - g_main_loop_run (mainloop); + e_util_change_uri_component (&uri, SOUP_URI_PATH, paths[i]); + + uri_str = g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD); + + gcal_discover_sources_from_uri (uri_str, + NULL, + NULL, + NULL, + discovered_file_cb, + mainloop); + + g_main_loop_run (mainloop); + } } /*********************************************************************************************************************/ @@ -146,7 +164,7 @@ discoverer_webdav_unauthorized (void) server = init_server (); uri = gcal_simple_server_get_uri (server); - e_util_change_uri_component (&uri, SOUP_URI_PATH, "/secret-area/calendar"); + e_util_change_uri_component (&uri, SOUP_URI_PATH, "/secret-area/lf-calendar"); uri_str = g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD); diff --git a/tests/test-server.c b/tests/test-server.c index be616e26..949c78c8 100644 --- a/tests/test-server.c +++ b/tests/test-server.c @@ -153,7 +153,7 @@ server_request_no_auth_calendar (void) server = init_server (); uri = gcal_simple_server_get_uri (server); - e_util_change_uri_component (&uri, SOUP_URI_PATH, "/public/calendar"); + e_util_change_uri_component (&uri, SOUP_URI_PATH, "/public/lf-calendar"); session = gcal_create_soup_session (); @@ -203,7 +203,7 @@ server_request_auth_calendar (void) server = init_server (); uri = gcal_simple_server_get_uri (server); - e_util_change_uri_component (&uri, SOUP_URI_PATH, "/secret-area/calendar"); + e_util_change_uri_component (&uri, SOUP_URI_PATH, "/secret-area/lf-calendar"); session = gcal_create_soup_session ();