test_utils.c revision cffe3defa3cb5011efc92a7773fe113a1e69774f
/*
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2013 Red Hat
SSSD tests: Tests for utility functions
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <popt.h>
#include "tests/cmocka/common_mock.h"
#include "test_utils.h"
#define TEST_CONF_DB "test_utils_conf.ldb"
#define TEST_DOM_NAME "utils_test.ldb"
#define DOM_COUNT 10
#define DOMNAME_TMPL "name_%zu.dom"
#define FLATNAME_TMPL "name_%zu"
#define SID_TMPL "S-1-5-21-1-2-%zu"
#define USERNAME "sssduser"
#define UID 1234
#define DOMAIN "sssddomain"
#define ORIGINAL_HOME "/home/user"
#define FLATNAME "flatname"
#define HOMEDIR_SUBSTR "/mnt/home"
#define DUMMY "dummy"
#define DUMMY2 "dummy2"
struct dom_list_test_ctx {
struct sss_domain_info *dom_list;
};
static int setup_dom_list(void **state)
{
struct dom_list_test_ctx *test_ctx;
size_t c;
}
return 0;
}
static int teardown_dom_list(void **state)
{
struct dom_list_test_ctx);
return 1;
}
return 0;
}
void test_find_domain_by_name_null(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
}
void test_find_domain_by_name(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
size_t c;
char *name;
char *flat_name;
char *sid;
}
}
void test_find_domain_by_name_missing_flat_name(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
size_t c;
char *name;
char *flat_name;
char *sid;
for (c = 0; c < mis; c++) {
}
if (c == mis - 1) {
} else {
}
if (c == mis - 1) {
} else {
}
if (c == mis - 1) {
} else {
}
}
}
void test_find_domain_by_name_disabled(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
size_t c;
char *name;
char *flat_name;
char *sid;
for (c = 0; c < mis; c++) {
}
if (c == mis - 1) {
} else {
}
if (c == mis - 1) {
} else {
}
if (c == mis - 1) {
} else {
}
}
}
void test_find_domain_by_sid_null(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
}
void test_find_domain_by_sid(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
size_t c;
char *name;
char *flat_name;
char *sid;
}
}
void test_find_domain_by_sid_missing_sid(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
size_t c;
char *name;
char *flat_name;
char *sid;
for (c = 0; c < mis; c++) {
}
if (c == mis - 1) {
} else {
}
}
}
void test_find_domain_by_sid_disabled(void **state)
{
struct dom_list_test_ctx);
struct sss_domain_info *dom;
size_t c;
char *name;
char *flat_name;
char *sid;
for (c = 0; c < mis; c++) {
}
if (c == mis - 1) {
} else {
}
}
}
/*
* dom1 -> sub1a
* |
* dom2 -> sub2a -> sub2b
*
*/
static int setup_dom_tree(void **state)
{
struct dom_list_test_ctx *test_ctx;
return 0;
}
static int teardown_dom_tree(void **state)
{
struct dom_list_test_ctx);
return 1;
}
return 0;
}
static void test_get_next_domain(void **state)
{
struct dom_list_test_ctx);
}
static void test_get_next_domain_descend(void **state)
{
struct dom_list_test_ctx);
}
static void test_get_next_domain_disabled(void **state)
{
struct dom_list_test_ctx);
}
}
struct name_init_test_ctx {
struct confdb_ctx *confdb;
};
#define GLOBAL_FULL_NAME_FORMAT "%1$s@%2$s"
#define GLOBAL_RE_EXPRESSION "(?P<name>[^@]+)@?(?P<domain>[^@]*$)"
#define TEST_DOMAIN_NAME "test.dom"
#define DOMAIN_FULL_NAME_FORMAT "%3$s\\%1$s"
#define DOMAIN_RE_EXPRESSION "(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
"((?P<name>[^@]+)@(?P<domain>.+$))|" \
"(^(?P<name>[^@\\\\]+)$))"
static int confdb_test_setup(void **state)
{
struct name_init_test_ctx *test_ctx;
int ret;
const char *val[2];
val[0] = TEST_DOMAIN_NAME;
val[0] = GLOBAL_FULL_NAME_FORMAT;
val[0] = GLOBAL_RE_EXPRESSION;
val[0] = "ldap";
val[0] = DOMAIN_FULL_NAME_FORMAT;
val[0] = DOMAIN_RE_EXPRESSION;
return 0;
}
static int confdb_test_teardown(void **state)
{
struct name_init_test_ctx *test_ctx;
return 0;
}
void test_sss_names_init(void **state)
{
struct name_init_test_ctx *test_ctx;
struct sss_names_ctx *names_ctx;
int ret;
&names_ctx);
}
void test_well_known_sid_to_name(void **state)
{
int ret;
const char *name;
const char *dom;
}
void test_name_to_well_known_sid(void **state)
{
int ret;
const char *sid;
}
#define TEST_SANITIZE_INPUT "TestUser@Test.Domain"
#define TEST_SANITIZE_LC_INPUT "testuser@test.domain"
void test_sss_filter_sanitize_for_dom(void **state)
{
struct dom_list_test_ctx *test_ctx;
int ret;
char *sanitized;
char *lc_sanitized;
struct sss_domain_info *dom;
dom->case_sensitive = true;
&sanitized, &lc_sanitized);
dom->case_sensitive = false;
&sanitized, &lc_sanitized);
}
struct sss_nss_homedir_ctx *homedir_ctx,
{
char *homedir;
} else {
}
}
static int setup_homedir_ctx(void **state)
{
struct sss_nss_homedir_ctx *homedir_ctx;
struct sss_nss_homedir_ctx);
*state = homedir_ctx;
return 0;
}
static int teardown_homedir_ctx(void **state)
{
struct sss_nss_homedir_ctx);
if (homedir_ctx == NULL) {
return 1;
}
return 0;
}
void test_expand_homedir_template_NULL(void **state)
{
char *homedir;
struct sss_nss_homedir_ctx *homedir_ctx;
/* following format strings requires data in homedir_ctx */
NULL };
int i;
/* missing data in homedir_ctx */
for (i = 0; format_strings[i] != NULL; ++i) {
}
/* flatname requires domain and username */
/* test unknown format string */
/* test malformed format string */
}
void test_expand_homedir_template(void **state)
{
struct sss_nss_homedir_ctx);
/* string without template */
/* test all format strings */
}
static int setup_add_strings_lists(void **state)
{
return 0;
}
static int teardown_add_strings_lists(void **state)
{
return 0;
}
void test_add_strings_lists(void **state)
{
char **res;
int ret;
size_t c;
size_t d;
assert_null(res[0]);
assert_null(res[0]);
/* 'copy_strings' is 'false', pointers must be equal */
}
assert_null(res[c]);
/* 'copy_strings' is 'true', pointers must be different, but strings
* must be equal */
}
assert_null(res[c]);
/* 'copy_strings' is 'false', pointers must be equal */
}
assert_null(res[c]);
/* 'copy_strings' is 'true', pointers must be different, but strings
* must be equal */
}
assert_null(res[c]);
/* 'copy_strings' is 'false', pointers must be equal */
}
}
assert_null(res[c+d]);
/* 'copy_strings' is 'true', pointers must be different, but strings
* must be equal */
}
}
assert_null(res[c+d]);
}
void test_sss_write_krb5_conf_snippet(void **state)
{
int ret;
char *cwd;
char *path;
char *file;
assert_true(ret > 0);
assert_true(ret > 0);
/* Check if writing a second time will work as well */
#ifdef HAVE_KRB5_LOCALAUTH_PLUGIN
#endif
}
void test_fix_domain_in_name_list(void **state)
{
struct name_init_test_ctx *test_ctx;
int ret;
struct sss_domain_info *sd;
struct sss_domain_info *dom;
assert_non_null(out[0]);
}
struct unique_file_test_ctx {
char *filename;
};
static int unique_file_test_setup(void **state)
{
struct unique_file_test_ctx *test_ctx;
return 0;
}
static int unique_file_test_teardown(void **state)
{
struct unique_file_test_ctx *test_ctx;
errno = 0;
fail();
}
return 0;
}
struct unique_file_test_ctx *test_ctx)
{
int fd;
char *check_filename;
/* Test that the destructor works */
return;
}
}
bool test_destructor)
{
int fd;
if (test_destructor) {
}
}
static void test_sss_unique_file(void **state)
{
struct unique_file_test_ctx *test_ctx;
sss_unique_file_test(test_ctx, false);
}
static void test_sss_unique_file_destruct(void **state)
{
struct unique_file_test_ctx *test_ctx;
sss_unique_file_test(test_ctx, true);
}
static void test_sss_unique_file_neg(void **state)
{
int fd;
}
bool test_destructor)
{
int fd;
char *tmp_filename;
if (test_destructor) {
}
0);
}
static void test_sss_unique_filename(void **state)
{
struct unique_file_test_ctx *test_ctx;
sss_unique_filename_test(test_ctx, false);
}
static void test_sss_unique_filename_destruct(void **state)
{
struct unique_file_test_ctx *test_ctx;
sss_unique_filename_test(test_ctx, true);
}
{
int opt;
int rv;
struct poptOption long_options[] = {
};
const struct CMUnitTest tests[] = {
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
/* Even though normally the tests should clean up after themselves
* they might not after a failed run. Remove the old db to be sure */
if (rv == 0) {
}
return rv;
}