utils/source-discoverer: Test URI before discovery
This makes sure that we have a valid host set. This check is copies from Soup's private SOUP_URI_IS_VALID() macro. Add a test for this behavior. Closes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/794
This commit is contained in:
@@ -208,6 +208,26 @@ is_authentication_error (gint code)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GUri *
|
||||||
|
create_and_validate_uri (const gchar *uri,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
g_autoptr (GUri) guri = NULL;
|
||||||
|
|
||||||
|
guri = g_uri_parse (uri, SOUP_HTTP_URI_FLAGS | G_URI_FLAGS_PARSE_RELAXED, error);
|
||||||
|
|
||||||
|
if (!guri)
|
||||||
|
GCAL_RETURN (NULL);
|
||||||
|
|
||||||
|
if (!g_uri_get_host (guri) || g_uri_get_host (guri)[0] == '\0')
|
||||||
|
{
|
||||||
|
g_set_error (error, G_URI_ERROR, G_URI_ERROR_FAILED, "Invalid URI");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_steal_pointer (&guri);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Callbacks
|
* Callbacks
|
||||||
@@ -250,7 +270,7 @@ discover_file_in_thread (DiscovererData *data,
|
|||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
guri = g_uri_parse (data->uri, SOUP_HTTP_URI_FLAGS | G_URI_FLAGS_PARSE_RELAXED, error);
|
guri = create_and_validate_uri (data->uri, error);
|
||||||
|
|
||||||
if (!guri)
|
if (!guri)
|
||||||
GCAL_RETURN (NULL);
|
GCAL_RETURN (NULL);
|
||||||
@@ -319,6 +339,7 @@ discover_webdav_in_thread (DiscovererData *data,
|
|||||||
g_autoptr (ESource) source = NULL;
|
g_autoptr (ESource) source = NULL;
|
||||||
g_autoptr (GError) local_error = NULL;
|
g_autoptr (GError) local_error = NULL;
|
||||||
g_autofree gchar *certificate_pem = NULL;
|
g_autofree gchar *certificate_pem = NULL;
|
||||||
|
g_autoptr (GUri) guri = NULL;
|
||||||
GTlsCertificateFlags flags;
|
GTlsCertificateFlags flags;
|
||||||
GSList *discovered_sources = NULL;
|
GSList *discovered_sources = NULL;
|
||||||
GSList *user_addresses = NULL;
|
GSList *user_addresses = NULL;
|
||||||
@@ -326,6 +347,11 @@ discover_webdav_in_thread (DiscovererData *data,
|
|||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
|
guri = create_and_validate_uri (data->uri, error);
|
||||||
|
|
||||||
|
if (!guri)
|
||||||
|
GCAL_RETURN (NULL);
|
||||||
|
|
||||||
credentials = e_named_parameters_new ();
|
credentials = e_named_parameters_new ();
|
||||||
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_USERNAME, data->username);
|
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_USERNAME, data->username);
|
||||||
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_PASSWORD, data->password);
|
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_PASSWORD, data->password);
|
||||||
|
|||||||
@@ -82,6 +82,43 @@ discoverer_file (void)
|
|||||||
|
|
||||||
/*********************************************************************************************************************/
|
/*********************************************************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
discoverer_invalid_https_only_cb (GObject *source_object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_autoptr (GPtrArray) sources = NULL;
|
||||||
|
g_autoptr (GError) error = NULL;
|
||||||
|
GMainLoop *mainloop = user_data;
|
||||||
|
|
||||||
|
sources = gcal_discover_sources_from_uri_finish (result, &error);
|
||||||
|
g_assert_error (error, G_URI_ERROR, G_URI_ERROR_FAILED);
|
||||||
|
g_assert_null (sources);
|
||||||
|
|
||||||
|
g_main_loop_quit (mainloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
discoverer_invalid_https_only (void)
|
||||||
|
{
|
||||||
|
g_autoptr (GMainLoop) mainloop = NULL;
|
||||||
|
|
||||||
|
g_test_bug ("794");
|
||||||
|
|
||||||
|
mainloop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
|
gcal_discover_sources_from_uri ("https://",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
discoverer_invalid_https_only_cb,
|
||||||
|
mainloop);
|
||||||
|
|
||||||
|
g_main_loop_run (mainloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************************************************************************************/
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -184,6 +221,7 @@ main (gint argc,
|
|||||||
g_test_bug_base ("https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/");
|
g_test_bug_base ("https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/");
|
||||||
|
|
||||||
g_test_add_func ("/discoverer/file", discoverer_file);
|
g_test_add_func ("/discoverer/file", discoverer_file);
|
||||||
|
g_test_add_func ("/discoverer/invalid-https-only", discoverer_invalid_https_only);
|
||||||
//g_test_add_func ("/discoverer/webdav/unauthorized", discoverer_webdav_unauthorized);
|
//g_test_add_func ("/discoverer/webdav/unauthorized", discoverer_webdav_unauthorized);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
|
|||||||
Reference in New Issue
Block a user