|
|
4de095 |
From e2f39220bc1cbfc87bbe41e84042ab8be9d046ec Mon Sep 17 00:00:00 2001
|
|
|
4de095 |
From: =?UTF-8?q?Petr=20=C4=8Cech?= <pcech@redhat.com>
|
|
|
4de095 |
Date: Thu, 13 Oct 2016 09:31:52 +0200
|
|
|
4de095 |
Subject: [PATCH 161/162] TESTS: Extending sysdb sudo store tests
|
|
|
4de095 |
MIME-Version: 1.0
|
|
|
4de095 |
Content-Type: text/plain; charset=UTF-8
|
|
|
4de095 |
Content-Transfer-Encoding: 8bit
|
|
|
4de095 |
|
|
|
4de095 |
We covered diference between case sensitive and case insensitive
|
|
|
4de095 |
domains. If domain is case insensitive we add lowercase form of
|
|
|
4de095 |
sudoUser to local sysdb cache.
|
|
|
4de095 |
|
|
|
4de095 |
Resolves:
|
|
|
4de095 |
https://fedorahosted.org/sssd/ticket/3203
|
|
|
4de095 |
|
|
|
4de095 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
4de095 |
(cherry picked from commit 23637e2fd2b1fe42bdd2335893a11ac8016f56bc)
|
|
|
4de095 |
(cherry picked from commit 143b1dcbbe865a139616a22b139e19bd772e46f0)
|
|
|
4de095 |
---
|
|
|
4de095 |
src/tests/cmocka/test_sysdb_sudo.c | 168 ++++++++++++++++++++++++++++++++++++-
|
|
|
4de095 |
1 file changed, 167 insertions(+), 1 deletion(-)
|
|
|
4de095 |
|
|
|
4de095 |
diff --git a/src/tests/cmocka/test_sysdb_sudo.c b/src/tests/cmocka/test_sysdb_sudo.c
|
|
|
4de095 |
index 889de72371ac724de7c791d889a670cf25a36968..f21ff3655efbdc5b66a1fdbc24a51ec8174c3c8c 100644
|
|
|
4de095 |
--- a/src/tests/cmocka/test_sysdb_sudo.c
|
|
|
4de095 |
+++ b/src/tests/cmocka/test_sysdb_sudo.c
|
|
|
4de095 |
@@ -44,7 +44,7 @@ struct test_user {
|
|
|
4de095 |
const char *name;
|
|
|
4de095 |
uid_t uid;
|
|
|
4de095 |
gid_t gid;
|
|
|
4de095 |
-} users[] = { { "test_user1", 1001, 1001 },
|
|
|
4de095 |
+} users[] = { { "test_USER1", 1001, 1001 },
|
|
|
4de095 |
{ "test_user2", 1002, 1002 },
|
|
|
4de095 |
{ "test_user3", 1003, 1003 } };
|
|
|
4de095 |
|
|
|
4de095 |
@@ -104,6 +104,29 @@ static void create_rule_attrs(struct sysdb_attrs *rule, int i)
|
|
|
4de095 |
assert_int_equal(ret, EOK);
|
|
|
4de095 |
}
|
|
|
4de095 |
|
|
|
4de095 |
+static void create_rule_attrs_multiple_sudoUser(struct sysdb_attrs *rule)
|
|
|
4de095 |
+{
|
|
|
4de095 |
+ errno_t ret;
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_CN,
|
|
|
4de095 |
+ rules[0].name);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_HOST,
|
|
|
4de095 |
+ rules[0].host);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_RUNASUSER,
|
|
|
4de095 |
+ rules[0].as_user);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ for (int i = 0; i < 3; i++ ) {
|
|
|
4de095 |
+ ret = sysdb_attrs_add_string_safe(rule, SYSDB_SUDO_CACHE_AT_USER,
|
|
|
4de095 |
+ users[i].name);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+ }
|
|
|
4de095 |
+}
|
|
|
4de095 |
+
|
|
|
4de095 |
static int get_stored_rules_count(struct sysdb_test_ctx *test_ctx)
|
|
|
4de095 |
{
|
|
|
4de095 |
errno_t ret;
|
|
|
4de095 |
@@ -217,6 +240,143 @@ void test_store_sudo(void **state)
|
|
|
4de095 |
talloc_zfree(msgs);
|
|
|
4de095 |
}
|
|
|
4de095 |
|
|
|
4de095 |
+void test_store_sudo_case_sensitive(void **state)
|
|
|
4de095 |
+{
|
|
|
4de095 |
+ errno_t ret;
|
|
|
4de095 |
+ char *filter;
|
|
|
4de095 |
+ const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_HOST,
|
|
|
4de095 |
+ SYSDB_SUDO_CACHE_AT_RUNASUSER,
|
|
|
4de095 |
+ SYSDB_SUDO_CACHE_AT_USER, NULL };
|
|
|
4de095 |
+ struct ldb_message **msgs = NULL;
|
|
|
4de095 |
+ size_t msgs_count;
|
|
|
4de095 |
+ const char *result;
|
|
|
4de095 |
+ struct ldb_message_element *element;
|
|
|
4de095 |
+ struct sysdb_attrs *rule;
|
|
|
4de095 |
+ struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
4de095 |
+ struct sysdb_test_ctx);
|
|
|
4de095 |
+ const char *lowered_name = sss_tc_utf8_str_tolower(test_ctx, users[0].name);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ rule = sysdb_new_attrs(test_ctx);
|
|
|
4de095 |
+ assert_non_null(rule);
|
|
|
4de095 |
+ create_rule_attrs_multiple_sudoUser(rule);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ test_ctx->tctx->dom->case_sensitive = true;
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
|
|
|
4de095 |
+ assert_non_null(filter);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
|
|
|
4de095 |
+ attrs, &msgs_count, &msgs);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ assert_int_equal(msgs_count, 1);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
|
|
|
4de095 |
+ assert_non_null(result);
|
|
|
4de095 |
+ assert_string_equal(result, rules[0].name);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_HOST,
|
|
|
4de095 |
+ NULL);
|
|
|
4de095 |
+ assert_non_null(result);
|
|
|
4de095 |
+ assert_string_equal(result, rules[0].host);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_RUNASUSER,
|
|
|
4de095 |
+ NULL);
|
|
|
4de095 |
+ assert_non_null(result);
|
|
|
4de095 |
+ assert_string_equal(result, rules[0].as_user);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
|
|
|
4de095 |
+ users[0].name);
|
|
|
4de095 |
+ assert_int_equal(ret, 1);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
|
|
|
4de095 |
+ lowered_name);
|
|
|
4de095 |
+ assert_int_equal(ret, 0);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
|
|
|
4de095 |
+ users[1].name);
|
|
|
4de095 |
+ assert_int_equal(ret, 1);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
|
|
|
4de095 |
+ users[2].name);
|
|
|
4de095 |
+ assert_int_equal(ret, 1);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ element = ldb_msg_find_element(msgs[0], SYSDB_SUDO_CACHE_AT_USER);
|
|
|
4de095 |
+ assert_int_equal(element->num_values, 3);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ talloc_zfree(lowered_name);
|
|
|
4de095 |
+ talloc_zfree(rule);
|
|
|
4de095 |
+ talloc_zfree(filter);
|
|
|
4de095 |
+ talloc_zfree(msgs);
|
|
|
4de095 |
+}
|
|
|
4de095 |
+
|
|
|
4de095 |
+void test_store_sudo_case_insensitive(void **state)
|
|
|
4de095 |
+{
|
|
|
4de095 |
+ errno_t ret;
|
|
|
4de095 |
+ char *filter;
|
|
|
4de095 |
+ const char *attrs[] = { SYSDB_SUDO_CACHE_AT_CN, SYSDB_SUDO_CACHE_AT_HOST,
|
|
|
4de095 |
+ SYSDB_SUDO_CACHE_AT_RUNASUSER,
|
|
|
4de095 |
+ SYSDB_SUDO_CACHE_AT_USER, NULL };
|
|
|
4de095 |
+ struct ldb_message **msgs = NULL;
|
|
|
4de095 |
+ size_t msgs_count;
|
|
|
4de095 |
+ const char *result;
|
|
|
4de095 |
+ struct ldb_message_element *element;
|
|
|
4de095 |
+ struct sysdb_attrs *rule;
|
|
|
4de095 |
+ struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
4de095 |
+ struct sysdb_test_ctx);
|
|
|
4de095 |
+ const char *lowered_name = sss_tc_utf8_str_tolower(test_ctx, users[0].name);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ rule = sysdb_new_attrs(test_ctx);
|
|
|
4de095 |
+ assert_non_null(rule);
|
|
|
4de095 |
+ create_rule_attrs_multiple_sudoUser(rule);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ test_ctx->tctx->dom->case_sensitive = false;
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = sysdb_sudo_store(test_ctx->tctx->dom, &rule, 1);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ filter = sysdb_sudo_filter_user(test_ctx, users[0].name, NULL, 0);
|
|
|
4de095 |
+ assert_non_null(filter);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ ret = sysdb_search_sudo_rules(test_ctx, test_ctx->tctx->dom, filter,
|
|
|
4de095 |
+ attrs, &msgs_count, &msgs);
|
|
|
4de095 |
+ assert_int_equal(ret, EOK);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ assert_int_equal(msgs_count, 1);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_CN, NULL);
|
|
|
4de095 |
+ assert_non_null(result);
|
|
|
4de095 |
+ assert_string_equal(result, rules[0].name);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_HOST,
|
|
|
4de095 |
+ NULL);
|
|
|
4de095 |
+ assert_non_null(result);
|
|
|
4de095 |
+ assert_string_equal(result, rules[0].host);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ result = ldb_msg_find_attr_as_string(msgs[0], SYSDB_SUDO_CACHE_AT_RUNASUSER,
|
|
|
4de095 |
+ NULL);
|
|
|
4de095 |
+ assert_non_null(result);
|
|
|
4de095 |
+ assert_string_equal(result, rules[0].as_user);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ for (int i = 0; i < 3; i++) {
|
|
|
4de095 |
+ ret = ldb_msg_check_string_attribute(msgs[0], SYSDB_SUDO_CACHE_AT_USER,
|
|
|
4de095 |
+ users[i].name);
|
|
|
4de095 |
+ assert_int_equal(ret, 1);
|
|
|
4de095 |
+ }
|
|
|
4de095 |
+
|
|
|
4de095 |
+ /* test there is no duplication of lowercase forms */
|
|
|
4de095 |
+ element = ldb_msg_find_element(msgs[0], SYSDB_SUDO_CACHE_AT_USER);
|
|
|
4de095 |
+ assert_int_equal(element->num_values, 4);
|
|
|
4de095 |
+
|
|
|
4de095 |
+ talloc_zfree(lowered_name);
|
|
|
4de095 |
+ talloc_zfree(rule);
|
|
|
4de095 |
+ talloc_zfree(filter);
|
|
|
4de095 |
+ talloc_zfree(msgs);
|
|
|
4de095 |
+}
|
|
|
4de095 |
+
|
|
|
4de095 |
void test_sudo_purge_by_filter(void **state)
|
|
|
4de095 |
{
|
|
|
4de095 |
errno_t ret;
|
|
|
4de095 |
@@ -648,6 +808,12 @@ int main(int argc, const char *argv[])
|
|
|
4de095 |
cmocka_unit_test_setup_teardown(test_store_sudo,
|
|
|
4de095 |
test_sysdb_setup,
|
|
|
4de095 |
test_sysdb_teardown),
|
|
|
4de095 |
+ cmocka_unit_test_setup_teardown(test_store_sudo_case_sensitive,
|
|
|
4de095 |
+ test_sysdb_setup,
|
|
|
4de095 |
+ test_sysdb_teardown),
|
|
|
4de095 |
+ cmocka_unit_test_setup_teardown(test_store_sudo_case_insensitive,
|
|
|
4de095 |
+ test_sysdb_setup,
|
|
|
4de095 |
+ test_sysdb_teardown),
|
|
|
4de095 |
|
|
|
4de095 |
/* sysdb_sudo_purge() */
|
|
|
4de095 |
cmocka_unit_test_setup_teardown(test_sudo_purge_by_filter,
|
|
|
4de095 |
--
|
|
|
4de095 |
2.9.3
|
|
|
4de095 |
|