From 430516c8f22e26821a22868621e59ec201d6a805 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 9 Dec 2010 22:14:38 +0000 Subject: tests: Add test for basic verification. This test depends on the certificates you have in gnome-keyring, will fix this dependency in later commits. --- tests/empathy-tls-test.c | 60 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/empathy-tls-test.c b/tests/empathy-tls-test.c index 8da2cd002..12d2aa216 100644 --- a/tests/empathy-tls-test.c +++ b/tests/empathy-tls-test.c @@ -3,8 +3,11 @@ #include #include +#include #include "test-helper.h" +#include + #include #include #include @@ -280,9 +283,23 @@ accepted_callback (GObject *object, GAsyncResult *res, gpointer user_data) g_main_loop_quit (test->loop); } +static void +prepared_callback (GObject *object, GAsyncResult *res, gpointer user_data) +{ + GError *error = NULL; + Test *test = user_data; + + g_assert (EMPATHY_IS_TLS_CERTIFICATE (object)); + empathy_tls_certificate_prepare_finish (EMPATHY_TLS_CERTIFICATE (object), + res, &error); + g_assert_no_error (error); + + g_main_loop_quit (test->loop); +} + /* A simple test to make sure the test infrastructure is working */ static void -test_certificate_mock_accept (Test *test, gconstpointer data G_GNUC_UNUSED) +test_certificate_mock_basics (Test *test, gconstpointer data G_GNUC_UNUSED) { GError *error = NULL; EmpathyTLSCertificate *cert; @@ -294,34 +311,40 @@ test_certificate_mock_accept (Test *test, gconstpointer data G_GNUC_UNUSED) MOCK_TLS_CERTIFICATE_PATH, &error); g_assert_no_error (error); - empathy_tls_certificate_accept_async (cert, accepted_callback, test); - g_object_unref (cert); + empathy_tls_certificate_prepare_async (cert, prepared_callback, test); + g_main_loop_run (test->loop); + empathy_tls_certificate_accept_async (cert, accepted_callback, test); g_main_loop_run (test->loop); + g_object_unref (cert); g_assert (test->mock->state == TP_TLS_CERTIFICATE_STATE_ACCEPTED); } static void -prepared_callback (GObject *object, GAsyncResult *res, gpointer user_data) +verifier_callback (GObject *object, GAsyncResult *res, gpointer user_data) { + EmpTLSCertificateRejectReason reason = 0; + GHashTable *details = NULL; GError *error = NULL; Test *test = user_data; - g_assert (EMPATHY_IS_TLS_CERTIFICATE (object)); - empathy_tls_certificate_prepare_finish (EMPATHY_TLS_CERTIFICATE (object), - res, &error); + g_assert (EMPATHY_IS_TLS_VERIFIER (object)); + empathy_tls_verifier_verify_finish (EMPATHY_TLS_VERIFIER (object), + res, &reason, &details, &error); g_assert_no_error (error); - /* Stop the tests */ + if (details) + g_hash_table_destroy (details); g_main_loop_quit (test->loop); } static void -test_certificate_prepare (Test *test, gconstpointer data G_GNUC_UNUSED) +test_certificate_verify (Test *test, gconstpointer data G_GNUC_UNUSED) { GError *error = NULL; EmpathyTLSCertificate *cert; + EmpathyTLSVerifier *verifier; test->mock = mock_tls_certificate_new_and_register (test->dbus, "dhansak-collabora.cer"); @@ -331,9 +354,19 @@ test_certificate_prepare (Test *test, gconstpointer data G_GNUC_UNUSED) g_assert_no_error (error); empathy_tls_certificate_prepare_async (cert, prepared_callback, test); + g_main_loop_run (test->loop); + + verifier = empathy_tls_verifier_new (cert, "another-host"); + empathy_tls_verifier_verify_async (verifier, verifier_callback, test); + g_main_loop_run (test->loop); + +#if 0 + empathy_tls_certificate_accept_async (cert, accepted_callback, test); g_main_loop_run (test->loop); +#endif + g_object_unref (verifier); g_object_unref (cert); } @@ -344,11 +377,12 @@ main (int argc, int result; test_init (argc, argv); + gnutls_global_init (); - g_test_add ("/tls/certificate_accept", Test, NULL, - setup, test_certificate_mock_accept, teardown); - g_test_add ("/tls/certificate_prepare", Test, NULL, - setup, test_certificate_prepare, teardown); + g_test_add ("/tls/certificate_basics", Test, NULL, + setup, test_certificate_mock_basics, teardown); + g_test_add ("/tls/certificate_verify", Test, NULL, + setup, test_certificate_verify, teardown); result = g_test_run (); test_deinit (); -- cgit v1.2.1