mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
tests: use new g_test_build_filename() API
Port most of the tests to the new g_test_build_filename() API. https://bugzilla.gnome.org/show_bug.cgi?id=549783
This commit is contained in:
@@ -26,8 +26,6 @@
|
||||
|
||||
#include "gtesttlsbackend.h"
|
||||
|
||||
gchar *datapath;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gchar *cert_pems[3];
|
||||
@@ -46,7 +44,7 @@ pem_parser (const Reference *ref)
|
||||
GError *error = NULL;
|
||||
|
||||
/* Check PEM parsing in certificate, private key order. */
|
||||
path = g_build_filename (datapath, "cert-key.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert-key.pem", NULL);
|
||||
g_file_get_contents (path, &pem, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pem);
|
||||
@@ -75,7 +73,7 @@ pem_parser (const Reference *ref)
|
||||
g_free (pem);
|
||||
|
||||
/* Check PEM parsing in private key, certificate order */
|
||||
path = g_build_filename (datapath, "key-cert.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem", NULL);
|
||||
g_file_get_contents (path, &pem, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pem);
|
||||
@@ -99,7 +97,7 @@ pem_parser (const Reference *ref)
|
||||
g_object_unref (cert);
|
||||
|
||||
/* Check certificate only PEM */
|
||||
path = g_build_filename (datapath, "cert1.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
|
||||
g_file_get_contents (path, &pem, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pem);
|
||||
@@ -122,7 +120,7 @@ pem_parser (const Reference *ref)
|
||||
g_object_unref (cert);
|
||||
|
||||
/* Check error with private key only PEM */
|
||||
path = g_build_filename (datapath, "key.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL);
|
||||
g_file_get_contents (path, &pem, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pem);
|
||||
@@ -144,7 +142,7 @@ from_file (const Reference *ref)
|
||||
gchar *path;
|
||||
GError *error = NULL;
|
||||
|
||||
path = g_build_filename (datapath, "key-cert.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem", NULL);
|
||||
cert = g_tls_certificate_new_from_file (path, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (cert);
|
||||
@@ -172,8 +170,8 @@ from_files (const Reference *ref)
|
||||
gchar *path, *path2;
|
||||
GError *error = NULL;
|
||||
|
||||
path = g_build_filename (datapath, "cert1.pem", NULL);
|
||||
path2 = g_build_filename (datapath, "key.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
|
||||
path2 = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL);
|
||||
cert = g_tls_certificate_new_from_files (path, path2, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (cert);
|
||||
@@ -193,8 +191,8 @@ from_files (const Reference *ref)
|
||||
g_object_unref (cert);
|
||||
|
||||
/* Missing private key */
|
||||
path = g_build_filename (datapath, "cert1.pem", NULL);
|
||||
path2 = g_build_filename (datapath, "cert2.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
|
||||
path2 = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert2.pem", NULL);
|
||||
cert = g_tls_certificate_new_from_files (path, path2, &error);
|
||||
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
|
||||
g_clear_error (&error);
|
||||
@@ -203,7 +201,7 @@ from_files (const Reference *ref)
|
||||
g_free (path2);
|
||||
|
||||
/* Missing certificate */
|
||||
path = g_build_filename (datapath, "key.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL);
|
||||
cert = g_tls_certificate_new_from_files (path, path, &error);
|
||||
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
|
||||
g_clear_error (&error);
|
||||
@@ -213,7 +211,7 @@ from_files (const Reference *ref)
|
||||
/* Using this method twice with a file containing both private key and
|
||||
* certificate as a way to inforce private key presence is a fair use
|
||||
*/
|
||||
path = g_build_filename (datapath, "key-cert.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key-cert.pem", NULL);
|
||||
cert = g_tls_certificate_new_from_files (path, path, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (cert);
|
||||
@@ -231,8 +229,8 @@ from_files_pkcs8 (const Reference *ref)
|
||||
gchar *path, *path2;
|
||||
GError *error = NULL;
|
||||
|
||||
path = g_build_filename (datapath, "cert1.pem", NULL);
|
||||
path2 = g_build_filename (datapath, "key8.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
|
||||
path2 = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key8.pem", NULL);
|
||||
cert = g_tls_certificate_new_from_files (path, path2, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (cert);
|
||||
@@ -260,7 +258,7 @@ list_from_file (const Reference *ref)
|
||||
gchar *path;
|
||||
int i;
|
||||
|
||||
path = g_build_filename (datapath, "cert-list.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert-list.pem", NULL);
|
||||
list = g_tls_certificate_list_new_from_file (path, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpint (g_list_length (list), ==, 3);
|
||||
@@ -282,7 +280,7 @@ list_from_file (const Reference *ref)
|
||||
g_list_free_full (list, g_object_unref);
|
||||
|
||||
/* Empty list is not an error */
|
||||
path = g_build_filename (datapath, "nothing.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "nothing.pem", NULL);
|
||||
list = g_tls_certificate_list_new_from_file (path, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpint (g_list_length (list), ==, 0);
|
||||
@@ -298,37 +296,32 @@ main (int argc,
|
||||
GError *error = NULL;
|
||||
gchar *path;
|
||||
|
||||
if (g_getenv ("G_TEST_DATA"))
|
||||
datapath = g_build_filename (g_getenv ("G_TEST_DATA"), "cert-tests", NULL);
|
||||
else
|
||||
datapath = g_build_filename (SRCDIR, "cert-tests", NULL);
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
_g_test_tls_backend_get_type ();
|
||||
|
||||
/* Load reference PEM */
|
||||
path = g_build_filename (datapath, "cert1.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert1.pem", NULL);
|
||||
g_file_get_contents (path, &ref.cert_pems[0], NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ref.cert_pems[0]);
|
||||
g_free (path);
|
||||
path = g_build_filename (datapath, "cert2.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert2.pem", NULL);
|
||||
g_file_get_contents (path, &ref.cert_pems[1], NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ref.cert_pems[1]);
|
||||
g_free (path);
|
||||
path = g_build_filename (datapath, "cert3.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "cert3.pem", NULL);
|
||||
g_file_get_contents (path, &ref.cert_pems[2], NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ref.cert_pems[2]);
|
||||
g_free (path);
|
||||
path = g_build_filename (datapath, "key.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key.pem", NULL);
|
||||
g_file_get_contents (path, &ref.key_pem, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ref.key_pem);
|
||||
g_free (path);
|
||||
path = g_build_filename (datapath, "key8.pem", NULL);
|
||||
path = g_test_build_filename (G_TEST_DISTED, "cert-tests", "key8.pem", NULL);
|
||||
g_file_get_contents (path, &ref.key8_pem, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ref.key8_pem);
|
||||
|
Reference in New Issue
Block a user