summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2013-11-01 18:40:08 +0100
committerJakub Hrozek <jhrozek@redhat.com>2013-11-04 15:44:32 +0100
commitec7732b91c7ca5367e2ae62a237d975ed1b9763f (patch)
tree267a2956e93c81a02c12c1718ce2afd6d335fb78
parent654757bcead49427baaeb1b368c0e3433b67c51a (diff)
downloadsssd-ec7732b91c7ca5367e2ae62a237d975ed1b9763f.tar.gz
sssd-ec7732b91c7ca5367e2ae62a237d975ed1b9763f.tar.xz
sssd-ec7732b91c7ca5367e2ae62a237d975ed1b9763f.zip
Enhance/add unit tests for find_subdomain_by_sid/name
-rw-r--r--src/tests/cmocka/test_utils.c263
-rw-r--r--src/util/domain_info_utils.c4
2 files changed, 267 insertions, 0 deletions
diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c
index 1be59ab69..76be12992 100644
--- a/src/tests/cmocka/test_utils.c
+++ b/src/tests/cmocka/test_utils.c
@@ -81,6 +81,211 @@ void teardown_dom_list(void **state)
assert_true(leak_check_teardown());
}
+void test_find_subdomain_by_name_null(void **state)
+{
+ struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
+ struct dom_list_test_ctx);
+ struct sss_domain_info *dom;
+
+ dom = find_subdomain_by_name(NULL, NULL, false);
+ assert_null(dom);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, NULL, false);
+ assert_null(dom);
+
+ dom = find_subdomain_by_name(NULL, "test", false);
+ assert_null(dom);
+}
+
+void test_find_subdomain_by_name(void **state)
+{
+ struct dom_list_test_ctx *test_ctx = talloc_get_type(*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 < test_ctx->dom_count; c++) {
+ name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
+ assert_non_null(name);
+
+ flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
+ assert_non_null(flat_name);
+
+ sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
+ assert_non_null(sid);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, name, false);
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, name, true);
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, true);
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, false);
+ assert_null(dom);
+
+ talloc_free(name);
+ talloc_free(flat_name);
+ talloc_free(sid);
+ }
+}
+
+void test_find_subdomain_by_name_missing_flat_name(void **state)
+{
+ struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
+ struct dom_list_test_ctx);
+ struct sss_domain_info *dom;
+ size_t c;
+ char *name;
+ char *flat_name;
+ char *sid;
+ size_t mis;
+
+ mis = test_ctx->dom_count/2;
+ assert_true((mis >= 1 && mis < test_ctx->dom_count));
+
+ dom = test_ctx->dom_list;
+ for (c = 0; c < mis; c++) {
+ assert_non_null(dom);
+ dom = dom->next;
+ }
+ assert_non_null(dom);
+ dom->flat_name = NULL;
+
+ for (c = 0; c < test_ctx->dom_count; c++) {
+ name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
+ assert_non_null(name);
+
+ flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
+ assert_non_null(flat_name);
+
+ sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
+ assert_non_null(sid);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, name, true);
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ if (c == mis - 1) {
+ assert_null(dom->flat_name);
+ } else {
+ assert_string_equal(flat_name, dom->flat_name);
+ }
+ assert_string_equal(sid, dom->domain_id);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, name, false);
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ if (c == mis - 1) {
+ assert_null(dom->flat_name);
+ } else {
+ assert_string_equal(flat_name, dom->flat_name);
+ }
+ assert_string_equal(sid, dom->domain_id);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, true);
+ if (c == mis - 1) {
+ assert_null(dom);
+ } else {
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+ }
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, false);
+ assert_null(dom);
+
+ talloc_free(name);
+ talloc_free(flat_name);
+ talloc_free(sid);
+ }
+}
+
+void test_find_subdomain_by_name_disabled(void **state)
+{
+ struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
+ struct dom_list_test_ctx);
+ struct sss_domain_info *dom;
+ size_t c;
+ char *name;
+ char *flat_name;
+ char *sid;
+ size_t mis;
+
+ mis = test_ctx->dom_count/2;
+ assert_true((mis >= 1 && mis < test_ctx->dom_count));
+
+ dom = test_ctx->dom_list;
+ for (c = 0; c < mis; c++) {
+ assert_non_null(dom);
+ dom = dom->next;
+ }
+ assert_non_null(dom);
+ dom->disabled = true;
+
+ for (c = 0; c < test_ctx->dom_count; c++) {
+ name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
+ assert_non_null(name);
+
+ flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
+ assert_non_null(flat_name);
+
+ sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
+ assert_non_null(sid);
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, name, true);
+ if (c == mis - 1) {
+ assert_null(dom);
+ } else {
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+ }
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, name, false);
+ if (c == mis - 1) {
+ assert_null(dom);
+ } else {
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+ }
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, true);
+ if (c == mis - 1) {
+ assert_null(dom);
+ } else {
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+ }
+
+ dom = find_subdomain_by_name(test_ctx->dom_list, flat_name, false);
+ assert_null(dom);
+
+ talloc_free(name);
+ talloc_free(flat_name);
+ talloc_free(sid);
+ }
+}
+
void test_find_subdomain_by_sid_null(void **state)
{
struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
@@ -177,6 +382,54 @@ void test_find_subdomain_by_sid_missing_sid(void **state)
}
}
+void test_find_subdomain_by_sid_disabled(void **state)
+{
+ struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
+ struct dom_list_test_ctx);
+ struct sss_domain_info *dom;
+ size_t c;
+ char *name;
+ char *flat_name;
+ char *sid;
+ size_t mis;
+
+ mis = test_ctx->dom_count/2;
+ assert_true((mis >= 1 && mis < test_ctx->dom_count));
+
+ dom = test_ctx->dom_list;
+ for (c = 0; c < mis; c++) {
+ assert_non_null(dom);
+ dom = dom->next;
+ }
+ assert_non_null(dom);
+ dom->disabled = true;
+
+ for (c = 0; c < test_ctx->dom_count; c++) {
+ name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
+ assert_non_null(name);
+
+ flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
+ assert_non_null(flat_name);
+
+ sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
+ assert_non_null(sid);
+
+ dom = find_subdomain_by_sid(test_ctx->dom_list, sid);
+ if (c == mis - 1) {
+ assert_null(dom);
+ } else {
+ assert_non_null(dom);
+ assert_string_equal(name, dom->name);
+ assert_string_equal(flat_name, dom->flat_name);
+ assert_string_equal(sid, dom->domain_id);
+ }
+
+ talloc_free(name);
+ talloc_free(flat_name);
+ talloc_free(sid);
+ }
+}
+
int main(int argc, const char *argv[])
{
poptContext pc;
@@ -194,6 +447,16 @@ int main(int argc, const char *argv[])
setup_dom_list, teardown_dom_list),
unit_test_setup_teardown(test_find_subdomain_by_sid_missing_sid,
setup_dom_list, teardown_dom_list),
+ unit_test_setup_teardown(test_find_subdomain_by_sid_disabled,
+ setup_dom_list, teardown_dom_list),
+ unit_test_setup_teardown(test_find_subdomain_by_name_null,
+ setup_dom_list, teardown_dom_list),
+ unit_test_setup_teardown(test_find_subdomain_by_name,
+ setup_dom_list, teardown_dom_list),
+ unit_test_setup_teardown(test_find_subdomain_by_name_missing_flat_name,
+ setup_dom_list, teardown_dom_list),
+ unit_test_setup_teardown(test_find_subdomain_by_name_disabled,
+ setup_dom_list, teardown_dom_list),
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c
index 61efc0b40..5e7b2f2b6 100644
--- a/src/util/domain_info_utils.c
+++ b/src/util/domain_info_utils.c
@@ -93,6 +93,10 @@ struct sss_domain_info *find_subdomain_by_name(struct sss_domain_info *domain,
{
struct sss_domain_info *dom = domain;
+ if (name == NULL) {
+ return NULL;
+ }
+
while (dom && dom->disabled) {
dom = get_next_domain(dom, true);
}