gnutls: Add test for g_tls_certificate_is_same()
authorStef Walter <stefw@gnome.org>
Fri, 3 Aug 2012 16:46:36 +0000 (18:46 +0200)
committerStef Walter <stefw@gnome.org>
Fri, 3 Aug 2012 17:00:44 +0000 (19:00 +0200)
 * The test can't live in glib since there's no implementation of
   GTlsCertificate there.

https://bugzilla.gnome.org/show_bug.cgi?id=681154

tls/tests/certificate.c
tls/tests/file-database.c

index eb1217d..2598ff1 100644 (file)
@@ -320,6 +320,35 @@ test_verify_certificate_bad_combo (TestVerify      *test,
   g_object_unref (identity);
 }
 
+static void
+test_certificate_is_same (void)
+{
+  GTlsCertificate *one;
+  GTlsCertificate *two;
+  GTlsCertificate *three;
+  GError *error = NULL;
+
+  one = g_tls_certificate_new_from_file (TEST_FILE ("client.pem"), &error);
+  g_assert_no_error (error);
+
+  two = g_tls_certificate_new_from_file (TEST_FILE ("client-and-key.pem"), &error);
+  g_assert_no_error (error);
+
+  three = g_tls_certificate_new_from_file (TEST_FILE ("server.pem"), &error);
+  g_assert_no_error (error);
+
+  g_assert (g_tls_certificate_is_same (one, two) == TRUE);
+  g_assert (g_tls_certificate_is_same (two, one) == TRUE);
+  g_assert (g_tls_certificate_is_same (three, one) == FALSE);
+  g_assert (g_tls_certificate_is_same (one, three) == FALSE);
+  g_assert (g_tls_certificate_is_same (two, three) == FALSE);
+  g_assert (g_tls_certificate_is_same (three, two) == FALSE);
+
+  g_object_unref (one);
+  g_object_unref (two);
+  g_object_unref (three);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -351,5 +380,7 @@ main (int   argc,
   g_test_add ("/tls/certificate/verify-bad-combo", TestVerify, NULL,
               setup_verify, test_verify_certificate_bad_combo, teardown_verify);
 
+  g_test_add_func ("/tls/certificate/is-same", test_certificate_is_same);
+
   return g_test_run();
 }
index 69ba0a2..a7ef16e 100644 (file)
@@ -324,7 +324,7 @@ certificate_is_in_list (GList *certificates,
 
   for (l = certificates; l != NULL; l = g_list_next (l))
     {
-      if (g_tls_certificate_equal (l->data, cert))
+      if (g_tls_certificate_is_same (l->data, cert))
         break;
     }