From 25072dd5274f07255cdc930f6257c4cbf74692de Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Tue, 7 Oct 2014 16:57:40 +0200 Subject: tests: add test for sysdb_get_user_attr with subdomain user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Lukáš Slebodník --- src/tests/sysdb-tests.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/tests') diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index 8ba214c83..c25115697 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -1294,6 +1294,57 @@ done: } END_TEST +START_TEST (test_sysdb_get_user_attr_subdomain) +{ + struct sysdb_test_ctx *test_ctx; + struct sss_domain_info *subdomain = NULL; + const char *attrs[] = { SYSDB_SHELL, NULL }; + struct ldb_result *res; + const char *attrval; + const char *username = "test_sysdb_get_user_attr_subdomain"; + const char *fq_name; + int ret; + + /* Setup */ + ret = setup_sysdb_tests(&test_ctx); + fail_if(ret != EOK, "Could not set up the test"); + + /* Create subdomain */ + subdomain = new_subdomain(test_ctx, test_ctx->domain, + "test.sub", "TEST.SUB", "test", "S-3", + false, false, NULL); + fail_if(subdomain == NULL, "Failed to create new subdomain."); + + ret = sss_names_init_from_args(test_ctx, + "(((?P[^\\\\]+)\\\\(?P.+$))|" \ + "((?P[^@]+)@(?P.+$))|" \ + "(^(?P[^@\\\\]+)$))", + "%1$s@%2$s", &subdomain->names); + fail_if(ret != EOK, "Failed to init names."); + + /* Create user */ + fq_name = sss_tc_fqname(test_ctx, subdomain->names, subdomain, username); + fail_if(fq_name == NULL, "Failed to create fq name."); + + ret = sysdb_store_user(subdomain, fq_name, NULL, 12345, 0, "Gecos", + "/home/userhome", "/bin/bash", NULL, NULL, NULL, + -1, 0); + fail_if(ret != EOK, "sysdb_store_user failed."); + + /* Test */ + ret = sysdb_get_user_attr(test_ctx, subdomain, username, + attrs, &res); + fail_if(ret != EOK, "Could not get user attributes."); + fail_if(res->count != 1, "Invalid number of entries, expected 1, got %d", + res->count); + + attrval = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, 0); + fail_if(strcmp(attrval, "/bin/bash") != 0, "Got bad attribute value."); + + talloc_free(test_ctx); +} +END_TEST + START_TEST (test_sysdb_add_group_member) { struct sysdb_test_ctx *test_ctx; @@ -5946,6 +5997,9 @@ Suite *create_sysdb_suite(void) tcase_add_test(tc_sysdb, test_group_rename); tcase_add_test(tc_sysdb, test_user_rename); + /* Test GetUserAttr with subdomain user */ + tcase_add_test(tc_sysdb, test_sysdb_get_user_attr_subdomain); + /* ===== NETGROUP TESTS ===== */ /* Create a new netgroup */ -- cgit