1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
5 * Copyright 2011, 2015, 2016 Collabora, Ltd.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see
19 * <http://www.gnu.org/licenses/>.
21 * In addition, when the library is used with OpenSSL, a special
22 * exception applies. Refer to the LICENSE_EXCEPTION file for details.
24 * Author: Stef Walter <stefw@collabora.co.uk>
25 * Philip Withnall <philip.withnall@collabora.co.uk>
30 #include "lossy-socket.h"
31 #include "mock-interaction.h"
34 #ifdef BACKEND_IS_GNUTLS
35 #include <gnutls/gnutls.h>
38 #include <sys/types.h>
42 tls_test_file_path (const char *name)
44 const gchar *const_path;
47 path = g_test_build_filename (G_TEST_DIST, "files", name, NULL);
48 if (!g_path_is_absolute (path))
52 cwd = g_get_current_dir ();
53 abs = g_build_filename (cwd, path, NULL);
59 const_path = g_intern_string (path);
64 #define TEST_DATA "You win again, gravity!\n"
65 #define TEST_DATA_LENGTH 24
67 /* Static test parameters. */
69 gint64 server_timeout; /* microseconds */
70 gint64 client_timeout; /* microseconds */
71 gboolean server_should_disappear; /* whether the server should stop responding before sending a message */
72 gboolean server_should_close; /* whether the server should close gracefully once it’s sent a message */
73 GTlsAuthenticationMode auth_mode;
74 IOPredicateFunc client_loss_inducer;
75 IOPredicateFunc server_loss_inducer;
79 const TestData *test_data;
81 GMainContext *client_context;
82 GMainContext *server_context;
83 gboolean loop_finished;
84 GSocket *server_socket;
85 GDatagramBased *server_transport;
86 GSource *server_source;
87 GTlsDatabase *database;
88 GDatagramBased *server_connection;
89 GDatagramBased *client_connection;
90 GSocketConnectable *identity;
91 GSocketAddress *address;
93 GTlsCertificateFlags accept_flags;
95 gboolean expect_server_error;
97 gboolean server_running;
98 const gchar * const *server_protocols;
101 gssize nread, nwrote;
105 setup_connection (TestConnection *test, gconstpointer data)
107 test->test_data = data;
109 test->client_context = g_main_context_default ();
110 test->loop_finished = FALSE;
113 /* Waits about 10 seconds for @var to be NULL/FALSE */
114 #define WAIT_UNTIL_UNSET(var) \
119 for (i = 0; i < 13 && (var); i++) \
121 g_usleep (1000 * (1 << i)); \
122 g_main_context_iteration (test->client_context, FALSE); \
125 g_assert_true (!(var)); \
128 /* Waits about 10 seconds for @var's ref_count to drop to 1 */
129 #define WAIT_UNTIL_UNREFFED(var) \
134 for (i = 0; i < 13 && G_OBJECT (var)->ref_count > 1; i++) \
136 g_usleep (1000 * (1 << i)); \
137 g_main_context_iteration (test->client_context, FALSE); \
140 g_assert_cmpuint (G_OBJECT (var)->ref_count, ==, 1); \
144 teardown_connection (TestConnection *test, gconstpointer data)
146 GError *error = NULL;
148 if (test->server_source)
150 g_source_destroy (test->server_source);
151 g_source_unref (test->server_source);
152 test->server_source = NULL;
155 if (test->server_connection)
157 WAIT_UNTIL_UNSET (test->server_running);
159 WAIT_UNTIL_UNREFFED (test->server_connection);
160 g_object_unref (test->server_connection);
161 test->server_connection = NULL;
164 g_clear_object (&test->server_transport);
166 if (test->server_socket)
168 g_socket_close (test->server_socket, &error);
169 g_assert_no_error (error);
171 /* The outstanding accept_async will hold a ref on test->server_socket,
172 * which we want to wait for it to release if we're valgrinding.
174 WAIT_UNTIL_UNREFFED (test->server_socket);
175 g_object_unref (test->server_socket);
176 test->server_socket = NULL;
179 if (test->client_connection)
181 WAIT_UNTIL_UNREFFED (test->client_connection);
182 g_object_unref (test->client_connection);
183 test->client_connection = NULL;
188 WAIT_UNTIL_UNREFFED (test->database);
189 g_object_unref (test->database);
190 test->database = NULL;
193 g_clear_object (&test->address);
194 g_clear_object (&test->identity);
195 g_clear_error (&test->read_error);
196 g_clear_error (&test->server_error);
200 start_server (TestConnection *test)
203 GSocketAddress *addr;
204 GInetSocketAddress *iaddr;
205 GSocket *socket = NULL;
206 GError *error = NULL;
208 inet = g_inet_address_new_from_string ("127.0.0.1");
209 addr = g_inet_socket_address_new (inet, 0);
210 g_object_unref (inet);
212 socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
213 G_SOCKET_PROTOCOL_UDP, &error);
214 g_assert_no_error (error);
216 g_socket_bind (socket, addr, FALSE, &error);
217 g_assert_no_error (error);
219 test->address = g_socket_get_local_address (socket, &error);
220 g_assert_no_error (error);
222 g_object_unref (addr);
224 /* The hostname in test->identity matches the server certificate. */
225 iaddr = G_INET_SOCKET_ADDRESS (test->address);
226 test->identity = g_network_address_new ("server.example.com",
227 g_inet_socket_address_get_port (iaddr));
229 test->server_socket = socket;
230 if (test->test_data->server_loss_inducer)
232 test->server_transport = lossy_socket_new (G_DATAGRAM_BASED (socket),
233 test->test_data->server_loss_inducer,
238 test->server_transport = G_DATAGRAM_BASED (g_object_ref (socket));
240 test->server_running = TRUE;
244 on_accept_certificate (GTlsClientConnection *conn, GTlsCertificate *cert,
245 GTlsCertificateFlags errors, gpointer user_data)
247 TestConnection *test = user_data;
248 return errors == test->accept_flags;
251 static void close_server_connection (TestConnection *test,
255 on_rehandshake_finish (GObject *object,
259 TestConnection *test = user_data;
260 GError *error = NULL;
261 GOutputVector vectors[2] = {
262 { TEST_DATA + TEST_DATA_LENGTH / 2, TEST_DATA_LENGTH / 4 },
263 { TEST_DATA + 3 * TEST_DATA_LENGTH / 4, TEST_DATA_LENGTH / 4},
265 GOutputMessage message = { NULL, vectors, G_N_ELEMENTS (vectors), 0, NULL, 0 };
268 g_dtls_connection_handshake_finish (G_DTLS_CONNECTION (object), res, &error);
269 g_assert_no_error (error);
273 g_clear_error (&test->server_error);
274 n_sent = g_datagram_based_send_messages (test->server_connection,
276 G_SOCKET_MSG_NONE, 0, NULL,
277 &test->server_error);
278 g_main_context_iteration (test->server_context, FALSE);
280 while (g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
282 if (!test->server_error)
284 g_assert_cmpint (n_sent, ==, 1);
285 g_assert_cmpuint (message.bytes_sent, ==, TEST_DATA_LENGTH / 2);
288 if (!test->server_error && test->rehandshake)
290 test->rehandshake = FALSE;
291 g_dtls_connection_handshake_async (G_DTLS_CONNECTION (test->server_connection),
292 G_PRIORITY_DEFAULT, NULL,
293 on_rehandshake_finish, test);
297 if (test->test_data->server_should_close)
298 close_server_connection (test, TRUE);
302 on_rehandshake_finish_threaded (GObject *object,
306 TestConnection *test = user_data;
307 GError *error = NULL;
308 GOutputVector vectors[2] = {
309 { TEST_DATA + TEST_DATA_LENGTH / 2, TEST_DATA_LENGTH / 4 },
310 { TEST_DATA + 3 * TEST_DATA_LENGTH / 4, TEST_DATA_LENGTH / 4},
312 GOutputMessage message = { NULL, vectors, G_N_ELEMENTS (vectors), 0, NULL, 0 };
315 g_dtls_connection_handshake_finish (G_DTLS_CONNECTION (object), res, &error);
316 g_assert_no_error (error);
320 g_clear_error (&test->server_error);
321 n_sent = g_datagram_based_send_messages (test->server_connection,
323 G_SOCKET_MSG_NONE, 0, NULL,
324 &test->server_error);
325 g_main_context_iteration (test->server_context, FALSE);
327 while (g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
329 if (!test->server_error)
331 g_assert_cmpint (n_sent, ==, 1);
332 g_assert_cmpuint (message.bytes_sent, ==, TEST_DATA_LENGTH / 2);
335 if (!test->server_error && test->rehandshake)
337 test->rehandshake = FALSE;
338 g_dtls_connection_handshake_async (G_DTLS_CONNECTION (test->server_connection),
339 G_PRIORITY_DEFAULT, NULL,
340 on_rehandshake_finish_threaded, test);
344 if (test->test_data->server_should_close)
345 close_server_connection (test, TRUE);
349 close_server_connection (TestConnection *test,
352 GError *error = NULL;
355 g_dtls_connection_close (G_DTLS_CONNECTION (test->server_connection),
358 /* Clear pending dispatches from the context. */
359 while (g_main_context_iteration (test->server_context, FALSE));
361 if (graceful && test->expect_server_error)
362 g_assert_nonnull (error);
364 g_assert_no_error (error);
366 test->server_running = FALSE;
370 on_incoming_connection (GSocket *socket,
371 GIOCondition condition,
374 TestConnection *test = user_data;
375 GTlsCertificate *cert;
376 GError *error = NULL;
377 GOutputVector vector = {
379 test->rehandshake ? TEST_DATA_LENGTH / 2 : TEST_DATA_LENGTH
381 GOutputMessage message = { NULL, &vector, 1, 0, NULL, 0 };
383 GSocketAddress *addr = NULL; /* owned */
384 guint8 databuf[65536];
385 GInputVector vec = {databuf, sizeof (databuf)};
386 gint flags = G_SOCKET_MSG_PEEK;
389 /* Ignore this if the source has already been destroyed. */
390 if (g_source_is_destroyed (test->server_source))
391 return G_SOURCE_REMOVE;
393 /* Remove the source as the first thing. */
394 g_source_destroy (test->server_source);
395 g_source_unref (test->server_source);
396 test->server_source = NULL;
398 /* Peek at the incoming packet to get the peer’s address. */
399 ret = g_socket_receive_message (socket, &addr, &vec, 1, NULL, NULL,
403 return G_SOURCE_REMOVE;
405 if (!g_socket_connect (socket, addr, NULL, NULL))
407 g_object_unref (addr);
408 return G_SOURCE_CONTINUE;
411 g_clear_object (&addr);
413 /* Wrap the socket in a GDtlsServerConnection. */
414 cert = g_tls_certificate_new_from_file (tls_test_file_path ("server-and-key.pem"), &error);
415 g_assert_no_error (error);
417 test->server_connection = g_dtls_server_connection_new (test->server_transport,
419 g_debug ("%s: Server connection %p on socket %p", G_STRFUNC, test->server_connection, socket);
420 g_assert_no_error (error);
421 g_object_unref (cert);
423 g_object_set (test->server_connection, "authentication-mode",
424 test->test_data->auth_mode, NULL);
425 g_signal_connect (test->server_connection, "accept-certificate",
426 G_CALLBACK (on_accept_certificate), test);
429 g_dtls_connection_set_database (G_DTLS_CONNECTION (test->server_connection), test->database);
431 if (test->server_protocols)
433 g_dtls_connection_set_advertised_protocols (G_DTLS_CONNECTION (test->server_connection),
434 test->server_protocols);
437 if (test->test_data->server_should_disappear)
439 close_server_connection (test, FALSE);
440 return G_SOURCE_REMOVE;
445 g_clear_error (&test->server_error);
446 n_sent = g_datagram_based_send_messages (test->server_connection,
448 G_SOCKET_MSG_NONE, 0, NULL,
449 &test->server_error);
450 g_main_context_iteration (test->server_context, FALSE);
452 while (g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
454 if (!test->server_error)
456 g_assert_cmpint (n_sent, ==, 1);
457 g_assert_cmpuint (message.bytes_sent, ==, vector.size);
460 if (!test->server_error && test->rehandshake)
462 test->rehandshake = FALSE;
463 g_dtls_connection_handshake_async (G_DTLS_CONNECTION (test->server_connection),
464 G_PRIORITY_DEFAULT, NULL,
465 on_rehandshake_finish, test);
466 return G_SOURCE_REMOVE;
469 if (test->test_data->server_should_close)
470 close_server_connection (test, TRUE);
472 return G_SOURCE_REMOVE;
476 on_incoming_connection_threaded (GSocket *socket,
477 GIOCondition condition,
480 TestConnection *test = user_data;
481 GTlsCertificate *cert;
482 GError *error = NULL;
483 GOutputVector vector = {
485 test->rehandshake ? TEST_DATA_LENGTH / 2 : TEST_DATA_LENGTH
487 GOutputMessage message = { NULL, &vector, 1, 0, NULL, 0 };
489 GSocketAddress *addr = NULL; /* owned */
490 guint8 databuf[65536];
491 GInputVector vec = {databuf, sizeof (databuf)};
492 gint flags = G_SOCKET_MSG_PEEK;
495 /* Ignore this if the source has already been destroyed. */
496 if (g_source_is_destroyed (test->server_source))
497 return G_SOURCE_REMOVE;
499 /* Remove the source as the first thing. */
500 g_source_destroy (test->server_source);
501 g_source_unref (test->server_source);
502 test->server_source = NULL;
504 /* Peek at the incoming packet to get the peer’s address. */
505 ret = g_socket_receive_message (socket, &addr, &vec, 1, NULL, NULL,
509 return G_SOURCE_REMOVE;
511 if (!g_socket_connect (socket, addr, NULL, NULL))
513 g_object_unref (addr);
514 return G_SOURCE_CONTINUE;
517 g_clear_object (&addr);
519 /* Wrap the socket in a GDtlsServerConnection. */
520 cert = g_tls_certificate_new_from_file (tls_test_file_path ("server-and-key.pem"), &error);
521 g_assert_no_error (error);
523 test->server_connection = g_dtls_server_connection_new (test->server_transport,
525 g_debug ("%s: Server connection %p on socket %p", G_STRFUNC, test->server_connection, socket);
526 g_assert_no_error (error);
527 g_object_unref (cert);
529 g_object_set (test->server_connection, "authentication-mode",
530 test->test_data->auth_mode, NULL);
531 g_signal_connect (test->server_connection, "accept-certificate",
532 G_CALLBACK (on_accept_certificate), test);
535 g_dtls_connection_set_database (G_DTLS_CONNECTION (test->server_connection), test->database);
537 if (test->test_data->server_should_disappear)
539 close_server_connection (test, FALSE);
540 return G_SOURCE_REMOVE;
545 g_clear_error (&test->server_error);
546 n_sent = g_datagram_based_send_messages (test->server_connection,
549 test->test_data->server_timeout, NULL,
550 &test->server_error);
551 g_main_context_iteration (test->server_context, FALSE);
553 while (g_error_matches (test->server_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
555 if (!test->server_error)
557 g_assert_cmpint (n_sent, ==, 1);
558 g_assert_cmpuint (message.bytes_sent, ==, vector.size);
561 if (!test->server_error && test->rehandshake)
563 test->rehandshake = FALSE;
564 g_dtls_connection_handshake_async (G_DTLS_CONNECTION (test->server_connection),
565 G_PRIORITY_DEFAULT, NULL,
566 on_rehandshake_finish_threaded, test);
567 return G_SOURCE_REMOVE;
570 if (test->test_data->server_should_close)
571 close_server_connection (test, TRUE);
573 return G_SOURCE_REMOVE;
577 server_service_cb (gpointer user_data)
579 TestConnection *test = user_data;
581 test->server_context = g_main_context_new ();
582 g_main_context_push_thread_default (test->server_context);
584 test->server_source = g_socket_create_source (test->server_socket, G_IO_IN,
586 g_source_set_callback (test->server_source,
587 (GSourceFunc) on_incoming_connection_threaded, test, NULL);
588 g_source_attach (test->server_source, test->server_context);
590 /* Run the server until it should stop. */
591 while (test->server_running)
592 g_main_context_iteration (test->server_context, TRUE);
594 g_main_context_pop_thread_default (test->server_context);
600 start_server_service (TestConnection *test,
607 g_thread_new ("dtls-server", server_service_cb, test);
611 test->server_source = g_socket_create_source (test->server_socket, G_IO_IN,
613 g_source_set_callback (test->server_source,
614 (GSourceFunc) on_incoming_connection, test, NULL);
615 g_source_attach (test->server_source, NULL);
618 static GDatagramBased *
619 start_server_and_connect_to_it (TestConnection *test,
622 GError *error = NULL;
624 GDatagramBased *transport;
626 start_server_service (test, threaded);
628 socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
629 G_SOCKET_PROTOCOL_UDP, &error);
630 g_assert_no_error (error);
632 g_socket_connect (socket, test->address, NULL, &error);
633 g_assert_no_error (error);
635 if (test->test_data->client_loss_inducer)
637 transport = lossy_socket_new (G_DATAGRAM_BASED (socket),
638 test->test_data->client_loss_inducer,
640 g_object_unref (socket);
644 transport = G_DATAGRAM_BASED (socket);
651 read_test_data_async (TestConnection *test)
654 GError *error = NULL;
655 guint8 buf[TEST_DATA_LENGTH * 2];
656 GInputVector vectors[2] = {
657 { buf, sizeof (buf) / 2 },
658 { buf + sizeof (buf) / 2, sizeof (buf) / 2 },
660 GInputMessage message = { NULL, vectors, G_N_ELEMENTS (vectors), 0, 0, NULL, NULL };
665 g_clear_error (&test->read_error);
666 n_read = g_datagram_based_receive_messages (test->client_connection,
669 test->test_data->client_timeout,
670 NULL, &test->read_error);
671 g_main_context_iteration (test->client_context, FALSE);
673 while (g_error_matches (test->read_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK));
675 if (!test->read_error)
677 g_assert_cmpint (n_read, ==, 1);
679 check = g_strdup (TEST_DATA);
680 g_assert_cmpuint (strlen (check), ==, message.bytes_received);
681 g_assert_cmpint (strncmp (check, (const char *)buf, message.bytes_received), ==, 0);
685 g_dtls_connection_close (G_DTLS_CONNECTION (test->client_connection),
687 g_assert_no_error (error);
689 test->loop_finished = TRUE;
692 /* Test that connecting a client to a server, both using main contexts in the
693 * same thread, works; and that sending a message from the server to the client
694 * before shutting down gracefully works. */
696 test_basic_connection (TestConnection *test,
699 GDatagramBased *connection;
700 GError *error = NULL;
702 connection = start_server_and_connect_to_it (test, FALSE);
703 test->client_connection = g_dtls_client_connection_new (connection, test->identity, &error);
704 g_debug ("%s: Client connection %p on socket %p", G_STRFUNC, test->client_connection, connection);
705 g_assert_no_error (error);
706 g_object_unref (connection);
708 /* No validation at all in this test */
709 g_dtls_client_connection_set_validation_flags (G_DTLS_CLIENT_CONNECTION (test->client_connection),
712 read_test_data_async (test);
713 while (!test->loop_finished)
714 g_main_context_iteration (test->client_context, TRUE);
716 g_assert_no_error (test->server_error);
717 g_assert_no_error (test->read_error);
720 /* Test that connecting a client to a server, both using separate threads,
721 * works; and that sending a message from the server to the client before
722 * shutting down gracefully works. */
724 test_threaded_connection (TestConnection *test,
727 GDatagramBased *connection;
728 GError *error = NULL;
730 connection = start_server_and_connect_to_it (test, TRUE);
731 test->client_connection = g_dtls_client_connection_new (connection, test->identity, &error);
732 g_debug ("%s: Client connection %p on socket %p", G_STRFUNC, test->client_connection, connection);
733 g_assert_no_error (error);
734 g_object_unref (connection);
736 /* No validation at all in this test */
737 g_dtls_client_connection_set_validation_flags (G_DTLS_CLIENT_CONNECTION (test->client_connection),
740 read_test_data_async (test);
741 while (!test->loop_finished)
742 g_main_context_iteration (test->client_context, TRUE);
744 g_assert_no_error (test->server_error);
745 g_assert_no_error (test->read_error);
748 /* Test that a client can successfully connect to a server, then the server
749 * disappears, and when the client tries to read from it, the client hits a
750 * timeout error (rather than blocking indefinitely or returning another
753 test_connection_timeouts_read (TestConnection *test,
756 GDatagramBased *connection;
757 GError *error = NULL;
759 connection = start_server_and_connect_to_it (test, TRUE);
760 test->client_connection = g_dtls_client_connection_new (connection,
761 test->identity, &error);
762 g_debug ("%s: Client connection %p on socket %p", G_STRFUNC,
763 test->client_connection, connection);
764 g_assert_no_error (error);
765 g_object_unref (connection);
767 /* No validation at all in this test */
768 g_dtls_client_connection_set_validation_flags (G_DTLS_CLIENT_CONNECTION (test->client_connection),
771 read_test_data_async (test);
772 while (!test->loop_finished)
773 g_main_context_iteration (test->client_context, TRUE);
775 g_assert_no_error (test->server_error);
776 g_assert_error (test->read_error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
780 drop_first_outgoing (const IODetails *io,
783 if (io->direction == IO_OUT && io->serial == 1)
793 const TestData blocking = {
794 -1, /* server_timeout */
795 0, /* client_timeout */
796 FALSE, /* server_should_disappear */
797 TRUE, /* server_should_close */
798 G_TLS_AUTHENTICATION_NONE, /* auth_mode */
799 NULL, NULL, /* loss inducers */
801 const TestData server_timeout = {
802 1000 * G_USEC_PER_SEC, /* server_timeout */
803 0, /* client_timeout */
804 FALSE, /* server_should_disappear */
805 TRUE, /* server_should_close */
806 G_TLS_AUTHENTICATION_NONE, /* auth_mode */
807 NULL, NULL, /* loss inducers */
809 const TestData nonblocking = {
810 0, /* server_timeout */
811 0, /* client_timeout */
812 FALSE, /* server_should_disappear */
813 TRUE, /* server_should_close */
814 G_TLS_AUTHENTICATION_NONE, /* auth_mode */
815 NULL, NULL, /* loss inducers */
817 const TestData client_timeout = {
818 0, /* server_timeout */
819 (gint64) (0.5 * G_USEC_PER_SEC), /* client_timeout */
820 TRUE, /* server_should_disappear */
821 TRUE, /* server_should_close */
822 G_TLS_AUTHENTICATION_NONE, /* auth_mode */
823 NULL, NULL, /* loss inducers */
825 const TestData client_loss = {
826 -1, /* server_timeout */
827 0, /* client_timeout */
828 FALSE, /* server_should_disappear */
829 TRUE, /* server_should_close */
830 G_TLS_AUTHENTICATION_NONE, /* auth_mode */
831 drop_first_outgoing, NULL, /* loss inducers */
833 const TestData server_loss = {
834 -1, /* server_timeout */
835 0, /* client_timeout */
836 FALSE, /* server_should_disappear */
837 TRUE, /* server_should_close */
838 G_TLS_AUTHENTICATION_NONE, /* auth_mode */
839 NULL, drop_first_outgoing, /* loss inducers */
844 /* Check if this is a subprocess, and set G_TLS_GNUTLS_PRIORITY
845 * appropriately if so.
847 for (i = 1; i < argc - 1; i++)
849 if (!strcmp (argv[i], "-p"))
851 const char *priority = argv[i + 1];
853 priority = strrchr (priority, '/');
855 (g_str_has_prefix (priority, "NORMAL:") ||
856 g_str_has_prefix (priority, "NONE:")))
857 g_setenv ("G_TLS_GNUTLS_PRIORITY", priority, TRUE);
862 g_test_init (&argc, &argv, NULL);
863 g_test_bug_base ("http://bugzilla.gnome.org/");
865 g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
866 g_setenv ("GIO_USE_TLS", BACKEND, TRUE);
867 g_assert_cmpint (g_ascii_strcasecmp (G_OBJECT_TYPE_NAME (g_tls_backend_get_default ()), "GTlsBackend" BACKEND), ==, 0);
869 g_test_add ("/dtls/" BACKEND "/connection/basic/blocking", TestConnection, &blocking,
870 setup_connection, test_basic_connection, teardown_connection);
871 g_test_add ("/dtls/" BACKEND "/connection/basic/timeout", TestConnection, &server_timeout,
872 setup_connection, test_basic_connection, teardown_connection);
873 g_test_add ("/dtls/" BACKEND "/connection/basic/nonblocking",
874 TestConnection, &nonblocking,
875 setup_connection, test_basic_connection, teardown_connection);
877 g_test_add ("/dtls/" BACKEND "/connection/threaded/blocking", TestConnection, &blocking,
878 setup_connection, test_threaded_connection, teardown_connection);
879 g_test_add ("/dtls/" BACKEND "/connection/threaded/timeout",
880 TestConnection, &server_timeout,
881 setup_connection, test_threaded_connection, teardown_connection);
882 g_test_add ("/dtls/" BACKEND "/connection/threaded/nonblocking",
883 TestConnection, &nonblocking,
884 setup_connection, test_threaded_connection, teardown_connection);
886 g_test_add ("/dtls/" BACKEND "/connection/timeouts/read", TestConnection, &client_timeout,
887 setup_connection, test_connection_timeouts_read,
888 teardown_connection);
890 g_test_add ("/dtls/" BACKEND "/connection/lossy/client", TestConnection, &client_loss,
891 setup_connection, test_basic_connection, teardown_connection);
892 g_test_add ("/dtls/" BACKEND "/connection/lossy/server", TestConnection, &server_loss,
893 setup_connection, test_basic_connection, teardown_connection);
897 /* for valgrinding */
898 g_main_context_unref (g_main_context_default ());