test_sysdb_sudo.c revision dd285415d7a8d8376207960cfa3e977524c3b98c
/*
Authors:
Petr Čech <pcech@redhat.com>
Copyright (C) 2016 Red Hat
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/>.
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <popt.h>
#include <ldb_module.h>
#include "tests/cmocka/common_mock.h"
#include "src/db/sysdb_sudo.h"
#include "src/db/sysdb_private.h"
#define TEST_CONF_DB "test_sysdb_sudorules.ldb"
#define TEST_DOM_NAME "test_domain.test"
#define TEST_CACHE_SUDO_TIMEOUT "20"
#define TEST_USER_NON_EXIST "no_user"
#define TEST_GROUP_NAME "test_sudo_group"
#define TEST_GID 10001
struct test_user {
const char *name;
{ "test_user2", 1002, 1002 },
{ "test_user3", 1003, 1003 } };
struct test_rule {
const char *name;
const char *host;
const char *as_user;
struct sysdb_test_ctx {
struct sss_test_ctx *tctx;
};
{
}
{
int gid;
for (int i = 0; i < 3; i++) {
}
}
{
}
{
"(objectClass=sudoRule)",
msgs_count = -1;
}
return msgs_count;
}
static int test_sysdb_setup(void **state)
{
struct sysdb_test_ctx *test_ctx;
return 0;
}
static int test_sysdb_teardown(void **state)
{
struct sysdb_test_ctx *test_ctx;
return 0;
}
void test_store_sudo(void **state)
{
char *filter;
int uid = 0;
char **groupnames = NULL;
const char *result;
struct sysdb_attrs *rule;
struct sysdb_test_ctx);
create_rule_attrs(rule, 0);
&filter);
NULL);
NULL);
NULL);
}
void test_sudo_purge_by_filter(void **state)
{
struct sysdb_attrs *rule;
char *delete_filter;
int uid = 0;
char **groupnames = NULL;
struct sysdb_test_ctx);
create_rule_attrs(rule, 0);
"(&(objectClass=sudoRule)(|(sudoUser=test_user1)))");
}
void test_sudo_purge_by_rules(void **state)
{
struct sysdb_attrs *rule;
struct sysdb_test_ctx);
create_rule_attrs(rule, 0);
}
void test_sudo_set_get_last_full_refresh(void **state)
{
struct sysdb_test_ctx);
}
void test_sudo_get_filter(void **state)
{
char *filter;
int uid = 0;
char **groupnames = NULL;
struct sysdb_test_ctx);
&filter);
"(&(objectClass=sudoRule)(|(sudoUser=test_user1)))");
}
void test_get_sudo_user_info(void **state)
{
char **groupnames = NULL;
struct sysdb_test_ctx);
/* User 1 has group. */
}
void test_get_sudo_user_info_nogroup(void **state)
{
char **groupnames = NULL;
struct sysdb_test_ctx);
/* User 0 hasn't group. */
}
void test_get_sudo_nouser(void **state)
{
char **groupnames = NULL;
struct sysdb_test_ctx);
TEST_USER_NON_EXIST, 0, &groupnames);
}
void test_set_sudo_rule_attr_add(void **state)
{
struct sysdb_attrs *rule;
struct sysdb_attrs *new_rule;
NULL };
char *filter;
int uid = 0;
char **groupnames = NULL;
const char *result;
struct sysdb_test_ctx);
create_rule_attrs(rule, 0);
"test_command");
&filter);
NULL);
}
void test_set_sudo_rule_attr_replace(void **state)
{
struct sysdb_attrs *rule;
struct sysdb_attrs *new_rule;
char *filter;
int uid = 0;
char **groupnames = NULL;
const char *result;
struct sysdb_test_ctx);
create_rule_attrs(rule, 0);
&filter);
}
void test_set_sudo_rule_attr_delete(void **state)
{
struct sysdb_attrs *rule;
struct sysdb_attrs *new_rule;
NULL };
char *filter;
int uid = 0;
char **groupnames = NULL;
const char *result;
struct sysdb_test_ctx);
create_rule_attrs(rule, 0);
&filter);
"deleted");
}
void test_search_sudo_rules(void **state)
{
char *filter;
const char *rule_names[num_rules];
const char *db_results[num_rules];
struct sysdb_test_ctx);
assert_non_null(tmp_rules[0]);
create_rule_attrs(tmp_rules[0], 0);
for (int i = 0; i < num_rules; ++i) {
}
db_results, num_rules));
talloc_zfree(tmp_rules[0]);
}
void test_filter_rules_by_time(void **state)
{
struct sysdb_attrs *tmp_attr;
struct sysdb_attrs **_rules;
struct sysdb_attrs **loaded_rules;
char buff[20];
struct sysdb_test_ctx);
assert_non_null(tmp_rules[0]);
create_rule_attrs(tmp_rules[0], 0);
/*
* We hit DST issue of time functions,
* so we use big time shift to avoid this.
*/
"(objectClass=sudoRule)",
&_num_rules, &_rules);
talloc_zfree(tmp_rules[0]);
}
{
int rv;
int opt;
struct poptOption long_options[] = {
};
const struct CMUnitTest tests[] = {
/* sysdb_sudo_store() */
/* sysdb_sudo_purge() */
/*
* sysdb_sudo_set_last_full_refresh()
* sysdb_sudo_get_last_full_refresh()
*/
/* sysdb_get_sudo_filter() */
/* sysdb_get_sudo_user_info() */
/* sysdb_set_sudo_rule_attr() */
/* sysdb_search_sudo_rules() */
/* sysdb_sudo_filter_rules_by_time() */
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch (opt) {
default:
return 1;
}
}
return rv;
}