aboutsummaryrefslogtreecommitdiffstats
path: root/tests/empathy-tls-test.c
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2010-12-10 06:14:38 +0800
committerStef Walter <stefw@collabora.co.uk>2010-12-24 21:40:02 +0800
commit430516c8f22e26821a22868621e59ec201d6a805 (patch)
tree03f98ffb2058b0014119cbe71f30bcd876ba0f7b /tests/empathy-tls-test.c
parentd6cacab44d2c134688c79be7d62ab4307ce7f527 (diff)
downloadgsoc2013-empathy-430516c8f22e26821a22868621e59ec201d6a805.tar
gsoc2013-empathy-430516c8f22e26821a22868621e59ec201d6a805.tar.gz
gsoc2013-empathy-430516c8f22e26821a22868621e59ec201d6a805.tar.bz2
gsoc2013-empathy-430516c8f22e26821a22868621e59ec201d6a805.tar.lz
gsoc2013-empathy-430516c8f22e26821a22868621e59ec201d6a805.tar.xz
gsoc2013-empathy-430516c8f22e26821a22868621e59ec201d6a805.tar.zst
gsoc2013-empathy-430516c8f22e26821a22868621e59ec201d6a805.zip
tests: Add test for basic verification.
This test depends on the certificates you have in gnome-keyring, will fix this dependency in later commits.
Diffstat (limited to 'tests/empathy-tls-test.c')
-rw-r--r--tests/empathy-tls-test.c60
1 files changed, 47 insertions, 13 deletions
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 <string.h>
#include <libempathy/empathy-tls-certificate.h>
+#include <libempathy/empathy-tls-verifier.h>
#include "test-helper.h"
+#include <gnutls/gnutls.h>
+
#include <telepathy-glib/dbus-properties-mixin.h>
#include <telepathy-glib/enums.h>
#include <telepathy-glib/interfaces.h>
@@ -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 ();