|
Packit Service |
3749ba |
/*
|
|
Packit Service |
3749ba |
* Copyright (c) 2011, Collabora Ltd.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
3749ba |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
3749ba |
* are met:
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* * Redistributions of source code must retain the above
|
|
Packit Service |
3749ba |
* copyright notice, this list of conditions and the
|
|
Packit Service |
3749ba |
* following disclaimer.
|
|
Packit Service |
3749ba |
* * Redistributions in binary form must reproduce the
|
|
Packit Service |
3749ba |
* above copyright notice, this list of conditions and
|
|
Packit Service |
3749ba |
* the following disclaimer in the documentation and/or
|
|
Packit Service |
3749ba |
* other materials provided with the distribution.
|
|
Packit Service |
3749ba |
* * The names of contributors to this software may not be
|
|
Packit Service |
3749ba |
* used to endorse or promote products derived from this
|
|
Packit Service |
3749ba |
* software without specific prior written permission.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit Service |
3749ba |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit Service |
3749ba |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
Packit Service |
3749ba |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
Packit Service |
3749ba |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit Service |
3749ba |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
Packit Service |
3749ba |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
Packit Service |
3749ba |
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
Packit Service |
3749ba |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit Service |
3749ba |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
Packit Service |
3749ba |
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
Packit Service |
3749ba |
* DAMAGE.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Author: Stef Walter <stefw@collabora.co.uk>
|
|
Packit Service |
3749ba |
*/
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "config.h"
|
|
Packit Service |
3749ba |
#include "test.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include <errno.h>
|
|
Packit Service |
3749ba |
#include <stdlib.h>
|
|
Packit Service |
3749ba |
#include <stdio.h>
|
|
Packit Service |
3749ba |
#include <string.h>
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "conf.h"
|
|
Packit Service |
3749ba |
#include "debug.h"
|
|
Packit Service |
3749ba |
#include "message.h"
|
|
Packit Service |
3749ba |
#include "p11-kit.h"
|
|
Packit Service |
3749ba |
#include "private.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#ifdef OS_UNIX
|
|
Packit Service |
3749ba |
#include <sys/stat.h>
|
|
Packit Service |
3749ba |
#include <sys/wait.h>
|
|
Packit Service |
3749ba |
#include <unistd.h>
|
|
Packit Service |
3749ba |
#endif
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_parse_conf_1 (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *map;
|
|
Packit Service |
3749ba |
const char *value;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
map = _p11_conf_parse_file (SRCDIR "/p11-kit/fixtures/test-1.conf", NULL, 0);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (map);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
value = p11_dict_get (map, "key1");
|
|
Packit Service |
3749ba |
assert_str_eq ("value1", value);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
value = p11_dict_get (map, "with-colon");
|
|
Packit Service |
3749ba |
assert_str_eq ("value-of-colon", value);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
value = p11_dict_get (map, "with-whitespace");
|
|
Packit Service |
3749ba |
assert_str_eq ("value-with-whitespace", value);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
value = p11_dict_get (map, "embedded-comment");
|
|
Packit Service |
3749ba |
assert_str_eq ("this is # not a comment", value);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (map);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_parse_ignore_missing (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *map;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
map = _p11_conf_parse_file (SRCDIR "/p11-kit/fixtures/non-existant.conf", NULL, CONF_IGNORE_MISSING);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (map);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert_num_eq (0, p11_dict_size (map));
|
|
Packit Service |
3749ba |
assert (p11_message_last () == NULL);
|
|
Packit Service |
3749ba |
p11_dict_free (map);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_parse_fail_missing (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *map;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
map = _p11_conf_parse_file (SRCDIR "/p11-kit/fixtures/non-existant.conf", NULL, 0);
|
|
Packit Service |
3749ba |
assert (map == NULL);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (p11_message_last ());
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_merge_defaults (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *values;
|
|
Packit Service |
3749ba |
p11_dict *defaults;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
values = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, free, free);
|
|
Packit Service |
3749ba |
defaults = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, free, free);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_set (values, strdup ("one"), strdup ("real1"));
|
|
Packit Service |
3749ba |
p11_dict_set (values, strdup ("two"), strdup ("real2"));
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_set (defaults, strdup ("two"), strdup ("default2"));
|
|
Packit Service |
3749ba |
p11_dict_set (defaults, strdup ("three"), strdup ("default3"));
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
if (!_p11_conf_merge_defaults (values, defaults))
|
|
Packit Service |
3749ba |
assert_not_reached ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (defaults);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (values, "one"), "real1");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (values, "two"), "real2");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (values, "three"), "default3");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (values);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_globals_merge (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
int user_mode = -1;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = _p11_conf_load_globals (SRCDIR "/p11-kit/fixtures/test-system-merge.conf",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/test-user.conf",
|
|
Packit Service |
3749ba |
&user_mode);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert (NULL == p11_message_last ());
|
|
Packit Service |
3749ba |
assert_num_eq (CONF_USER_MERGE, user_mode);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key1"), "system1");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key2"), "user2");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key3"), "user3");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (config);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_globals_no_user (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
int user_mode = -1;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = _p11_conf_load_globals (SRCDIR "/p11-kit/fixtures/test-system-none.conf",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/test-user.conf",
|
|
Packit Service |
3749ba |
&user_mode);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert (NULL == p11_message_last ());
|
|
Packit Service |
3749ba |
assert_num_eq (CONF_USER_NONE, user_mode);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key1"), "system1");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key2"), "system2");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key3"), "system3");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (config);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_globals_user_sets_only (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
int user_mode = -1;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = _p11_conf_load_globals (SRCDIR "/p11-kit/fixtures/test-system-merge.conf",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/test-user-only.conf",
|
|
Packit Service |
3749ba |
&user_mode);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert (NULL == p11_message_last ());
|
|
Packit Service |
3749ba |
assert_num_eq (CONF_USER_ONLY, user_mode);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert (p11_dict_get (config, "key1") == NULL);
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key2"), "user2");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key3"), "user3");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (config);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_globals_system_sets_only (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
int user_mode = -1;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = _p11_conf_load_globals (SRCDIR "/p11-kit/fixtures/test-system-only.conf",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/test-user.conf",
|
|
Packit Service |
3749ba |
&user_mode);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert (NULL == p11_message_last ());
|
|
Packit Service |
3749ba |
assert_num_eq (CONF_USER_ONLY, user_mode);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert (p11_dict_get (config, "key1") == NULL);
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key2"), "user2");
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "key3"), "user3");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (config);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_globals_system_sets_invalid (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
int user_mode = -1;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
int error;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = _p11_conf_load_globals (SRCDIR "/p11-kit/fixtures/test-system-invalid.conf",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/non-existant.conf",
|
|
Packit Service |
3749ba |
&user_mode);
|
|
Packit Service |
3749ba |
error = errno;
|
|
Packit Service |
3749ba |
assert_ptr_eq (NULL, config);
|
|
Packit Service |
3749ba |
assert_num_eq (EINVAL, error);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (p11_message_last ());
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (config);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_globals_user_sets_invalid (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
int user_mode = -1;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
int error;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = _p11_conf_load_globals (SRCDIR "/p11-kit/fixtures/test-system-merge.conf",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/test-user-invalid.conf",
|
|
Packit Service |
3749ba |
&user_mode);
|
|
Packit Service |
3749ba |
error = errno;
|
|
Packit Service |
3749ba |
assert_ptr_eq (NULL, config);
|
|
Packit Service |
3749ba |
assert_num_eq (EINVAL, error);
|
|
Packit Service |
3749ba |
assert_ptr_not_null (p11_message_last ());
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (config);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static bool
|
|
Packit Service |
3749ba |
assert_msg_contains (const char *msg,
|
|
Packit Service |
3749ba |
const char *text)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
return (msg && strstr (msg, text)) ? true : false;
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_modules_merge (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *configs;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
configs = _p11_conf_load_modules (CONF_USER_MERGE,
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/package-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/system-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/user-modules");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (configs);
|
|
Packit Service |
3749ba |
assert (assert_msg_contains (p11_message_last (), "invalid config filename"));
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "one");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-one.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "user1");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "two.badname");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-two.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "system2");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "three");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-three.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "user3");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (configs);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_modules_user_none (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *configs;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
configs = _p11_conf_load_modules (CONF_USER_NONE,
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/package-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/system-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/user-modules");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (configs);
|
|
Packit Service |
3749ba |
assert (assert_msg_contains (p11_message_last (), "invalid config filename"));
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "one");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-one.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "system1");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "two.badname");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-two.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "system2");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "three");
|
|
Packit Service |
3749ba |
assert_ptr_eq (NULL, config);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (configs);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_modules_user_only (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *configs;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
configs = _p11_conf_load_modules (CONF_USER_ONLY,
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/package-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/system-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/user-modules");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (configs);
|
|
Packit Service |
3749ba |
assert_ptr_eq (NULL, (void *)p11_message_last ());
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "one");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert (p11_dict_get (config, "module") == NULL);
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "user1");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "two.badname");
|
|
Packit Service |
3749ba |
assert_ptr_eq (NULL, config);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "three");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-three.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "user3");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (configs);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_load_modules_no_user (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_dict *configs;
|
|
Packit Service |
3749ba |
p11_dict *config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_message_clear ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
configs = _p11_conf_load_modules (CONF_USER_MERGE,
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/package-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/system-modules",
|
|
Packit Service |
3749ba |
SRCDIR "/p11-kit/fixtures/non-existant");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (configs);
|
|
Packit Service |
3749ba |
assert (assert_msg_contains (p11_message_last (), "invalid config filename"));
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "one");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-one.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "system1");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "two.badname");
|
|
Packit Service |
3749ba |
assert_ptr_not_null (config);
|
|
Packit Service |
3749ba |
assert_str_eq ("mock-two.so", p11_dict_get (config, "module"));
|
|
Packit Service |
3749ba |
assert_str_eq (p11_dict_get (config, "setting"), "system2");
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
config = p11_dict_get (configs, "three");
|
|
Packit Service |
3749ba |
assert_ptr_eq (NULL, config);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_dict_free (configs);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_parse_boolean (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_message_quiet ();
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert_num_eq (true, _p11_conf_parse_boolean ("yes", false));
|
|
Packit Service |
3749ba |
assert_num_eq (false, _p11_conf_parse_boolean ("no", true));
|
|
Packit Service |
3749ba |
assert_num_eq (true, _p11_conf_parse_boolean ("!!!", true));
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#ifdef OS_UNIX
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_setuid (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
const char *args[] = { BUILDDIR "/p11-kit/frob-setuid", NULL, };
|
|
Packit Service |
3749ba |
char *path;
|
|
Packit Service |
3749ba |
int ret;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
if (getuid () == 0)
|
|
Packit Service |
3749ba |
assert_skip ("cannot perform setuid test as root", NULL);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/* This is the 'number' setting set in one.module user configuration. */
|
|
Packit Service |
3749ba |
ret = p11_test_run_child (args, true);
|
|
Packit Service |
3749ba |
assert_num_eq (ret, 33);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
path = p11_test_copy_setgid (args[0], BUILDDIR);
|
|
Packit Service |
3749ba |
if (path == NULL)
|
|
Packit Service |
3749ba |
return;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
args[0] = path;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
/* This is the 'number' setting set in one.module system configuration. */
|
|
Packit Service |
3749ba |
ret = p11_test_run_child (args, true);
|
|
Packit Service |
3749ba |
assert_num_eq (ret, 18);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
if (unlink (path) < 0)
|
|
Packit Service |
3749ba |
assert_fail ("unlink failed", strerror (errno));
|
|
Packit Service |
3749ba |
free (path);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#endif /* OS_UNIX */
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
extern bool p11_conf_force_user_config;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
int
|
|
Packit Service |
3749ba |
main (int argc,
|
|
Packit Service |
3749ba |
char *argv[])
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_conf_force_user_config = true;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_test (test_parse_conf_1, "/conf/test_parse_conf_1");
|
|
Packit Service |
3749ba |
p11_test (test_parse_ignore_missing, "/conf/test_parse_ignore_missing");
|
|
Packit Service |
3749ba |
p11_test (test_parse_fail_missing, "/conf/test_parse_fail_missing");
|
|
Packit Service |
3749ba |
p11_test (test_merge_defaults, "/conf/test_merge_defaults");
|
|
Packit Service |
3749ba |
p11_test (test_load_globals_merge, "/conf/test_load_globals_merge");
|
|
Packit Service |
3749ba |
p11_test (test_load_globals_no_user, "/conf/test_load_globals_no_user");
|
|
Packit Service |
3749ba |
p11_test (test_load_globals_system_sets_only, "/conf/test_load_globals_system_sets_only");
|
|
Packit Service |
3749ba |
p11_test (test_load_globals_user_sets_only, "/conf/test_load_globals_user_sets_only");
|
|
Packit Service |
3749ba |
p11_test (test_load_globals_system_sets_invalid, "/conf/test_load_globals_system_sets_invalid");
|
|
Packit Service |
3749ba |
p11_test (test_load_globals_user_sets_invalid, "/conf/test_load_globals_user_sets_invalid");
|
|
Packit Service |
3749ba |
p11_test (test_load_modules_merge, "/conf/test_load_modules_merge");
|
|
Packit Service |
3749ba |
p11_test (test_load_modules_no_user, "/conf/test_load_modules_no_user");
|
|
Packit Service |
3749ba |
p11_test (test_load_modules_user_only, "/conf/test_load_modules_user_only");
|
|
Packit Service |
3749ba |
p11_test (test_load_modules_user_none, "/conf/test_load_modules_user_none");
|
|
Packit Service |
3749ba |
p11_test (test_parse_boolean, "/conf/test_parse_boolean");
|
|
Packit Service |
3749ba |
#ifdef OS_UNIX
|
|
Packit Service |
3749ba |
/* Don't run this test when under fakeroot, or the binary is
|
|
Packit Service |
3749ba |
* written under /tmp */
|
|
Packit Service |
3749ba |
if (!getenv ("FAKED_MODE") && strncmp (BUILDDIR, "/tmp/", 5) != 0) {
|
|
Packit Service |
3749ba |
p11_test (test_setuid, "/conf/setuid");
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
#endif
|
|
Packit Service |
3749ba |
return p11_test_run (argc, argv);
|
|
Packit Service |
3749ba |
}
|