summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-01-14 20:30:04 -0500
committerJakub Hrozek <jhrozek@redhat.com>2013-02-10 22:08:47 +0100
commitbba1a5fd62cffcae076d1351df5a83fbc4a6ec17 (patch)
tree8dbc22a528ccda8cc889a5297df2edb1919d86e6 /src/tests
parent1f800ebb0f190854b8296146174f3d696a426333 (diff)
downloadsssd-bba1a5fd62cffcae076d1351df5a83fbc4a6ec17.tar.gz
sssd-bba1a5fd62cffcae076d1351df5a83fbc4a6ec17.tar.bz2
sssd-bba1a5fd62cffcae076d1351df5a83fbc4a6ec17.zip
Change the way domains are linked.
- Use a double-linked list for domains and subdomains. - Never remove a subdomain, simply mark it as disabled if it becomes unused. - Rework the way subdomains are refreshed. Now sysdb_update_subdomains() actually updates the current subdomains and marks as disabled the ones not found in the sysdb or add new ones found. It never removes them. Removal of missing domains from sysdb is deferred to the providers, which will perform it at refresh time, for the ipa provider that is done by ipa_subdomains_write_mappings() now. sysdb_update_subdomains() is then used to update the memory hierarchy of the subdomains. - Removes sysdb_get_subdomains() - Removes copy_subdomain() - Add sysdb_subdomain_delete()
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/pac_responder-tests.c43
-rw-r--r--src/tests/sysdb-tests.c87
2 files changed, 43 insertions, 87 deletions
diff --git a/src/tests/pac_responder-tests.c b/src/tests/pac_responder-tests.c
index 7d352a0e..847dbe00 100644
--- a/src/tests/pac_responder-tests.c
+++ b/src/tests/pac_responder-tests.c
@@ -98,15 +98,7 @@ void pac_setup(void) {
fail_unless(pac_ctx->rctx->domains->domain_id != NULL,
"talloc_strdup failed.");
- pac_ctx->rctx->domains->subdomain_count = 1;
- pac_ctx->rctx->domains->subdomains = talloc_zero_array(pac_ctx->rctx->domains,
- struct sss_domain_info *,
- pac_ctx->rctx->domains->subdomain_count);
- fail_unless(pac_ctx->rctx->domains->subdomains != NULL,
- "talloc_array_zero failed");
-
- sd = talloc_zero(pac_ctx->rctx->domains->subdomains,
- struct sss_domain_info);
+ sd = talloc_zero(pac_ctx->rctx->domains, struct sss_domain_info);
fail_unless(sd != NULL, "talloc_zero failed.");
sd->name = talloc_strdup(sd, "remote.dom");
@@ -118,7 +110,7 @@ void pac_setup(void) {
sd->domain_id = talloc_strdup(sd, test_remote_dom_sid_str);
fail_unless(sd->domain_id != NULL, "talloc_strdup failed");
- pac_ctx->rctx->domains->subdomains[0] = sd;
+ pac_ctx->rctx->domains->subdomains = sd;
err = sss_idmap_init(idmap_talloc, pac_ctx, idmap_talloc_free,
&pac_ctx->idmap_ctx);
@@ -285,8 +277,8 @@ END_TEST
#define NUM_DOMAINS 10
START_TEST(pac_test_find_domain_by_id)
{
+ struct sss_domain_info *domains;
struct sss_domain_info *dom;
- struct sss_domain_info **domains;
size_t c;
char *id;
@@ -296,33 +288,30 @@ START_TEST(pac_test_find_domain_by_id)
dom = find_domain_by_id(NULL, "id");
fail_unless(dom == NULL, "Domain returned without domain list.");
- domains = talloc_zero_array(global_talloc_context, struct sss_domain_info *,
- NUM_DOMAINS);
+ domains = NULL;
for (c = 0; c < NUM_DOMAINS; c++) {
- domains[c] = talloc_zero(domains, struct sss_domain_info);
- fail_unless(domains[c] != NULL, "talloc_zero failed.");
-
- domains[c]->domain_id = talloc_asprintf(domains[c],
- "ID-of-domains-%zu", c);
- fail_unless(domains[c]->domain_id != NULL, "talloc_asprintf failed.");
- if (c > 0) {
- domains[c-1]->next = domains[c];
- }
+ dom = talloc_zero(domains, struct sss_domain_info);
+ fail_unless(dom != NULL, "talloc_zero failed.");
+
+ dom->domain_id = talloc_asprintf(dom, "ID-of-domains-%zu", c);
+ fail_unless(dom->domain_id != NULL, "talloc_aprintf failed.");
+
+ DLIST_ADD(domains, dom);
}
- dom = find_domain_by_id(domains[0], NULL);
+ dom = find_domain_by_id(domains, NULL);
fail_unless(dom == NULL, "Domain returned without search domain.");
- dom = find_domain_by_id(domains[0], "DOES-NOT_EXISTS");
+ dom = find_domain_by_id(domains, "DOES-NOT_EXISTS");
fail_unless(dom == NULL, "Domain returned with non existing id.");
for (c = 0; c < NUM_DOMAINS; c++) {
id = talloc_asprintf(global_talloc_context, "ID-of-domains-%zu", c);
fail_unless(id != NULL, "talloc_asprintf failed.\n");
- dom = find_domain_by_id(domains[0], id);
- fail_unless(dom == domains[c], "Wrong domain returned for id [%s].",
- id);
+ dom = find_domain_by_id(domains, id);
+ fail_unless((strcmp(dom->domain_id, id) == 0),
+ "Wrong domain returned for id [%s].", id);
talloc_free(id);
}
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 58198d50..081df6cf 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -4471,90 +4471,54 @@ START_TEST(test_sysdb_subdomain_create)
{
struct sysdb_test_ctx *test_ctx;
errno_t ret;
- struct sss_domain_info **cur_subdomains = NULL;
- size_t cur_subdomains_count;
- struct sss_domain_info *new_subdom1;
- struct sss_domain_info *new_subdom2;
+ const char const *dom1[4] = { "dom1.sub", "DOM1.SUB", "dom1", "S-1" };
+ const char const *dom2[4] = { "dom2.sub", "DOM2.SUB", "dom2", "S-2" };
ret = setup_sysdb_tests(&test_ctx);
fail_if(ret != EOK, "Could not set up the test");
- ret = sysdb_get_subdomains(test_ctx, test_ctx->domain,
- &cur_subdomains_count, &cur_subdomains);
- fail_unless(ret == EOK, "sysdb_get_subdomains failed with [%d][%s]",
- ret, strerror(ret));
- fail_unless(cur_subdomains != NULL, "Non zero sub-domains returned.");
- fail_unless(cur_subdomains[0] == NULL, "No empty sub-domain list returned.");
-
- test_ctx->domain->subdomains = talloc_array(test_ctx->domain,
- struct sss_domain_info *, 2);
- fail_unless(test_ctx->domain->subdomains != NULL,
- "talloc_array_zero failed");
-
- new_subdom1 = new_subdomain(test_ctx, test_ctx->domain,
- "dom1.sub", "DOM1.SUB", "dom1", "S-1");
- fail_unless(new_subdom1 != NULL, "Failed to create new subdomin.");
- test_ctx->domain->subdomains[0] = new_subdom1;
- test_ctx->domain->subdomain_count = 1;
-
ret = sysdb_subdomain_store(test_ctx->sysdb,
- "dom1.sub", "DOM1.SUB", "dom1", "S-1");
+ dom1[0], dom1[1], dom1[2], dom1[3]);
fail_if(ret != EOK, "Could not set up the test (dom1)");
ret = sysdb_update_subdomains(test_ctx->domain);
fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]",
ret, strerror(ret));
- ret = sysdb_get_subdomains(test_ctx, test_ctx->domain,
- &cur_subdomains_count, &cur_subdomains);
- fail_unless(ret == EOK, "sysdb_get_subdomains failed with [%d][%s]",
- ret, strerror(ret));
- fail_if(cur_subdomains_count != 1, "Wrong number of sub-domains returned.");
- fail_if(cur_subdomains[0] == NULL, "Empyt sub-domain list returned.");
- fail_if(strcmp(cur_subdomains[0]->name, new_subdom1->name) != 0,
+ fail_if(test_ctx->domain->subdomains == NULL, "Empyt sub-domain list.");
+ fail_if(strcmp(test_ctx->domain->subdomains->name, dom1[0]) != 0,
"Unexpected sub-domain found, expected [%s], got [%s]",
- new_subdom1->name, cur_subdomains[0]->name);
-
- new_subdom2 = new_subdomain(test_ctx, test_ctx->domain,
- "dom2.sub", "DOM2.SUB", "dom2", "S-2");
- fail_unless(new_subdom2 != NULL, "Failed to create new subdomin.");
- test_ctx->domain->subdomains[1] = new_subdom2;
- test_ctx->domain->subdomain_count = 2;
+ dom1[0], test_ctx->domain->subdomains->name);
ret = sysdb_subdomain_store(test_ctx->sysdb,
- "dom2.sub", "DOM2.SUB", "dom2", "S-2");
+ dom2[0], dom2[1], dom2[2], dom2[3]);
fail_if(ret != EOK, "Could not set up the test (dom2)");
ret = sysdb_update_subdomains(test_ctx->domain);
fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]",
ret, strerror(ret));
- ret = sysdb_get_subdomains(test_ctx, test_ctx->domain,
- &cur_subdomains_count, &cur_subdomains);
- fail_unless(ret == EOK, "sysdb_get_subdomains failed with [%d][%s]",
- ret, strerror(ret));
- fail_if(cur_subdomains_count != 2, "Wrong number of sub-domains returned.");
- fail_if(cur_subdomains[1] == NULL, "Empyt sub-domain list returned.");
- fail_if(strcmp(cur_subdomains[1]->name, new_subdom2->name) != 0,
+ fail_if(test_ctx->domain->subdomains->next == NULL, "Missing sub-domain");
+ fail_if(strcmp(test_ctx->domain->subdomains->next->name, dom2[0]) != 0,
"Unexpected sub-domain found, expected [%s], got [%s]",
- new_subdom2->name, cur_subdomains[1]->name);
+ dom2[0], test_ctx->domain->subdomains->next->name);
- test_ctx->domain->subdomain_count = 0;
- talloc_zfree(test_ctx->domain->subdomains);
+ ret = sysdb_subdomain_delete(test_ctx->sysdb, dom2[0]);
+ fail_if(ret != EOK, "Could not delete subdomain");
+
+ ret = sysdb_subdomain_delete(test_ctx->sysdb, dom1[0]);
+ fail_if(ret != EOK, "Could not delete subdomain");
ret = sysdb_update_subdomains(test_ctx->domain);
fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]",
ret, strerror(ret));
- ret = sysdb_get_subdomains(test_ctx, test_ctx->domain,
- &cur_subdomains_count, &cur_subdomains);
- fail_unless(ret == EOK, "sysdb_get_subdomains failed with [%d][%s]",
- ret, strerror(ret));
- fail_unless(cur_subdomains != NULL, "No sub-domains returned.");
- fail_if(cur_subdomains[0] != NULL, "No empty sub-domain list returned.");
+ fail_unless(test_ctx->domain->subdomains->disabled, "Subdomain not disabled.");
}
END_TEST
+const char const *testdom[4] = { "test.sub", "TEST.SUB", "test", "S-3" };
+
START_TEST(test_sysdb_subdomain_store_user)
{
struct sysdb_test_ctx *test_ctx;
@@ -4568,9 +4532,10 @@ START_TEST(test_sysdb_subdomain_store_user)
fail_if(ret != EOK, "Could not set up the test");
subdomain = new_subdomain(test_ctx, test_ctx->domain,
- "test.sub", "TEST.SUB", "test", "S-3");
+ testdom[0], testdom[1], testdom[2], testdom[3]);
fail_unless(subdomain != NULL, "Failed to create new subdomin.");
- ret = sysdb_subdomain_create(subdomain);
+ ret = sysdb_subdomain_store(test_ctx->sysdb,
+ testdom[0], testdom[1], testdom[2], testdom[3]);
fail_if(ret != EOK, "Could not set up the test (test subdom)");
ret = sysdb_update_subdomains(test_ctx->domain);
@@ -4624,9 +4589,10 @@ START_TEST(test_sysdb_subdomain_user_ops)
fail_if(ret != EOK, "Could not set up the test");
subdomain = new_subdomain(test_ctx, test_ctx->domain,
- "test.sub", "TEST.SUB", "test", "S-3");
+ testdom[0], testdom[1], testdom[2], testdom[3]);
fail_unless(subdomain != NULL, "Failed to create new subdomin.");
- ret = sysdb_subdomain_create(subdomain);
+ ret = sysdb_subdomain_store(test_ctx->sysdb,
+ testdom[0], testdom[1], testdom[2], testdom[3]);
fail_if(ret != EOK, "Could not set up the test (test subdom)");
ret = sysdb_update_subdomains(test_ctx->domain);
@@ -4676,9 +4642,10 @@ START_TEST(test_sysdb_subdomain_group_ops)
fail_if(ret != EOK, "Could not set up the test");
subdomain = new_subdomain(test_ctx, test_ctx->domain,
- "test.sub", "TEST.SUB", "test", "S-3");
+ testdom[0], testdom[1], testdom[2], testdom[3]);
fail_unless(subdomain != NULL, "Failed to create new subdomin.");
- ret = sysdb_subdomain_create(subdomain);
+ ret = sysdb_subdomain_store(test_ctx->sysdb,
+ testdom[0], testdom[1], testdom[2], testdom[3]);
fail_if(ret != EOK, "Could not set up the test (test subdom)");
ret = sysdb_update_subdomains(test_ctx->domain);