[gnome-keyring: 101/102] [gcr] Make tests use pkcs11.conf.defaults from srcdir.



commit 8c57f2cf3408d1a64a50c01bf823c2232f48bf29
Author: Stef Walter <stefw collabora co uk>
Date:   Wed Dec 22 17:16:49 2010 +0000

    [gcr] Make tests use pkcs11.conf.defaults from srcdir.
    
    So that make distcheck passes, and tests run without
    a prior 'make install'

 gcr/Makefile.am                     |    8 ++------
 gcr/gcr-internal.h                  |    4 ++++
 gcr/gcr-library.c                   |   29 ++++++++++++++++++-----------
 gcr/tests/Makefile.am               |    1 +
 gcr/tests/test-certificate-chain.c  |    4 ++++
 gcr/tests/test-certificate.c        |    4 ++++
 gcr/tests/test-pkcs11-certificate.c |    4 ++++
 gcr/tests/test-simple-certificate.c |    3 +++
 gcr/tests/test-trust.c              |    4 ++++
 gcr/tests/unit-test-parser.c        |    4 ++++
 10 files changed, 48 insertions(+), 17 deletions(-)
---
diff --git a/gcr/Makefile.am b/gcr/Makefile.am
index 72d757a..e92ffd4 100644
--- a/gcr/Makefile.am
+++ b/gcr/Makefile.am
@@ -13,11 +13,8 @@ ui_DATA = \
 
 confdir = $(sysconfdir)/xdg
 
-PKCS11_DEFAULT_FILE =  pkcs11.conf.defaults
-PKCS11_CONFIG_FILE = pkcs11.conf
-
 conf_DATA = \
-	$(PKCS11_DEFAULT_FILE)
+	pkcs11.conf.defaults
 
 # ------------------------------------------------------------------
 # HEADERS
@@ -86,8 +83,7 @@ libgcr GCR_VERSION_SUFFIX@_la_SOURCES = \
 	$(BUILT_SOURCES)
 
 libgcr GCR_VERSION_SUFFIX@_la_CFLAGS = \
-	-DPKCS11_DEFAULT_PATH=\""$(confdir)/$(PKCS11_DEFAULT_FILE)"\" \
-	-DPKCS11_CONFIG_PATH=\""$(confdir)/$(PKCS11_CONFIG_FILE)"\" \
+	-DPKCS11_CONFIG_DIR=\""$(confdir)"\" \
 	-DGCK_API_SUBJECT_TO_CHANGE \
 	-DGCR_API_SUBJECT_TO_CHANGE \
 	-DGCR_COMPILATION \
diff --git a/gcr/gcr-internal.h b/gcr/gcr-internal.h
index 421282a..99200c7 100644
--- a/gcr/gcr-internal.h
+++ b/gcr/gcr-internal.h
@@ -24,6 +24,10 @@
 #ifndef GCR_INTERNAL_H_
 #define GCR_INTERNAL_H_
 
+#include <glib.h>
+
 void              _gcr_initialize                  (void);
 
+void              _gcr_set_pkcs11_config_dir       (const gchar *dir);
+
 #endif /* GCR_INTERNAL_H_ */
diff --git a/gcr/gcr-library.c b/gcr/gcr-library.c
index aca6592..eba3763 100644
--- a/gcr/gcr-library.c
+++ b/gcr/gcr-library.c
@@ -57,6 +57,7 @@
  */
 static GList *all_modules = NULL;
 
+static const gchar *config_dir = PKCS11_CONFIG_DIR;
 static gchar *trust_store_uri = NULL;
 static gchar **trust_lookup_uris = NULL;
 
@@ -158,7 +159,7 @@ _gcr_initialize (void)
 	static volatile gsize gcr_initialized = 0;
 	GError *error = NULL;
 	GKeyFile *key_file;
-	gchar *value;
+	gchar *value, *path;
 
 	/* Initialize the libgcrypt library if needed */
 	egg_libgcrypt_initialize ();
@@ -169,21 +170,21 @@ _gcr_initialize (void)
 		key_file = g_key_file_new ();
 
 		/* Load the defaults */
-		if (!g_key_file_load_from_file (key_file, PKCS11_DEFAULT_PATH,
-		                                G_KEY_FILE_NONE, &error)) {
-			g_warning ("couldn't parse %s file: %s", PKCS11_DEFAULT_PATH,
-			           egg_error_message (error));
+		path = g_build_filename (config_dir, "pkcs11.conf.defaults", NULL);
+		if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error)) {
+			g_warning ("couldn't parse %s file: %s", path, egg_error_message (error));
 			g_clear_error (&error);
 		}
+		g_free (path);
 
-		/* Load any changes */
-		if (g_file_test (PKCS11_CONFIG_PATH, G_FILE_TEST_EXISTS) &&
-		    !g_key_file_load_from_file (key_file, PKCS11_CONFIG_PATH,
-		                                G_KEY_FILE_NONE, &error)) {
-			g_warning ("couldn't parse %s file: %s", PKCS11_CONFIG_PATH,
-			           egg_error_message (error));
+		/* Load any overrides */
+		path = g_build_filename (config_dir, "pkcs11.conf", NULL);
+		if (g_file_test (path, G_FILE_TEST_EXISTS) &&
+		    !g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error)) {
+			g_warning ("couldn't parse %s file: %s", path, egg_error_message (error));
 			g_clear_error (&error);
 		}
+		g_free (path);
 
 		trust_store_uri = g_key_file_get_string (key_file, "trust-assertions", "storage", NULL);
 
@@ -197,6 +198,12 @@ _gcr_initialize (void)
 	}
 }
 
+void
+_gcr_set_pkcs11_config_dir (const gchar *dir)
+{
+	config_dir = dir;
+}
+
 /**
  * gcr_pkcs11_get_modules:
  *
diff --git a/gcr/tests/Makefile.am b/gcr/tests/Makefile.am
index fab95d8..bfea68e 100644
--- a/gcr/tests/Makefile.am
+++ b/gcr/tests/Makefile.am
@@ -15,6 +15,7 @@ TESTING_LIBS =  \
 	$(top_builddir)/gck/libgck.la
 
 TESTING_FLAGS = \
+	-DTEST_CONFIG_DIR=\""$(srcdir)/.."\" \
 	-DGCR_API_SUBJECT_TO_CHANGE \
 	-DGCK_API_SUBJECT_TO_CHANGE
 
diff --git a/gcr/tests/test-certificate-chain.c b/gcr/tests/test-certificate-chain.c
index 94a7d3b..2cb5318 100644
--- a/gcr/tests/test-certificate-chain.c
+++ b/gcr/tests/test-certificate-chain.c
@@ -6,6 +6,7 @@
 #include "egg/egg-asn1-defs.h"
 
 #include "gcr/gcr.h"
+#include "gcr/gcr-internal.h"
 
 #include "gck/gck-mock.h"
 #include "gck/gck-test.h"
@@ -109,6 +110,9 @@ TESTING_SETUP (certificate_chain)
 	CK_RV rv;
 	GckModule *module;
 
+	/* Look for the config in the build directory */
+	_gcr_set_pkcs11_config_dir (TEST_CONFIG_DIR);
+
 	rv = gck_mock_C_GetFunctionList (&f);
 	gck_assert_cmprv (rv, ==, CKR_OK);
 	memcpy (&funcs, f, sizeof (funcs));
diff --git a/gcr/tests/test-certificate.c b/gcr/tests/test-certificate.c
index 73afb13..28be047 100644
--- a/gcr/tests/test-certificate.c
+++ b/gcr/tests/test-certificate.c
@@ -3,6 +3,7 @@
 #include "test-suite.h"
 
 #include "gcr/gcr.h"
+#include "gcr/gcr-internal.h"
 
 #include <glib.h>
 
@@ -17,6 +18,9 @@ TESTING_SETUP(certificate)
 	guchar *contents;
 	gsize n_contents;
 
+	/* Look for the config in the build directory */
+	_gcr_set_pkcs11_config_dir (TEST_CONFIG_DIR);
+
 	contents = testing_data_read ("der-certificate.crt", &n_contents);
 	certificate = gcr_simple_certificate_new (contents, n_contents);
 	g_assert (certificate);
diff --git a/gcr/tests/test-pkcs11-certificate.c b/gcr/tests/test-pkcs11-certificate.c
index 117c8c7..91a6d9e 100644
--- a/gcr/tests/test-pkcs11-certificate.c
+++ b/gcr/tests/test-pkcs11-certificate.c
@@ -28,6 +28,7 @@
 #include "egg/egg-asn1-defs.h"
 
 #include "gcr.h"
+#include "gcr/gcr-internal.h"
 
 #include "gck/gck-mock.h"
 #include "gck/gck-test.h"
@@ -53,6 +54,9 @@ TESTING_SETUP (pkcs11_certificate)
 	GNode *asn, *node;
 	CK_RV rv;
 
+	/* Look for the config in the build directory */
+	_gcr_set_pkcs11_config_dir (TEST_CONFIG_DIR);
+
 	cert_data = testing_data_read ("der-certificate.crt", &n_cert_data);
 	g_assert (cert_data);
 
diff --git a/gcr/tests/test-simple-certificate.c b/gcr/tests/test-simple-certificate.c
index 3bc18dd..2ef7a96 100644
--- a/gcr/tests/test-simple-certificate.c
+++ b/gcr/tests/test-simple-certificate.c
@@ -38,6 +38,9 @@ static gsize n_cert_data;
 
 TESTING_SETUP (simple_certificate)
 {
+	/* Look for the config in the build directory */
+	_gcr_set_pkcs11_config_dir (TEST_CONFIG_DIR);
+
 	cert_data = testing_data_read ("der-certificate.crt", &n_cert_data);
 	g_assert (cert_data);
 }
diff --git a/gcr/tests/test-trust.c b/gcr/tests/test-trust.c
index 923dcd5..c74cd5f 100644
--- a/gcr/tests/test-trust.c
+++ b/gcr/tests/test-trust.c
@@ -25,6 +25,7 @@
 #include "test-suite.h"
 
 #include "gcr.h"
+#include "gcr/gcr-internal.h"
 
 #include "gck/gck-mock.h"
 #include "gck/gck-test.h"
@@ -48,6 +49,9 @@ TESTING_SETUP (trust_setup)
 	gsize len;
 	CK_RV rv;
 
+	/* Look for the config in the build directory */
+	_gcr_set_pkcs11_config_dir (TEST_CONFIG_DIR);
+
 	contents = testing_data_read ("der-certificate.crt", &len);
 	g_assert (contents);
 
diff --git a/gcr/tests/unit-test-parser.c b/gcr/tests/unit-test-parser.c
index c2ecf32..e06cb52 100644
--- a/gcr/tests/unit-test-parser.c
+++ b/gcr/tests/unit-test-parser.c
@@ -29,6 +29,7 @@
 #include "egg/egg-secure-memory.h"
 
 #include "gcr/gcr.h"
+#include "gcr/gcr-internal.h"
 
 #include "gck/gck.h"
 
@@ -93,6 +94,9 @@ authenticate (GcrParser *par, gint state, gpointer user_data)
 
 TESTING_SETUP(parser)
 {
+	/* Look for the config in the build directory */
+	_gcr_set_pkcs11_config_dir (TEST_CONFIG_DIR);
+
 	parser = gcr_parser_new ();
 	g_signal_connect (parser, "parsed", G_CALLBACK (parsed_item), parser);
 	g_signal_connect (parser, "authenticate", G_CALLBACK (authenticate), parser);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]