summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2021-12-27 09:53:10 +0100
committerJens Georg <mail@jensge.org>2021-12-30 10:12:10 +0100
commit5224f6e08c51dfb378fcefa204a5f50228c8870f (patch)
treee45cf9ce894d327310b40a210c9bb0f1dd3f93dc /tests
parent887704577afe5a74603f16c44bfde634725b7243 (diff)
downloadgupnp-5224f6e08c51dfb378fcefa204a5f50228c8870f.tar.gz
test: Check redirect for folders
Diffstat (limited to 'tests')
-rw-r--r--tests/test-context.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/test-context.c b/tests/test-context.c
index 9cb09dc..73e5cff 100644
--- a/tests/test-context.c
+++ b/tests/test-context.c
@@ -763,6 +763,60 @@ test_gupnp_context_http_language_serve_folder ()
}
void
+test_gupnp_context_http_folder_redirect ()
+{
+ GError *error = NULL;
+ GUPnPContext *context = create_context (0, &error);
+ DefaultCallbackData d = { .bytes = NULL, .loop = NULL };
+
+ d.loop = g_main_loop_new (NULL, FALSE);
+
+ GSList *uris =
+ soup_server_get_uris (gupnp_context_get_server (context));
+ g_assert_no_error (error);
+
+ gupnp_context_host_path (context, DATA_PATH "/locale", "/foo");
+
+ SoupSession *session = soup_session_new ();
+ char *base = g_uri_to_string (uris->data);
+ char *new_uri =
+ g_uri_resolve_relative (base, "foo", G_URI_FLAGS_NONE, &error);
+ g_free (base);
+
+ SoupMessage *msg = soup_message_new (SOUP_METHOD_GET, new_uri);
+
+ // Do not automatically follow the redirect as we want to check if it happened
+ soup_message_add_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+
+ soup_session_send_and_read_async (session,
+ msg,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ soup_message_default_callback,
+ &d);
+ g_main_loop_run (d.loop);
+
+ g_assert_cmpint (soup_message_get_status (msg),
+ ==,
+ SOUP_STATUS_MOVED_PERMANENTLY);
+ g_assert_nonnull (d.bytes);
+ g_assert_null (g_bytes_get_data (d.bytes, NULL));
+ g_bytes_unref (d.bytes);
+
+
+ g_slist_free_full (uris, (GDestroyNotify) g_uri_unref);
+ g_object_unref (context);
+ g_object_unref (msg);
+ g_free (new_uri);
+
+ // Make sure the source teardown handlers get run so we don't confuse valgrind
+ g_timeout_add (500, (GSourceFunc) g_main_loop_quit, d.loop);
+ g_main_loop_run (d.loop);
+ g_main_loop_unref (d.loop);
+ g_object_unref (session);
+}
+
+void
test_gupnp_context_host_for_agent ()
{
GError *error = NULL;
@@ -913,7 +967,10 @@ int main (int argc, char *argv[]) {
g_test_add_func ("/context/http/language/serve-folder",
test_gupnp_context_http_language_serve_folder);
- g_test_add_func ("/context/http/host-for-agent",
+ g_test_add_func ("/context/http/host/folder-rewrite",
+ test_gupnp_context_http_folder_redirect);
+
+ g_test_add_func ("/context/http/host/for-agent",
test_gupnp_context_host_for_agent);
g_test_add_func ("/context/utility/rewrite_uri",