]> git.0d.be Git - empathy.git/blobdiff - tests/empathy-tls-test.c
Merge branch 'gnome-3-8'
[empathy.git] / tests / empathy-tls-test.c
index e2ba5b4cc65e95b0af5bdcecd384795610309ae2..2155c68b27addf05ec8896fb244e075eb7b9130e 100644 (file)
@@ -1,22 +1,9 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <libempathy/empathy-tls-certificate.h>
-#include <libempathy/empathy-tls-verifier.h>
-#include "test-helper.h"
-#include "mock-pkcs11.h"
-
-#include <gcr/gcr.h>
-
 #include <gnutls/gnutls.h>
-
-#include <telepathy-glib/dbus-properties-mixin.h>
-#include <telepathy-glib/enums.h>
-#include <telepathy-glib/interfaces.h>
 #include <telepathy-glib/svc-tls.h>
-#include <telepathy-glib/svc-generic.h>
-#include <telepathy-glib/telepathy-glib.h>
+
+#include "empathy-tls-verifier.h"
+#include "mock-pkcs11.h"
+#include "test-helper.h"
 
 #define MOCK_TLS_CERTIFICATE_PATH "/mock/certificate"
 
@@ -206,10 +193,10 @@ mock_tls_certificate_iface_init (gpointer g_iface,
 #if 0
 static void
 mock_tls_certificate_assert_rejected (MockTLSCertificate *self,
-        EmpTLSCertificateRejectReason reason)
+        TpTLSCertificateRejectReason reason)
 {
   GValueArray *rejection;
-  EmpTLSCertificateRejectReason rejection_reason;
+  TpTLSCertificateRejectReason rejection_reason;
   gchar *rejection_error;
   GHashTable *rejection_details;
   guint i;
@@ -282,7 +269,7 @@ typedef struct {
   TpDBusDaemon *dbus;
   const gchar *dbus_name;
   MockTLSCertificate *mock;
-  EmpathyTLSCertificate *cert;
+  TpTLSCertificate *cert;
   GAsyncResult *result;
 } Test;
 
@@ -384,17 +371,22 @@ static void
 ensure_certificate_proxy (Test *test)
 {
   GError *error = NULL;
+  GQuark features[] = { TP_TLS_CERTIFICATE_FEATURE_CORE, 0 };
 
   if (test->cert)
     return;
 
   /* Create and prepare a certificate */
-  test->cert = empathy_tls_certificate_new (test->dbus, test->dbus_name,
-          MOCK_TLS_CERTIFICATE_PATH, &error);
-  g_assert_no_error (error);
-  empathy_tls_certificate_prepare_async (test->cert, fetch_callback_result, test);
+  /* We don't use tp_tls_certificate_new() as we don't pass a parent */
+  test->cert = g_object_new (TP_TYPE_TLS_CERTIFICATE,
+      "dbus-daemon", test->dbus,
+      "bus-name", test->dbus_name,
+      "object-path", MOCK_TLS_CERTIFICATE_PATH,
+      NULL);
+
+  tp_proxy_prepare_async (test->cert, features, fetch_callback_result, test);
   g_main_loop_run (test->loop);
-  empathy_tls_certificate_prepare_finish (test->cert, test->result, &error);
+  tp_proxy_prepare_finish (test->cert, test->result, &error);
   g_assert_no_error (error);
 
   /* Clear for any future async stuff */
@@ -410,13 +402,13 @@ test_certificate_mock_basics (Test *test,
   GError *error = NULL;
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", NULL);
+          "server-cert.cer", NULL);
 
   ensure_certificate_proxy (test);
 
-  empathy_tls_certificate_accept_async (test->cert, fetch_callback_result, test);
+  tp_tls_certificate_accept_async (test->cert, fetch_callback_result, test);
   g_main_loop_run (test->loop);
-  empathy_tls_certificate_accept_finish (test->cert, test->result, &error);
+  tp_tls_certificate_accept_finish (test->cert, test->result, &error);
   g_assert_no_error (error);
 
   g_assert (test->mock->state == TP_TLS_CERTIFICATE_STATE_ACCEPTED);
@@ -426,11 +418,11 @@ static void
 test_certificate_verify_success_with_pkcs11_lookup (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
-    "www.collabora.co.uk",
+    "test-server.empathy.gnome.org",
     NULL
   };
 
@@ -441,14 +433,14 @@ test_certificate_verify_success_with_pkcs11_lookup (Test *test,
    */
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", NULL);
+          "server-cert.cer", NULL);
 
   /* We add the collabora directory with the collabora root */
-  add_certificate_to_mock (test, "collabora-ca.cer", NULL);
+  add_certificate_to_mock (test, "certificate-authority.cer", NULL);
 
   ensure_certificate_proxy (test);
 
-  verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
+  verifier = empathy_tls_verifier_new (test->cert, "test-server.empathy.gnome.org",
       reference_identities);
   empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
   g_main_loop_run (test->loop);
@@ -467,11 +459,11 @@ static void
 test_certificate_verify_success_with_full_chain (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
-    "www.collabora.co.uk",
+    "test-server.empathy.gnome.org",
     NULL
   };
 
@@ -481,14 +473,14 @@ test_certificate_verify_success_with_full_chain (Test *test,
    */
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", "collabora-ca.cer", NULL);
+          "server-cert.cer", "certificate-authority.cer", NULL);
 
   /* We add the collabora directory with the collabora root */
-  add_certificate_to_mock (test, "collabora-ca.cer", NULL);
+  add_certificate_to_mock (test, "certificate-authority.cer", NULL);
 
   ensure_certificate_proxy (test);
 
-  verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
+  verifier = empathy_tls_verifier_new (test->cert, "test-server.empathy.gnome.org",
       reference_identities);
   empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
   g_main_loop_run (test->loop);
@@ -506,22 +498,22 @@ static void
 test_certificate_verify_root_not_found (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
-    "www.collabora.co.uk",
+    "test-server.empathy.gnome.org",
     NULL
   };
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", NULL);
+          "server-cert.cer", NULL);
 
   /* Note that we're not adding any place to find root certs */
 
   ensure_certificate_proxy (test);
 
-  verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
+  verifier = empathy_tls_verifier_new (test->cert, "test-server.empathy.gnome.org",
       reference_identities);
   empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
   g_main_loop_run (test->loop);
@@ -531,7 +523,7 @@ test_certificate_verify_root_not_found (Test *test,
 
   /* And it should say we're self-signed (oddly enough) */
   g_assert_error (error, G_IO_ERROR,
-      EMP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
+      TP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
 
   g_clear_error (&error);
   g_object_unref (verifier);
@@ -541,22 +533,22 @@ static void
 test_certificate_verify_root_not_anchored (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
-    "www.collabora.co.uk",
+    "test-server.empathy.gnome.org",
     NULL
   };
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", "collabora-ca.cer", NULL);
+          "server-cert.cer", "certificate-authority.cer", NULL);
 
   /* Note that we're not adding any place to find root certs */
 
   ensure_certificate_proxy (test);
 
-  verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
+  verifier = empathy_tls_verifier_new (test->cert, "test-server.empathy.gnome.org",
       reference_identities);
   empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
   g_main_loop_run (test->loop);
@@ -566,7 +558,7 @@ test_certificate_verify_root_not_anchored (Test *test,
 
   /* And it should say we're self-signed (oddly enough) */
   g_assert_error (error, G_IO_ERROR,
-      EMP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
+      TP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
 
   g_clear_error (&error);
   g_object_unref (verifier);
@@ -576,7 +568,7 @@ static void
 test_certificate_verify_identities_invalid (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
@@ -585,10 +577,10 @@ test_certificate_verify_identities_invalid (Test *test,
   };
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", "collabora-ca.cer", NULL);
+          "server-cert.cer", "certificate-authority.cer", NULL);
 
   /* We add the collabora directory with the collabora root */
-  add_certificate_to_mock (test, "collabora-ca.cer", NULL);
+  add_certificate_to_mock (test, "certificate-authority.cer", NULL);
 
   ensure_certificate_proxy (test);
 
@@ -602,7 +594,7 @@ test_certificate_verify_identities_invalid (Test *test,
 
   /* And it should say we're self-signed (oddly enough) */
   g_assert_error (error, G_IO_ERROR,
-      EMP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH);
+      TP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH);
 
   g_clear_error (&error);
   g_object_unref (verifier);
@@ -612,7 +604,7 @@ static void
 test_certificate_verify_uses_reference_identities (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
@@ -621,15 +613,15 @@ test_certificate_verify_uses_reference_identities (Test *test,
   };
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", "collabora-ca.cer", NULL);
+          "server-cert.cer", "certificate-authority.cer", NULL);
 
   /* We add the collabora directory with the collabora root */
-  add_certificate_to_mock (test, "collabora-ca.cer", NULL);
+  add_certificate_to_mock (test, "certificate-authority.cer", NULL);
 
   ensure_certificate_proxy (test);
 
   /* Should be using the reference_identities and not host name for checks */
-  verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
+  verifier = empathy_tls_verifier_new (test->cert, "test-server.empathy.gnome.org",
       reference_identities);
   empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
   g_main_loop_run (test->loop);
@@ -639,7 +631,7 @@ test_certificate_verify_uses_reference_identities (Test *test,
 
   /* And it should say we're self-signed (oddly enough) */
   g_assert_error (error, G_IO_ERROR,
-      EMP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH);
+      TP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH);
 
   g_clear_error (&error);
   g_object_unref (verifier);
@@ -649,11 +641,11 @@ static void
 test_certificate_verify_success_with_pinned (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
-    "www.collabora.co.uk",
+    "test-server.empathy.gnome.org",
     NULL
   };
 
@@ -663,14 +655,14 @@ test_certificate_verify_success_with_pinned (Test *test,
    */
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", NULL);
+          "server-cert.cer", NULL);
 
   /* We add the collabora directory with the collabora root */
-  add_certificate_to_mock (test, "dhansak-collabora.cer", "www.collabora.co.uk");
+  add_certificate_to_mock (test, "server-cert.cer", "test-server.empathy.gnome.org");
 
   ensure_certificate_proxy (test);
 
-  verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
+  verifier = empathy_tls_verifier_new (test->cert, "test-server.empathy.gnome.org",
       reference_identities);
   empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
   g_main_loop_run (test->loop);
@@ -688,22 +680,22 @@ static void
 test_certificate_verify_pinned_wrong_host (Test *test,
         gconstpointer data G_GNUC_UNUSED)
 {
-  EmpTLSCertificateRejectReason reason = 0;
+  TpTLSCertificateRejectReason reason = 0;
   GError *error = NULL;
   EmpathyTLSVerifier *verifier;
   const gchar *reference_identities[] = {
-    "www.collabora.co.uk",
+    "test-server.empathy.gnome.org",
     NULL
   };
 
   test->mock = mock_tls_certificate_new_and_register (test->dbus,
-          "dhansak-collabora.cer", NULL);
+          "server-cert.cer", NULL);
 
   /* Note that we're not adding any place to find root certs */
 
   ensure_certificate_proxy (test);
 
-  verifier = empathy_tls_verifier_new (test->cert, "another.collabora.co.uk",
+  verifier = empathy_tls_verifier_new (test->cert, "another.gnome.org",
       reference_identities);
   empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
   g_main_loop_run (test->loop);
@@ -713,7 +705,7 @@ test_certificate_verify_pinned_wrong_host (Test *test,
 
   /* And it should say we're self-signed */
   g_assert_error (error, G_IO_ERROR,
-      EMP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
+      TP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
 
   g_clear_error (&error);
   g_object_unref (verifier);