summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conf-test.c262
-rw-r--r--tests/files/system-modules/one3
-rw-r--r--tests/files/system-modules/two3
-rw-r--r--tests/files/test-system-invalid.conf3
-rw-r--r--tests/files/test-system-merge.conf7
-rw-r--r--tests/files/test-system-none.conf8
-rw-r--r--tests/files/test-system-only.conf8
-rw-r--r--tests/files/test-user-invalid.conf3
-rw-r--r--tests/files/test-user-only.conf4
-rw-r--r--tests/files/test-user.conf3
-rw-r--r--tests/files/user-modules/one2
-rw-r--r--tests/files/user-modules/three3
12 files changed, 309 insertions, 0 deletions
diff --git a/tests/conf-test.c b/tests/conf-test.c
index 4b2f820..ac2a37d 100644
--- a/tests/conf-test.c
+++ b/tests/conf-test.c
@@ -35,12 +35,14 @@
#include "config.h"
#include "CuTest.h"
+#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "conf.h"
#include "p11-kit.h"
+#include "private.h"
static void
test_parse_conf_1 (CuTest *tc)
@@ -116,6 +118,256 @@ test_merge_defaults (CuTest *tc)
hash_free (values);
}
+static void
+test_load_globals_merge (CuTest *tc)
+{
+ int user_mode = -1;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ config = _p11_conf_load_globals (SRCDIR "/files/test-system-merge.conf",
+ SRCDIR "/files/test-user.conf",
+ &user_mode);
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+ CuAssertIntEquals (tc, CONF_USER_MERGE, user_mode);
+
+ CuAssertStrEquals (tc, hash_get (config, "key1"), "system1");
+ CuAssertStrEquals (tc, hash_get (config, "key2"), "user2");
+ CuAssertStrEquals (tc, hash_get (config, "key3"), "user3");
+
+ hash_free (config);
+}
+
+static void
+test_load_globals_no_user (CuTest *tc)
+{
+ int user_mode = -1;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ config = _p11_conf_load_globals (SRCDIR "/files/test-system-none.conf",
+ SRCDIR "/files/test-user.conf",
+ &user_mode);
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+ CuAssertIntEquals (tc, CONF_USER_NONE, user_mode);
+
+ CuAssertStrEquals (tc, hash_get (config, "key1"), "system1");
+ CuAssertStrEquals (tc, hash_get (config, "key2"), "system2");
+ CuAssertStrEquals (tc, hash_get (config, "key3"), "system3");
+
+ hash_free (config);
+}
+
+static void
+test_load_globals_user_sets_only (CuTest *tc)
+{
+ int user_mode = -1;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ config = _p11_conf_load_globals (SRCDIR "/files/test-system-merge.conf",
+ SRCDIR "/files/test-user-only.conf",
+ &user_mode);
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+ CuAssertIntEquals (tc, CONF_USER_ONLY, user_mode);
+
+ CuAssertStrEquals (tc, hash_get (config, "key1"), NULL);
+ CuAssertStrEquals (tc, hash_get (config, "key2"), "user2");
+ CuAssertStrEquals (tc, hash_get (config, "key3"), "user3");
+
+ hash_free (config);
+}
+
+static void
+test_load_globals_system_sets_only (CuTest *tc)
+{
+ int user_mode = -1;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ config = _p11_conf_load_globals (SRCDIR "/files/test-system-only.conf",
+ SRCDIR "/files/test-user.conf",
+ &user_mode);
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+ CuAssertIntEquals (tc, CONF_USER_ONLY, user_mode);
+
+ CuAssertStrEquals (tc, hash_get (config, "key1"), NULL);
+ CuAssertStrEquals (tc, hash_get (config, "key2"), "user2");
+ CuAssertStrEquals (tc, hash_get (config, "key3"), "user3");
+
+ hash_free (config);
+}
+
+static void
+test_load_globals_system_sets_invalid (CuTest *tc)
+{
+ int user_mode = -1;
+ hash_t *config;
+ int error;
+
+ _p11_kit_clear_message ();
+
+ config = _p11_conf_load_globals (SRCDIR "/files/test-system-invalid.conf",
+ SRCDIR "/files/non-existant.conf",
+ &user_mode);
+ error = errno;
+ CuAssertPtrEquals (tc, NULL, config);
+ CuAssertIntEquals (tc, EINVAL, error);
+ CuAssertPtrNotNull (tc, p11_kit_message ());
+
+ hash_free (config);
+}
+
+static void
+test_load_globals_user_sets_invalid (CuTest *tc)
+{
+ int user_mode = -1;
+ hash_t *config;
+ int error;
+
+ _p11_kit_clear_message ();
+
+ config = _p11_conf_load_globals (SRCDIR "/files/test-system-merge.conf",
+ SRCDIR "/files/test-user-invalid.conf",
+ &user_mode);
+ error = errno;
+ CuAssertPtrEquals (tc, NULL, config);
+ CuAssertIntEquals (tc, EINVAL, error);
+ CuAssertPtrNotNull (tc, p11_kit_message ());
+
+ hash_free (config);
+}
+
+static void
+test_load_modules_merge (CuTest *tc)
+{
+ hash_t *configs;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ configs = _p11_conf_load_modules (CONF_USER_MERGE,
+ SRCDIR "/files/system-modules",
+ SRCDIR "/files/user-modules");
+ CuAssertPtrNotNull (tc, configs);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+
+ config = hash_get (configs, "one");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "user1");
+
+ config = hash_get (configs, "two");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "system2");
+
+ config = hash_get (configs, "three");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-three");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "user3");
+
+ hash_free (configs);
+}
+
+static void
+test_load_modules_user_none (CuTest *tc)
+{
+ hash_t *configs;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ configs = _p11_conf_load_modules (CONF_USER_NONE,
+ SRCDIR "/files/system-modules",
+ SRCDIR "/files/user-modules");
+ CuAssertPtrNotNull (tc, configs);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+
+ config = hash_get (configs, "one");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "system1");
+
+ config = hash_get (configs, "two");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "system2");
+
+ config = hash_get (configs, "three");
+ CuAssertPtrEquals (tc, NULL, config);
+
+ hash_free (configs);
+}
+
+static void
+test_load_modules_user_only (CuTest *tc)
+{
+ hash_t *configs;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ configs = _p11_conf_load_modules (CONF_USER_ONLY,
+ SRCDIR "/files/system-modules",
+ SRCDIR "/files/user-modules");
+ CuAssertPtrNotNull (tc, configs);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+
+ config = hash_get (configs, "one");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), NULL);
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "user1");
+
+ config = hash_get (configs, "two");
+ CuAssertPtrEquals (tc, NULL, config);
+
+ config = hash_get (configs, "three");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-three");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "user3");
+
+ hash_free (configs);
+}
+
+static void
+test_load_modules_no_user (CuTest *tc)
+{
+ hash_t *configs;
+ hash_t *config;
+
+ _p11_kit_clear_message ();
+
+ configs = _p11_conf_load_modules (CONF_USER_MERGE,
+ SRCDIR "/files/system-modules",
+ SRCDIR "/files/non-existant");
+ CuAssertPtrNotNull (tc, configs);
+ CuAssertStrEquals (tc, NULL, p11_kit_message ());
+
+ config = hash_get (configs, "one");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-one");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "system1");
+
+ config = hash_get (configs, "two");
+ CuAssertPtrNotNull (tc, config);
+ CuAssertStrEquals (tc, hash_get (config, "module"), "/path/to/module-two");
+ CuAssertStrEquals (tc, hash_get (config, "setting"), "system2");
+
+ config = hash_get (configs, "three");
+ CuAssertPtrEquals (tc, NULL, config);
+
+ hash_free (configs);
+}
+
int
main (void)
{
@@ -127,6 +379,16 @@ main (void)
SUITE_ADD_TEST (suite, test_parse_ignore_missing);
SUITE_ADD_TEST (suite, test_parse_fail_missing);
SUITE_ADD_TEST (suite, test_merge_defaults);
+ SUITE_ADD_TEST (suite, test_load_globals_merge);
+ SUITE_ADD_TEST (suite, test_load_globals_no_user);
+ SUITE_ADD_TEST (suite, test_load_globals_system_sets_only);
+ SUITE_ADD_TEST (suite, test_load_globals_user_sets_only);
+ SUITE_ADD_TEST (suite, test_load_globals_system_sets_invalid);
+ SUITE_ADD_TEST (suite, test_load_globals_user_sets_invalid);
+ SUITE_ADD_TEST (suite, test_load_modules_merge);
+ SUITE_ADD_TEST (suite, test_load_modules_no_user);
+ SUITE_ADD_TEST (suite, test_load_modules_user_only);
+ SUITE_ADD_TEST (suite, test_load_modules_user_none);
p11_kit_be_quiet ();
diff --git a/tests/files/system-modules/one b/tests/files/system-modules/one
new file mode 100644
index 0000000..e48b76d
--- /dev/null
+++ b/tests/files/system-modules/one
@@ -0,0 +1,3 @@
+
+module: /path/to/module-one
+setting: system1 \ No newline at end of file
diff --git a/tests/files/system-modules/two b/tests/files/system-modules/two
new file mode 100644
index 0000000..66e24dc
--- /dev/null
+++ b/tests/files/system-modules/two
@@ -0,0 +1,3 @@
+
+module: /path/to/module-two
+setting: system2 \ No newline at end of file
diff --git a/tests/files/test-system-invalid.conf b/tests/files/test-system-invalid.conf
new file mode 100644
index 0000000..344ee96
--- /dev/null
+++ b/tests/files/test-system-invalid.conf
@@ -0,0 +1,3 @@
+
+# Invalid user-config setting
+user-config: bad
diff --git a/tests/files/test-system-merge.conf b/tests/files/test-system-merge.conf
new file mode 100644
index 0000000..978427d
--- /dev/null
+++ b/tests/files/test-system-merge.conf
@@ -0,0 +1,7 @@
+
+# Merge in user config
+user-config: merge
+
+key1: system1
+key2: system2
+key3: system3 \ No newline at end of file
diff --git a/tests/files/test-system-none.conf b/tests/files/test-system-none.conf
new file mode 100644
index 0000000..95351e6
--- /dev/null
+++ b/tests/files/test-system-none.conf
@@ -0,0 +1,8 @@
+
+# Only user config
+user-config: none
+
+# These values will not be overriden
+key1: system1
+key2: system2
+key3: system3 \ No newline at end of file
diff --git a/tests/files/test-system-only.conf b/tests/files/test-system-only.conf
new file mode 100644
index 0000000..589f1c7
--- /dev/null
+++ b/tests/files/test-system-only.conf
@@ -0,0 +1,8 @@
+
+# Only user config
+user-config: only
+
+# This stuff will be ignored
+key1: system1
+key2: system2
+key3: system3 \ No newline at end of file
diff --git a/tests/files/test-user-invalid.conf b/tests/files/test-user-invalid.conf
new file mode 100644
index 0000000..344ee96
--- /dev/null
+++ b/tests/files/test-user-invalid.conf
@@ -0,0 +1,3 @@
+
+# Invalid user-config setting
+user-config: bad
diff --git a/tests/files/test-user-only.conf b/tests/files/test-user-only.conf
new file mode 100644
index 0000000..3224c01
--- /dev/null
+++ b/tests/files/test-user-only.conf
@@ -0,0 +1,4 @@
+
+user-config: only
+key2: user2
+key3: user3 \ No newline at end of file
diff --git a/tests/files/test-user.conf b/tests/files/test-user.conf
new file mode 100644
index 0000000..369544a
--- /dev/null
+++ b/tests/files/test-user.conf
@@ -0,0 +1,3 @@
+
+key2: user2
+key3: user3 \ No newline at end of file
diff --git a/tests/files/user-modules/one b/tests/files/user-modules/one
new file mode 100644
index 0000000..c371e4a
--- /dev/null
+++ b/tests/files/user-modules/one
@@ -0,0 +1,2 @@
+
+setting: user1 \ No newline at end of file
diff --git a/tests/files/user-modules/three b/tests/files/user-modules/three
new file mode 100644
index 0000000..c8d800a
--- /dev/null
+++ b/tests/files/user-modules/three
@@ -0,0 +1,3 @@
+
+module: /path/to/module-three
+setting: user3 \ No newline at end of file