summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-04-02 07:34:25 +0200
committerStef Walter <stefw@gnome.org>2012-04-02 16:07:20 +0200
commitd4c5661a695b5fc4a0126a4583e30ef70aea54ac (patch)
treea26b4a371bddb030cda4ead5f9fd1350bdcdef28
parentc43038d82edcfd878ff66e3aa7fe247f53876f9b (diff)
downloadp11-kit-d4c5661a695b5fc4a0126a4583e30ef70aea54ac.tar.gz
Build some test modules for testing main p11-kit functionality
* And put together a test for duplicate modules
-rw-r--r--p11-kit/Makefile.am29
-rw-r--r--tests/Makefile.am32
-rw-r--r--tests/conf-test.c16
-rw-r--r--tests/files/system-modules/one2
-rw-r--r--tests/files/system-modules/two2
-rw-r--r--tests/files/system-modules/two-duplicate3
-rw-r--r--tests/files/user-modules/three2
-rw-r--r--tests/mock-module-ep.c50
-rw-r--r--tests/test-modules.c111
9 files changed, 225 insertions, 22 deletions
diff --git a/p11-kit/Makefile.am b/p11-kit/Makefile.am
index ee39319..cd445f1 100644
--- a/p11-kit/Makefile.am
+++ b/p11-kit/Makefile.am
@@ -3,11 +3,6 @@ NULL =
INCLUDES = \
-I$(top_srcdir) \
-DP11_KIT_FUTURE_UNSTABLE_API \
- -DP11_SYSTEM_CONFIG_FILE=\""$(p11_system_config_file)"\" \
- -DP11_SYSTEM_CONFIG_MODULES=\""$(p11_system_config_modules)"\" \
- -DP11_USER_CONFIG_FILE=\""$(p11_user_config_file)"\" \
- -DP11_USER_CONFIG_MODULES=\""$(p11_user_config_modules)"\" \
- -DP11_MODULE_PATH=\""$(p11_module_path)"\" \
$(NULL)
incdir = $(includedir)/p11-kit-1/p11-kit
@@ -36,8 +31,13 @@ MODULE_SRCS = \
lib_LTLIBRARIES = \
libp11-kit.la
-noinst_LTLIBRARIES = \
- libp11-kit-testable.la
+libp11_kit_la_CFLAGS = \
+ -DP11_SYSTEM_CONFIG_FILE=\""$(p11_system_config_file)"\" \
+ -DP11_SYSTEM_CONFIG_MODULES=\""$(p11_system_config_modules)"\" \
+ -DP11_USER_CONFIG_FILE=\""$(p11_user_config_file)"\" \
+ -DP11_USER_CONFIG_MODULES=\""$(p11_user_config_modules)"\" \
+ -DP11_MODULE_PATH=\""$(p11_module_path)"\" \
+ $(NULL)
libp11_kit_la_LDFLAGS = \
-no-undefined \
@@ -48,11 +48,26 @@ libp11_kit_la_SOURCES = $(MODULE_SRCS)
libp11_kit_la_LIBADD = $(LTLIBINTL)
+noinst_LTLIBRARIES = \
+ libp11-kit-testable.la \
+ libp11-kit-compat.la
+
libp11_kit_testable_la_LDFLAGS = \
-no-undefined
libp11_kit_testable_la_SOURCES = $(MODULE_SRCS)
+libp11_kit_testable_la_CFLAGS = \
+ -DP11_SYSTEM_CONFIG_FILE=\""$(abs_top_builddir)/tests/files/system-pkcs11.conf"\" \
+ -DP11_SYSTEM_CONFIG_MODULES=\""$(abs_top_builddir)/tests/files/system-modules"\" \
+ -DP11_USER_CONFIG_FILE=\""$(abs_top_builddir)/tests/files/user-pkcs11.conf"\" \
+ -DP11_USER_CONFIG_MODULES=\""$(abs_top_builddir)/tests/files/user-modules"\" \
+ -DP11_MODULE_PATH=\""$(abs_top_builddir)/tests/.libs"\" \
+ $(NULL)
+
+libp11_kit_compat_la_SOURCES = \
+ compat.c compat.h
+
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = p11-kit-1.pc
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0400045..1e71108 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,7 +17,8 @@ CHECK_PROGS = \
conf-test \
uri-test \
pin-test \
- test-init
+ test-init \
+ test-modules
noinst_PROGRAMS = \
print-messages \
@@ -30,14 +31,37 @@ hash_test_SOURCES = hash-test.c $(cutestfiles)
pin_test_SOURCES = pin-test.c $(cutestfiles)
ptr_array_test_SOURCES = ptr-array-test.c $(cutestfiles)
progname_test_SOURCES = progname-test.c $(cutestfiles)
-test_init_SOURCES = \
- test-init.c \
- mock-module.c mock-module.h $(cutestfiles)
+test_init_SOURCES = test-init.c $(cutestfiles) \
+ mock-module.c mock-module.h
+test_init_CFLAGS = $(AM_CFLAGS)
+test_modules_SOURCES = test-modules.c $(cutestfiles)
uri_test_SOURCES = uri-test.c $(cutestfiles)
TESTS = $(CHECK_PROGS:=$(EXEEXT))
+noinst_LTLIBRARIES = \
+ mock-one.la \
+ mock-two.la \
+ mock-three.la
+
+mock_one_la_SOURCES = \
+ mock-module.c mock-module.h \
+ mock-module-ep.c
+
+mock_one_la_LIBADD = \
+ $(top_srcdir)/p11-kit/libp11-kit-compat.la
+
+mock_one_la_LDFLAGS = \
+ -module -avoid-version -rpath /nowhere \
+ -no-undefined -export-symbols-regex 'C_GetFunctionList'
+
+mock_two_la_SOURCES = $(mock_one_la_SOURCES)
+mock_two_la_LDFLAGS = $(mock_one_la_LDFLAGS)
+
+mock_three_la_SOURCES = $(mock_one_la_SOURCES)
+mock_three_la_LDFLAGS = $(mock_one_la_LDFLAGS)
+
EXTRA_DIST = \
cutest \
files
diff --git a/tests/conf-test.c b/tests/conf-test.c
index df44fae..2934c0f 100644
--- a/tests/conf-test.c
+++ b/tests/conf-test.c
@@ -262,17 +262,17 @@ test_load_modules_merge (CuTest *tc)
config = _p11_hash_get (configs, "one");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-one.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "user1");
config = _p11_hash_get (configs, "two");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-two.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system2");
config = _p11_hash_get (configs, "three");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-three");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-three.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "user3");
_p11_hash_free (configs);
@@ -294,12 +294,12 @@ test_load_modules_user_none (CuTest *tc)
config = _p11_hash_get (configs, "one");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-one.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system1");
config = _p11_hash_get (configs, "two");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-two.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system2");
config = _p11_hash_get (configs, "three");
@@ -332,7 +332,7 @@ test_load_modules_user_only (CuTest *tc)
config = _p11_hash_get (configs, "three");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-three");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-three.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "user3");
_p11_hash_free (configs);
@@ -354,12 +354,12 @@ test_load_modules_no_user (CuTest *tc)
config = _p11_hash_get (configs, "one");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-one.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system1");
config = _p11_hash_get (configs, "two");
CuAssertPtrNotNull (tc, config);
- CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, _p11_hash_get (config, "module"), "mock-two.la");
CuAssertStrEquals (tc, _p11_hash_get (config, "setting"), "system2");
config = _p11_hash_get (configs, "three");
diff --git a/tests/files/system-modules/one b/tests/files/system-modules/one
index e48b76d..3620869 100644
--- a/tests/files/system-modules/one
+++ b/tests/files/system-modules/one
@@ -1,3 +1,3 @@
-module: /path/to/module-one
+module: mock-one.so
setting: system1 \ No newline at end of file
diff --git a/tests/files/system-modules/two b/tests/files/system-modules/two
index 66e24dc..0bfa3ca 100644
--- a/tests/files/system-modules/two
+++ b/tests/files/system-modules/two
@@ -1,3 +1,3 @@
-module: /path/to/module-two
+module: mock-two.so
setting: system2 \ No newline at end of file
diff --git a/tests/files/system-modules/two-duplicate b/tests/files/system-modules/two-duplicate
new file mode 100644
index 0000000..907aa75
--- /dev/null
+++ b/tests/files/system-modules/two-duplicate
@@ -0,0 +1,3 @@
+
+# This is a duplicate of the 'two' module
+module: mock-two.so
diff --git a/tests/files/user-modules/three b/tests/files/user-modules/three
index c8d800a..70c5e03 100644
--- a/tests/files/user-modules/three
+++ b/tests/files/user-modules/three
@@ -1,3 +1,3 @@
-module: /path/to/module-three
+module: mock-three.so
setting: user3 \ No newline at end of file
diff --git a/tests/mock-module-ep.c b/tests/mock-module-ep.c
new file mode 100644
index 0000000..69542bb
--- /dev/null
+++ b/tests/mock-module-ep.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012 Stefan Walter
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ * * Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ * * The names of contributors to this software may not be
+ * used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * Author: Stef Walter <stef@thewalter.net>
+ */
+
+#include "config.h"
+
+#include "pkcs11.h"
+#include "mock-module.h"
+
+#ifdef OS_WIN32
+__declspec(dllexport)
+#endif
+CK_RV
+C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
+{
+ if (list == NULL)
+ return CKR_ARGUMENTS_BAD;
+ *list = &mock_module_no_slots;
+ return CKR_OK;
+}
diff --git a/tests/test-modules.c b/tests/test-modules.c
new file mode 100644
index 0000000..10e0969
--- /dev/null
+++ b/tests/test-modules.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2012 Red Hat Inc
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ * * Redistributions in binary form must reproduce the
+ * above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ * * The names of contributors to this software may not be
+ * used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * Author: Stef Walter <stefw@redhat.com>
+ */
+
+#include "config.h"
+#include "CuTest.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "p11-kit.h"
+#include "private.h"
+#include "hashmap.h"
+
+static void
+test_no_duplicates (CuTest *tc)
+{
+ CK_FUNCTION_LIST_PTR_PTR modules;
+ hashmap *paths;
+ hashmap *funcs;
+ char *path;
+ CK_RV rv;
+ int i;
+
+ /* The loaded modules should contain duplicates */
+
+ rv = p11_kit_initialize_registered ();
+ CuAssertIntEquals (tc, CKR_OK, rv);
+
+ paths = _p11_hash_create (_p11_hash_string_hash, _p11_hash_string_equal, NULL, NULL);
+ funcs = _p11_hash_create (_p11_hash_direct_hash, _p11_hash_direct_equal, NULL, NULL);
+
+ modules = p11_kit_registered_modules ();
+ CuAssertTrue (tc, modules != NULL && modules[0] != NULL);
+
+ for (i = 0; modules[i] != NULL; i++) {
+ path = p11_kit_registered_option (modules[i], "module");
+
+ if (_p11_hash_get (funcs, modules[i]))
+ CuAssert (tc, "found duplicate function list pointer", 0);
+ if (_p11_hash_get (paths, path))
+ CuAssert (tc, "found duplicate path name", 0);
+
+ if (!_p11_hash_set (funcs, modules[i], ""))
+ CuAssert (tc, "shouldn't be reached", 0);
+ if (!_p11_hash_set (paths, path, ""))
+ CuAssert (tc, "shouldn't be reached", 0);
+ }
+
+ _p11_hash_free (paths);
+ _p11_hash_free (funcs);
+ free (modules);
+
+ rv = p11_kit_finalize_registered ();
+ CuAssertIntEquals (tc, CKR_OK, rv);
+}
+
+int
+main (void)
+{
+ CuString *output = CuStringNew ();
+ CuSuite* suite = CuSuiteNew ();
+ int ret;
+
+ _p11_library_init ();
+
+ SUITE_ADD_TEST (suite, test_no_duplicates);
+
+ p11_kit_be_quiet ();
+
+ CuSuiteRun (suite);
+ CuSuiteSummary (suite, output);
+ CuSuiteDetails (suite, output);
+ printf ("%s\n", output->buffer);
+ ret = suite->failCount;
+ CuSuiteDelete (suite);
+ CuStringDelete (output);
+ return ret;
+}