]> granicus.if.org Git - p11-kit/commitdiff
Complete testing of global config files and directories.
authorStef Walter <stefw@collabora.co.uk>
Thu, 9 Jun 2011 08:13:45 +0000 (10:13 +0200)
committerStef Walter <stefw@collabora.co.uk>
Thu, 9 Jun 2011 08:13:45 +0000 (10:13 +0200)
12 files changed:
tests/conf-test.c
tests/files/system-modules/one [new file with mode: 0644]
tests/files/system-modules/two [new file with mode: 0644]
tests/files/test-system-invalid.conf [new file with mode: 0644]
tests/files/test-system-merge.conf [new file with mode: 0644]
tests/files/test-system-none.conf [new file with mode: 0644]
tests/files/test-system-only.conf [new file with mode: 0644]
tests/files/test-user-invalid.conf [new file with mode: 0644]
tests/files/test-user-only.conf [new file with mode: 0644]
tests/files/test-user.conf [new file with mode: 0644]
tests/files/user-modules/one [new file with mode: 0644]
tests/files/user-modules/three [new file with mode: 0644]

index 4b2f820f37ea519663e412dd65981785aa1cb997..ac2a37d6cd4d5c844a30dfd08d4fcd29e5643a19 100644 (file)
 #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 (file)
index 0000000..e48b76d
--- /dev/null
@@ -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 (file)
index 0000000..66e24dc
--- /dev/null
@@ -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 (file)
index 0000000..344ee96
--- /dev/null
@@ -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 (file)
index 0000000..978427d
--- /dev/null
@@ -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 (file)
index 0000000..95351e6
--- /dev/null
@@ -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 (file)
index 0000000..589f1c7
--- /dev/null
@@ -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 (file)
index 0000000..344ee96
--- /dev/null
@@ -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 (file)
index 0000000..3224c01
--- /dev/null
@@ -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 (file)
index 0000000..369544a
--- /dev/null
@@ -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 (file)
index 0000000..c371e4a
--- /dev/null
@@ -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 (file)
index 0000000..c8d800a
--- /dev/null
@@ -0,0 +1,3 @@
+
+module: /path/to/module-three
+setting: user3
\ No newline at end of file