summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2021-12-25 18:48:19 +0100
committerJens Georg <mail@jensge.org>2021-12-30 10:11:40 +0100
commitff7d7ae3241e98aeb18c0e11639d90bf46f6427b (patch)
treedc67c6930d319cd99963541b8e8e1e5ce489636d /tests
parentf4cd78c0a9023e60baec984e193b31b2336659b7 (diff)
downloadgupnp-ff7d7ae3241e98aeb18c0e11639d90bf46f6427b.tar.gz
tests: Add test for v6 URI rewriting
Diffstat (limited to 'tests')
-rw-r--r--tests/test-bugs.c8
-rw-r--r--tests/test-context.c114
2 files changed, 115 insertions, 7 deletions
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);
@@ -246,6 +248,36 @@ test_gupnp_context_error_when_bound ()
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);
g_test_assert_expected_messages ();
g_assert_error (error, GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_OTHER);
@@ -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 ();