[gupnp: 7/25] tests: Add test for v6 URI rewriting
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp: 7/25] tests: Add test for v6 URI rewriting
- Date: Thu, 30 Dec 2021 09:13:00 +0000 (UTC)
commit ff7d7ae3241e98aeb18c0e11639d90bf46f6427b
Author: Jens Georg <mail jensge org>
Date: Sat Dec 25 18:48:19 2021 +0100
tests: Add test for v6 URI rewriting
libgupnp/gupnp-context.c | 11 +++++
tests/test-bugs.c | 8 ++--
tests/test-context.c | 114 +++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 126 insertions(+), 7 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index b5b9325..1c9450e 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -21,6 +21,8 @@
* exporting <envar>GUPNP_DEBUG</envar>.
*/
+#define G_LOG_DOMAIN "gupnp-context"
+
#include <config.h>
#define G_LOG_DOMAIN "gupnp-context"
@@ -1654,6 +1656,15 @@ gupnp_context_rewrite_uri_to_uri (GUPnPContext *context, const char *uri)
soup_uri = new_uri;
}
+ if (g_inet_address_get_family (addr) !=
+ gssdp_client_get_family (GSSDP_CLIENT (context))) {
+ g_warning ("Address family mismatch while trying to rewrite "
+ "URI %s",
+ uri);
+ g_uri_unref (soup_uri);
+ soup_uri = NULL;
+ }
+
g_object_unref (addr);
return soup_uri;
diff --git a/tests/test-bugs.c b/tests/test-bugs.c
index 8e9b361..1a1aeb2 100644
--- a/tests/test-bugs.c
+++ b/tests/test-bugs.c
@@ -589,7 +589,7 @@ test_ggo_58 ()
G_CALLBACK (test_ggo_58_on_ping_call),
&data);
- test_run_loop (data.loop);
+ test_run_loop (data.loop, g_test_get_path());
g_assert (data.proxy != NULL);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@@ -600,7 +600,7 @@ test_ggo_58 ()
&data,
NULL);
- test_run_loop (data.loop);
+ test_run_loop (data.loop, g_test_get_path());
gboolean success = gupnp_service_proxy_end_action (data.proxy,
action,
@@ -616,7 +616,7 @@ test_ggo_58 ()
&data,
NULL);
- test_run_loop (data.loop);
+ test_run_loop (data.loop, g_test_get_path());
GHashTable *result_hash = g_hash_table_new (g_str_hash, g_str_equal);
@@ -635,7 +635,7 @@ test_ggo_58 ()
&data,
NULL);
- test_run_loop (data.loop);
+ test_run_loop (data.loop, g_test_get_path());
GList *result_list = NULL;
success = gupnp_service_proxy_end_action_list (data.proxy,
diff --git a/tests/test-context.c b/tests/test-context.c
index 42311c7..dd98775 100644
--- a/tests/test-context.c
+++ b/tests/test-context.c
@@ -222,8 +222,10 @@ static void
test_gupnp_context_error_when_bound ()
{
GError *error = NULL;
- SoupServer *server = soup_server_new (NULL, NULL);
- soup_server_listen_local (server, 0, 0, &error);
+
+ // IPv6
+ SoupServer *server = soup_server_new (NULL, NULL);
+ soup_server_listen_local (server, 0, SOUP_SERVER_LISTEN_IPV4_ONLY, &error);
g_assert_no_error (error);
GSList *uris = soup_server_get_uris (server);
@@ -244,6 +246,36 @@ test_gupnp_context_error_when_bound ()
port,
NULL);
+ g_slist_free_full (uris, (GDestroyNotify) g_uri_unref);
+ g_object_unref (server);
+ g_test_assert_expected_messages ();
+ g_assert_error (error, GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_OTHER);
+ g_assert_null (context);
+ g_clear_error (&error);
+
+ // IPv6
+ server = soup_server_new (NULL, NULL);
+ soup_server_listen_local (server, 0, SOUP_SERVER_LISTEN_IPV6_ONLY, &error);
+ g_assert_no_error (error);
+
+ uris = soup_server_get_uris (server);
+
+ address = g_uri_get_host (uris->data);
+ port = g_uri_get_port (uris->data);
+
+ g_test_expect_message (
+ "gupnp-context",
+ G_LOG_LEVEL_WARNING,
+ "*Unable to listen*Could not listen*Address already in use*");
+ context = g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ &error,
+ "host-ip",
+ address,
+ "port",
+ port,
+ NULL);
+
g_slist_free_full (uris, (GDestroyNotify) g_uri_unref);
g_object_unref (server);
@@ -253,12 +285,88 @@ test_gupnp_context_error_when_bound ()
g_clear_error (&error);
}
+void
+test_gupnp_context_rewrite_uri ()
+{
+ GUPnPContext *context = NULL;
+ GError *error = NULL;
+
+ // Create a v4 context
+ context = g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ &error,
+ "host-ip",
+ "127.0.0.1",
+ NULL);
+
+ g_assert_no_error (error);
+ g_assert_nonnull (context);
+
+ char *uri = gupnp_context_rewrite_uri (context, "http://127.0.0.1");
+ g_assert_cmpstr (uri, ==, "http://127.0.0.1");
+ g_free (uri);
+
+ // Rewriting a v6 uri on a v4 context should not work
+ g_test_expect_message ("gupnp-context",
+ G_LOG_LEVEL_WARNING,
+ "Address*family*mismatch*");
+ uri = gupnp_context_rewrite_uri (context, "http://[::1]");
+ g_assert_null (uri);
+ g_test_assert_expected_messages ();
+
+ g_object_unref (context);
+
+ // Create a v6 context
+ context = g_initable_new (GUPNP_TYPE_CONTEXT,
+ NULL,
+ &error,
+ "host-ip",
+ "::1",
+ NULL);
+
+ g_assert_no_error (error);
+ g_assert_nonnull (context);
+ // Rewriting a v6 uri on a v4 context should not work
+ uri = gupnp_context_rewrite_uri (context, "http://[fe80::1]");
+ char *expected = g_strdup_printf (
+ "http://[fe80::1%%25%d]",
+ gssdp_client_get_index (GSSDP_CLIENT (context)));
+ g_assert_cmpstr (uri, ==, expected);
+ g_free (expected);
+ g_free (uri);
+
+ g_test_expect_message ("gupnp-context",
+ G_LOG_LEVEL_WARNING,
+ "Address*family*mismatch*");
+ uri = gupnp_context_rewrite_uri (context, "http://127.0.0.1");
+ g_assert_null (uri);
+ g_test_assert_expected_messages ();
+
+ g_object_unref (context);
+}
+
+void
+test_gupnp_context_http_default_handler ()
+{
+ GError *error = NULL;
+ GUPnPContext *context = create_context (0, &error);
+
+ g_assert_no_error (error);
+ g_assert_nonnull (context);
+}
+
int main (int argc, char *argv[]) {
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/context/http/ranged-requests",
test_gupnp_context_http_ranged_requests);
- g_test_add_func ("/context/creation/error-when-bound", test_gupnp_context_error_when_bound);
+ g_test_add_func ("/context/creation/error-when-bound",
+ test_gupnp_context_error_when_bound);
+ g_test_add_func ("/context/http/default-handler",
+ test_gupnp_context_http_default_handler);
+
+ g_test_add_func ("/context/utility/rewrite_uri",
+ test_gupnp_context_rewrite_uri);
g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]