sssd/0056-TESTS-Add-a-test-for-whitespace-trimming-in-netgroup.patch
Michal Židek c0971b7e39 Backport a bunch of upstream fixes
- Resolves: upstream#3821 - crash related to sbus_router_destructor()
- Resolves: upstream#3810 - sbus2: fix memory leak in sbus_message_bound_ref
- Resolves: upstream#3819 - sssd only sets the SELinux login context if it
                            differs from the default
- Resolves: upstream#3807 - The sbus codegen script relies on "python" which
                            might not be available on all distributions
- Resolves: upstream#3820 - sudo: search with lower cased name for case
                            insensitive domains
- Resolves: upstream#3701 - [RFE] Allow changing default behavior of SSSD from
                            an allow-any default to a deny-any default when it
                            can't find any GPOs to apply to a user login.
- Resolves: upstream#3828 - Invalid domain provider causes SSSD to abort
                            startup
- Resolves: upstream#3500 - Make sure sssd is a replacement for pam_pkcs11
                            also for local account authentication
- Resolves: upstream#3812 - sssd 2.0.0 segfaults on startup
- Resolves: upstream#3826 - Remove references of sss_user/group/add/del
                            commands in man pages since local provider is
                            deprecated
- Resolves: upstream#3827 - SSSD should log to syslog if a domain is not
                            started due to a misconfiguration
- Resolves: upstream#3830 - Printing incorrect information about domain with
                            sssctl utility
- Resolves: upstream#3489 - p11_child should work wit openssl1.0+
- Resolves: upstream#3750 - [RFE] man 5 sssd-files should mention necessary
                            changes in nsswitch.conf
- Resovles: upstream#3650 - RFE: Require smartcard authentication
- Resolves: upstream#3334 - sssctl config-check does not check any special
                            characters in domain name of domain section
- Resolves: upstream#3849 - Files: The files provider always enumerates
                            which causes duplicate when running getent passwd
- Related: upstream#3855 - session not recording for local user when groups
                           defined
- Resolves: upstream#3802 - Reuse sysdb_error_to_errno() outside sysdb
- Related: upstream#3493 - Remove the pysss.local interface
2018-10-24 14:40:58 +02:00

182 lines
6.3 KiB
Diff

From 941e67b0bbb780aadb6461b60b4e3554dfb893db Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Wed, 16 May 2018 10:23:49 +0200
Subject: [PATCH 71/83] TESTS: Add a test for whitespace trimming in netgroup
entries
This is a unit test for commit dbb1abae6eaa9df24f61e3a9f855e2461a66a197
Reviewed-by: Tomas Halman <thalman@redhat.com>
---
src/tests/sysdb-tests.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 130 insertions(+), 2 deletions(-)
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 933a07e..d3117cd 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -4388,6 +4388,125 @@ START_TEST (test_netgroup_base_dn)
}
END_TEST
+static errno_t netgr_triple_to_attrs(struct sysdb_attrs *attrs,
+ struct sysdb_netgroup_ctx *netgrent)
+{
+ int ret;
+ char *dummy;
+
+ dummy = talloc_asprintf(attrs, "(%s,%s,%s)",
+ netgrent->value.triple.hostname,
+ netgrent->value.triple.username,
+ netgrent->value.triple.domainname);
+ if (dummy == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed.\n");
+ return ENOMEM;
+ }
+
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NETGROUP_TRIPLE, dummy);
+ talloc_zfree(dummy);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_attrs_add_string failed.\n");
+ return ret;
+ }
+
+ return EOK;
+}
+
+static errno_t store_netgr(struct sysdb_test_ctx *test_ctx,
+ const char *name,
+ struct sysdb_netgroup_ctx *netgrent)
+{
+ struct sysdb_attrs *attrs;
+ errno_t ret;
+
+ attrs = sysdb_new_attrs(test_ctx);
+ if (attrs == NULL) {
+ return ENOMEM;
+ }
+
+ ret = netgr_triple_to_attrs(attrs, netgrent);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_netgroup failed.\n");
+ return ret;
+ }
+
+ ret = sysdb_add_netgroup(test_ctx->domain, name, NULL, attrs, NULL,
+ 0, 0);
+ talloc_zfree(attrs);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_netgroup failed.\n");
+ return ret;
+ }
+
+ return EOK;
+}
+
+static bool sysdb_netgr_ctx_cmp(struct sysdb_netgroup_ctx *a,
+ struct sysdb_netgroup_ctx *b)
+{
+ return a->type == b->type &&
+ strcmp(a->value.triple.username, b->value.triple.username) == 0 &&
+ strcmp(a->value.triple.hostname, b->value.triple.hostname) == 0 &&
+ strcmp(a->value.triple.domainname, b->value.triple.domainname) == 0;
+}
+
+START_TEST (test_sysdb_netgr_to_entries)
+{
+ errno_t ret;
+ bool bret;
+ struct sysdb_test_ctx *test_ctx;
+ struct sysdb_netgroup_ctx simple_netgroup = {
+ .type = SYSDB_NETGROUP_TRIPLE_VAL,
+ .value.triple.hostname = discard_const("host"),
+ .value.triple.username = discard_const("user"),
+ .value.triple.domainname = discard_const("domain"),
+ };
+ struct sysdb_netgroup_ctx ws_netgroup = {
+ .type = SYSDB_NETGROUP_TRIPLE_VAL,
+ .value.triple.hostname = discard_const(" host "),
+ .value.triple.username = discard_const(" user "),
+ .value.triple.domainname = discard_const(" domain "),
+ };
+ struct ldb_result *res;
+ struct sysdb_netgroup_ctx **entries;
+ size_t netgroup_count;
+
+ ret = setup_sysdb_tests(&test_ctx);
+ fail_if(ret != EOK, "Could not set up the test");
+
+ ret = store_netgr(test_ctx, "simple_netgroup", &simple_netgroup);
+ fail_if(ret != EOK, "Could not store the netgr");
+
+ ret = sysdb_getnetgr(test_ctx, test_ctx->domain, "simple_netgroup", &res);
+ fail_unless(ret == EOK, "sysdb_getnetgr error [%d][%s]",
+ ret, strerror(ret));
+ fail_unless(res->count == 1, "Received [%d] responses",
+ res->count);
+ ret = sysdb_netgr_to_entries(test_ctx, res, &entries, &netgroup_count);
+ fail_unless(ret == EOK, "sysdb_netgr_to_entries error [%d][%s]",
+ ret, strerror(ret));
+ fail_unless(netgroup_count == 1, "Received [%d] triples", netgroup_count);
+ bret = sysdb_netgr_ctx_cmp(entries[0], &simple_netgroup);
+ fail_unless(bret == true, "Netgroup triples do not match");
+
+ ret = store_netgr(test_ctx, "ws_netgroup", &ws_netgroup);
+ fail_if(ret != EOK, "Could not store the netgr");
+
+ ret = sysdb_getnetgr(test_ctx, test_ctx->domain, "ws_netgroup", &res);
+ fail_unless(ret == EOK, "sysdb_getnetgr error [%d][%s]",
+ ret, strerror(ret));
+ fail_unless(res->count == 1, "Received [%d] responses",
+ res->count);
+ ret = sysdb_netgr_to_entries(test_ctx, res, &entries, &netgroup_count);
+ fail_unless(ret == EOK, "sysdb_netgr_to_entries error [%d][%s]",
+ ret, strerror(ret));
+ fail_unless(netgroup_count == 1, "Received [%d] triples", netgroup_count);
+ bret = sysdb_netgr_ctx_cmp(entries[0], &simple_netgroup);
+ fail_unless(bret == true, "Netgroup triples do not match");
+}
+END_TEST
+
START_TEST(test_odd_characters)
{
errno_t ret;
@@ -4404,6 +4523,8 @@ START_TEST(test_odd_characters)
const char *received_group;
static const char *user_attrs[] = SYSDB_PW_ATTRS;
static const char *netgr_attrs[] = SYSDB_NETGR_ATTRS;
+ struct sysdb_netgroup_ctx **entries;
+ size_t netgroup_count;
/* Setup */
ret = setup_sysdb_tests(&test_ctx);
@@ -4546,9 +4667,13 @@ START_TEST(test_odd_characters)
ret, strerror(ret));
fail_unless(res->count == 1, "Received [%d] responses",
res->count);
- talloc_zfree(res);
- /* ===== Arbitrary Entries ===== */
+ /* Parse */
+ ret = sysdb_netgr_to_entries(test_ctx, res, &entries, &netgroup_count);
+ fail_unless(ret == EOK, "sysdb_netgr_to_entries error [%d][%s]",
+ ret, strerror(ret));
+
+ talloc_zfree(res);
talloc_free(test_ctx);
}
@@ -7418,6 +7543,9 @@ Suite *create_sysdb_suite(void)
tcase_add_test(tc_sysdb, test_netgroup_base_dn);
+ /* Test splitting the netgroup triple */
+ tcase_add_test(tc_sysdb, test_sysdb_netgr_to_entries);
+
/* ===== SERVICE TESTS ===== */
/* Create a new service */
--
2.9.5