tdb: version 1.4.12
[samba4-gss.git] / lib / ldb / tests / ldb_key_value_sub_txn_test.c
blob0b7c0240ec973f9bd3fe4e99a6f4f2de308f5ecf
1 /*
2 * Tests exercising the ldb key value operations.
4 * Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * from cmocka.c:
23 * These headers or their equivalents should be included prior to
24 * including
25 * this header file.
27 * #include <stdarg.h>
28 * #include <stddef.h>
29 * #include <setjmp.h>
31 * This allows test applications to use custom definitions of C standard
32 * library functions and types.
38 #include <stdarg.h>
39 #include <stddef.h>
40 #include <stdint.h>
41 #include <setjmp.h>
42 #include <cmocka.h>
44 #include <limits.h>
45 #define NO_FAILURE INT_MAX
46 #define FAILURE_LDB_ERR LDB_ERR_OTHER
49 * To test failure in ldb_kv_add, ldb_kv_delete, ldb_kv_modify and ldb_kv_rename
50 * we use the following global variables and macros to trigger a failure in
51 * the ldb_kv_<op>_internal functions. This allows testing of the sub
52 * transaction commits and roll backs in those operations.
54 * NOTE: Not all back ends support nested/sub transactions
56 int cmocka_unit_test_fail_add_internal_after = NO_FAILURE;
57 #define CMOCKA_UNIT_TEST_ADD_INTERNAL_FAIL \
59 cmocka_unit_test_fail_add_internal_after--;\
60 if (cmocka_unit_test_fail_add_internal_after <= 0) {\
61 assert_int_equal(LDB_SUCCESS, ret);\
62 ret = FAILURE_LDB_ERR;\
66 int cmocka_unit_test_fail_delete_internal_after = NO_FAILURE;
67 #define CMOCKA_UNIT_TEST_DELETE_INTERNAL_FAIL \
69 cmocka_unit_test_fail_delete_internal_after--;\
70 if (cmocka_unit_test_fail_delete_internal_after <= 0) {\
71 assert_int_equal(LDB_SUCCESS, ret);\
72 ret = FAILURE_LDB_ERR;\
76 int cmocka_unit_test_fail_rename_internal_after = NO_FAILURE;
77 #define CMOCKA_UNIT_TEST_RENAME_INTERNAL_FAIL \
79 cmocka_unit_test_fail_rename_internal_after--;\
80 if (cmocka_unit_test_fail_rename_internal_after <= 0) {\
81 assert_int_equal(LDB_SUCCESS, ret);\
82 ret = FAILURE_LDB_ERR;\
86 int cmocka_unit_test_fail_modify_internal_after = NO_FAILURE;
87 #define CMOCKA_UNIT_TEST_MODIFY_INTERNAL_FAIL \
89 cmocka_unit_test_fail_modify_internal_after--;\
90 if (cmocka_unit_test_fail_modify_internal_after <= 0) {\
91 assert_int_equal(LDB_SUCCESS, ret);\
92 ret = FAILURE_LDB_ERR;\
96 #include "ldb_key_value/ldb_kv.c"
99 #define DEFAULT_BE "tdb"
101 #ifndef TEST_BE
102 #define TEST_BE DEFAULT_BE
103 #endif /* TEST_BE */
105 #define NUM_RECS 1024
108 struct test_ctx {
109 struct tevent_context *ev;
110 struct ldb_context *ldb;
112 const char *dbfile;
113 const char *lockfile; /* lockfile is separate */
115 const char *dbpath;
119 * Remove the database files
121 static void unlink_old_db(struct test_ctx *test_ctx)
123 int ret;
125 errno = 0;
126 ret = unlink(test_ctx->lockfile);
127 if (ret == -1 && errno != ENOENT) {
128 fail();
131 errno = 0;
132 ret = unlink(test_ctx->dbfile);
133 if (ret == -1 && errno != ENOENT) {
134 fail();
139 * Test setup
141 static int noconn_setup(void **state)
143 struct test_ctx *test_ctx;
144 cmocka_unit_test_fail_add_internal_after = NO_FAILURE;
145 cmocka_unit_test_fail_delete_internal_after = NO_FAILURE;
146 cmocka_unit_test_fail_rename_internal_after = NO_FAILURE;
147 cmocka_unit_test_fail_modify_internal_after = NO_FAILURE;
149 test_ctx = talloc_zero(NULL, struct test_ctx);
150 assert_non_null(test_ctx);
152 test_ctx->ev = tevent_context_init(test_ctx);
153 assert_non_null(test_ctx->ev);
155 test_ctx->ldb = ldb_init(test_ctx, test_ctx->ev);
156 assert_non_null(test_ctx->ldb);
158 test_ctx->dbfile = talloc_strdup(test_ctx, "kvopstest.ldb");
159 assert_non_null(test_ctx->dbfile);
161 test_ctx->lockfile = talloc_asprintf(test_ctx, "%s-lock",
162 test_ctx->dbfile);
163 assert_non_null(test_ctx->lockfile);
165 test_ctx->dbpath = talloc_asprintf(test_ctx,
166 TEST_BE"://%s", test_ctx->dbfile);
167 assert_non_null(test_ctx->dbpath);
169 unlink_old_db(test_ctx);
170 *state = test_ctx;
171 return 0;
175 * Test teardown
177 static int noconn_teardown(void **state)
179 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
180 struct test_ctx);
182 unlink_old_db(test_ctx);
183 talloc_free(test_ctx);
184 return 0;
188 * Test setup
190 static int setup(void **state)
192 struct test_ctx *test_ctx;
193 int ret;
194 struct ldb_ldif *ldif;
195 const char *index_ldif = \
196 "dn: @INDEXLIST\n"
197 "@IDXGUID: objectUUID\n"
198 "@IDX_DN_GUID: GUID\n"
199 "\n";
201 noconn_setup((void **) &test_ctx);
203 ret = ldb_connect(test_ctx->ldb, test_ctx->dbpath, 0, NULL);
204 assert_int_equal(ret, 0);
206 while ((ldif = ldb_ldif_read_string(test_ctx->ldb, &index_ldif))) {
207 ret = ldb_add(test_ctx->ldb, ldif->msg);
208 assert_int_equal(ret, LDB_SUCCESS);
210 *state = test_ctx;
211 return 0;
215 * Test teardown
217 static int teardown(void **state)
219 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
220 struct test_ctx);
221 noconn_teardown((void **) &test_ctx);
222 return 0;
226 * Build an ldb_kv_context that can be passed to the ldb_kv operation under test
228 static struct ldb_kv_context* build_ldb_kv_context(
229 TALLOC_CTX *ctx,
230 struct ldb_module *module,
231 struct ldb_request *req)
233 struct ldb_kv_context *ldb_kv_ctx = NULL;
235 ldb_kv_ctx = talloc_zero(ctx, struct ldb_kv_context);
236 assert_non_null(ldb_kv_ctx);
238 ldb_kv_ctx->module = module;
239 ldb_kv_ctx->req = req;
241 return ldb_kv_ctx;
245 * Build an add request
247 static struct ldb_request *build_add_request(
248 TALLOC_CTX *ctx,
249 struct ldb_context *ldb,
250 const char* dc,
251 const char* uuid,
252 const char* cn)
254 int ret;
255 struct ldb_message *msg;
256 struct ldb_request *req;
258 msg = ldb_msg_new(ctx);
259 assert_non_null(msg);
261 msg->dn = ldb_dn_new_fmt(msg, ldb, "dc=%s", dc);
262 assert_non_null(msg->dn);
264 ret = ldb_msg_add_string(msg, "cn", cn);
265 assert_int_equal(ret, 0);
267 ret = ldb_msg_add_string(msg, "objectUUID", uuid);
268 assert_int_equal(ret, 0);
270 ret = ldb_msg_sanity_check(ldb, msg);
271 assert_int_equal(ret, LDB_SUCCESS);
273 ret = ldb_build_add_req(
274 &req, ldb, ldb, msg, NULL, NULL, ldb_op_default_callback, NULL);
275 assert_int_equal(ret, LDB_SUCCESS);
276 return req;
280 * Build a delete request
282 static struct ldb_request *build_delete_request(
283 TALLOC_CTX *ctx,
284 struct ldb_context *ldb,
285 const char* dc)
287 int ret = LDB_SUCCESS;
288 struct ldb_dn *dn = NULL;
289 struct ldb_request *req = NULL;
291 dn = ldb_dn_new_fmt(ctx, ldb, "dc=%s", dc);
292 assert_non_null(dn);
294 ret = ldb_build_del_req(
295 &req, ldb, ctx, dn, NULL, NULL, ldb_op_default_callback, NULL);
296 assert_int_equal(ret, LDB_SUCCESS);
297 return req;
301 * Build a rename request
303 static struct ldb_request *build_rename_request(
304 TALLOC_CTX *ctx,
305 struct ldb_context *ldb,
306 const char* old_dc,
307 const char* new_dc)
309 int ret = LDB_SUCCESS;
310 struct ldb_dn *old_dn = NULL;
311 struct ldb_dn *new_dn = NULL;
312 struct ldb_request *req = NULL;
314 old_dn = ldb_dn_new_fmt(ctx, ldb, "dc=%s", old_dc);
315 assert_non_null(old_dn);
317 new_dn = ldb_dn_new_fmt(ctx, ldb, "dc=%s", new_dc);
318 assert_non_null(new_dn);
320 ret = ldb_build_rename_req(
321 &req,
322 ldb,
323 ctx,
324 old_dn,
325 new_dn,
326 NULL,
327 NULL,
328 ldb_op_default_callback,
329 NULL);
330 assert_int_equal(ret, LDB_SUCCESS);
331 return req;
335 * Build a ldb modify request
337 static struct ldb_request *build_modify_request(
338 TALLOC_CTX *ctx,
339 struct ldb_context *ldb,
340 const char* dc,
341 const char* cn)
343 int ret;
344 struct ldb_message *msg;
345 struct ldb_request *req;
347 msg = ldb_msg_new(ctx);
348 assert_non_null(msg);
350 msg->dn = ldb_dn_new_fmt(msg, ldb, "dc=%s", dc);
351 assert_non_null(msg->dn);
353 ret = ldb_msg_add_empty(msg, "cn", LDB_FLAG_MOD_REPLACE, NULL);
354 assert_int_equal(ret, LDB_SUCCESS);
355 ret = ldb_msg_add_string(msg, "cn", cn);
356 assert_int_equal(ret, LDB_SUCCESS);
358 ret = ldb_msg_sanity_check(ldb, msg);
359 assert_int_equal(ret, LDB_SUCCESS);
361 ret = ldb_build_mod_req(
362 &req, ldb, ldb, msg, NULL, NULL, ldb_op_default_callback, NULL);
363 assert_int_equal(ret, LDB_SUCCESS);
364 return req;
368 * Delete a record from the database
370 static void delete_record(
371 TALLOC_CTX *ctx,
372 struct ldb_context *ldb,
373 const char* dc)
375 struct ldb_kv_context *ldb_kv_ctx = NULL;
376 struct ldb_dn *basedn = NULL;
377 struct ldb_result *result = NULL;
378 struct ldb_request *req = NULL;
379 int ret = LDB_SUCCESS;
381 req = build_delete_request(ctx, ldb, dc);
382 ldb_kv_ctx = build_ldb_kv_context(ctx, ldb->modules, req);
384 ret = ldb_transaction_start(ldb);
385 assert_int_equal(ret, LDB_SUCCESS);
387 cmocka_unit_test_fail_delete_internal_after = NO_FAILURE;
388 cmocka_unit_test_fail_modify_internal_after = NO_FAILURE;
389 ret = ldb_kv_delete(ldb_kv_ctx);
390 assert_int_equal(ret, LDB_SUCCESS);
391 TALLOC_FREE(ldb_kv_ctx);
392 TALLOC_FREE(req);
394 ret = ldb_transaction_commit(ldb);
395 assert_int_equal(ret, LDB_SUCCESS);
398 * Ensure that the record was actually deleted.
400 basedn = ldb_dn_new_fmt(ctx, ldb, "dc=%s", dc);
401 assert_non_null(basedn);
404 * DN search, indexed
406 ret = ldb_search(ldb, ctx, &result, basedn, LDB_SCOPE_BASE, NULL, NULL);
407 assert_int_equal(ret, LDB_SUCCESS);
408 assert_non_null(result);
409 assert_int_equal(result->count, 0);
410 TALLOC_FREE(basedn);
411 TALLOC_FREE(result);
415 * Add a record to the database
417 static void add_record(
418 TALLOC_CTX *ctx,
419 struct ldb_context *ldb,
420 const char* dc,
421 const char* uuid,
422 const char* cn)
425 struct ldb_request *req = NULL;
426 int ret = LDB_SUCCESS;
427 struct ldb_kv_context *ldb_kv_ctx = NULL;
428 struct ldb_dn *basedn = NULL;
429 struct ldb_result *result = NULL;
431 req = build_add_request(ctx, ldb, dc, uuid, cn);
433 ldb_req_set_location(req, "add_record");
435 assert_int_equal(ret, LDB_SUCCESS);
438 ldb_kv_ctx = build_ldb_kv_context(ctx, ldb->modules, req);
439 cmocka_unit_test_fail_add_internal_after = NO_FAILURE;
440 cmocka_unit_test_fail_modify_internal_after = NO_FAILURE;
442 ret = ldb_transaction_start(ldb);
443 assert_int_equal(ret, LDB_SUCCESS);
445 ret = ldb_kv_add(ldb_kv_ctx);
446 assert_int_equal(ret, LDB_SUCCESS);
447 TALLOC_FREE(ldb_kv_ctx);
448 TALLOC_FREE(req);
450 ret = ldb_transaction_commit(ldb);
451 assert_int_equal(ret, LDB_SUCCESS);
454 * Ensure that the record was actually written.
456 basedn = ldb_dn_new_fmt(ctx, ldb, "dc=%s", dc);
457 assert_non_null(basedn);
460 * DN search, indexed
462 ret = ldb_search(ldb, ctx, &result, basedn, LDB_SCOPE_BASE, NULL, NULL);
463 assert_int_equal(ret, LDB_SUCCESS);
464 assert_non_null(result);
465 assert_int_equal(result->count, 1);
466 TALLOC_FREE(result);
470 * CN search unindexed
472 ret = ldb_search(
473 ldb,
474 ctx,
475 &result,
476 basedn,
477 LDB_SCOPE_SUBTREE,
478 NULL,
479 "(cn=%s)",
480 cn);
481 assert_int_equal(ret, LDB_SUCCESS);
482 assert_non_null(result);
483 assert_int_equal(result->count, 1);
484 TALLOC_FREE(result);
485 TALLOC_FREE(basedn);
489 * Test that a failed add operation does not change the database.
491 static void test_add_failure(void **state)
493 int ret = LDB_SUCCESS;
494 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
495 struct test_ctx);
496 struct ldb_request *req = NULL;
497 struct ldb_dn *basedn = NULL;
498 struct ldb_result *result = NULL;
499 struct ldb_kv_context *ldb_kv_ctx = NULL;
501 TALLOC_CTX *tmp_ctx = talloc_new(test_ctx);
502 assert_non_null(tmp_ctx);
504 req = build_add_request(
505 tmp_ctx,
506 test_ctx->ldb,
507 "test_add_failure",
508 "0123456789abcdef",
509 "test_add_failure_value");
511 ldb_req_set_location(req, "test_add_failure");
513 ldb_kv_ctx = build_ldb_kv_context(tmp_ctx, test_ctx->ldb->modules, req);
514 cmocka_unit_test_fail_add_internal_after = 1;
516 ret = ldb_transaction_start(test_ctx->ldb);
517 assert_int_equal(ret, LDB_SUCCESS);
519 ret = ldb_kv_add(ldb_kv_ctx);
521 assert_int_equal(ret, FAILURE_LDB_ERR);
522 TALLOC_FREE(ldb_kv_ctx);
523 TALLOC_FREE(req);
527 * a search for "cn=test_add_failure_value" should fail
528 * as the transaction containing the operation should have been
529 * rolled back leaving the database consistent
531 * This should be an un-indexed search so the index caches won't be
532 * used.
534 basedn = ldb_dn_new_fmt(
535 tmp_ctx,
536 test_ctx->ldb,
537 "dc=%s",
538 "test_add_failure");
539 assert_non_null(basedn);
541 ret = ldb_search(
542 test_ctx->ldb, tmp_ctx,
543 &result,
544 basedn,
545 LDB_SCOPE_SUBTREE,
546 NULL,
547 "(cn=%s)",
548 "test_add_failure_value");
549 assert_int_equal(ret, LDB_SUCCESS);
550 assert_non_null(result);
551 assert_int_equal(result->count, 0);
552 TALLOC_FREE(basedn);
553 TALLOC_FREE(result);
555 ldb_transaction_cancel(test_ctx->ldb);
556 TALLOC_FREE(tmp_ctx);
561 * Test that a failed delete operation does not modify the database.
563 static void test_delete_failure(void **state)
565 int ret = LDB_SUCCESS;
566 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
567 struct test_ctx);
568 struct ldb_request *req = NULL;
569 struct ldb_dn *basedn = NULL;
570 struct ldb_result *result = NULL;
571 struct ldb_kv_context *ldb_kv_ctx = NULL;
573 TALLOC_CTX *tmp_ctx = talloc_new(test_ctx);
574 assert_non_null(tmp_ctx);
576 add_record(
577 tmp_ctx,
578 test_ctx->ldb,
579 "test_delete_failure",
580 "0123456789abcded",
581 "test_delete_failure_value");
583 req = build_delete_request(
584 tmp_ctx,
585 test_ctx->ldb,
586 "test_delete_failure");
588 ldb_kv_ctx = build_ldb_kv_context(tmp_ctx, test_ctx->ldb->modules, req);
589 cmocka_unit_test_fail_delete_internal_after = 1;
591 ret = ldb_transaction_start(test_ctx->ldb);
592 assert_int_equal(ret, LDB_SUCCESS);
594 ret = ldb_kv_delete(ldb_kv_ctx);
595 assert_int_equal(ret, FAILURE_LDB_ERR);
596 TALLOC_FREE(ldb_kv_ctx);
597 TALLOC_FREE(req);
600 * a search for "cn=test_add_failure_value" should succeed
601 * as the transaction containing the operation should have been
602 * rolled back leaving the database consistent
604 * This should be an un-indexed search so the index caches won't be
605 * used.
607 basedn = ldb_dn_new_fmt(
608 tmp_ctx,
609 test_ctx->ldb,
610 "dc=%s",
611 "test_delete_failure");
612 assert_non_null(basedn);
614 ret = ldb_search(
615 test_ctx->ldb, tmp_ctx,
616 &result,
617 basedn,
618 LDB_SCOPE_SUBTREE,
619 NULL,
620 "(cn=%s)",
621 "test_delete_failure_value");
622 assert_int_equal(ret, LDB_SUCCESS);
623 assert_non_null(result);
624 assert_int_equal(result->count, 1);
625 TALLOC_FREE(basedn);
626 TALLOC_FREE(result);
629 ldb_transaction_cancel(test_ctx->ldb);
630 delete_record(
631 tmp_ctx,
632 test_ctx->ldb,
633 "test_delete_failure");
634 TALLOC_FREE(tmp_ctx);
638 * Test that a failed rename operation dies not change the database
640 static void test_rename_failure(void **state)
642 int ret = LDB_SUCCESS;
643 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
644 struct test_ctx);
645 struct ldb_request *req = NULL;
646 struct ldb_dn *basedn = NULL;
647 struct ldb_result *result = NULL;
648 struct ldb_kv_context *ldb_kv_ctx = NULL;
650 TALLOC_CTX *tmp_ctx = talloc_new(test_ctx);
651 assert_non_null(tmp_ctx);
653 add_record(
654 tmp_ctx,
655 test_ctx->ldb,
656 "test_rename_failure",
657 "0123456789abcdec",
658 "test_rename_failure_value");
660 req = build_rename_request(
661 tmp_ctx,
662 test_ctx->ldb,
663 "test_rename_failure",
664 "test_rename_failure_renamed");
666 ldb_kv_ctx = build_ldb_kv_context(tmp_ctx, test_ctx->ldb->modules, req);
667 cmocka_unit_test_fail_rename_internal_after = 1;
669 ret = ldb_transaction_start(test_ctx->ldb);
670 assert_int_equal(ret, LDB_SUCCESS);
672 ret = ldb_kv_rename(ldb_kv_ctx);
673 assert_int_equal(ret, FAILURE_LDB_ERR);
674 TALLOC_FREE(ldb_kv_ctx);
675 TALLOC_FREE(req);
678 * The original record should be present
680 basedn = ldb_dn_new_fmt(
681 tmp_ctx,
682 test_ctx->ldb,
683 "dc=%s",
684 "test_rename_failure");
685 assert_non_null(basedn);
687 ret = ldb_search(
688 test_ctx->ldb, tmp_ctx,
689 &result,
690 basedn,
691 LDB_SCOPE_SUBTREE,
692 NULL,
693 "(cn=%s)",
694 "test_rename_failure_value");
695 assert_int_equal(ret, LDB_SUCCESS);
696 assert_non_null(result);
697 assert_int_equal(result->count, 1);
698 TALLOC_FREE(basedn);
699 TALLOC_FREE(result);
702 * And the renamed record should not be present
704 basedn = ldb_dn_new_fmt(
705 tmp_ctx,
706 test_ctx->ldb,
707 "dc=%s",
708 "test_rename_failure_renamed");
709 assert_non_null(basedn);
711 ret = ldb_search(
712 test_ctx->ldb, tmp_ctx,
713 &result,
714 basedn,
715 LDB_SCOPE_SUBTREE,
716 NULL,
717 "(cn=%s)",
718 "test_rename_failure_value");
719 assert_int_equal(ret, LDB_SUCCESS);
720 assert_non_null(result);
721 assert_int_equal(result->count, 0);
722 TALLOC_FREE(basedn);
723 TALLOC_FREE(result);
725 ldb_transaction_cancel(test_ctx->ldb);
726 delete_record(
727 tmp_ctx,
728 test_ctx->ldb,
729 "test_rename_failure");
730 TALLOC_FREE(tmp_ctx);
734 * Test that a failed modification operation does not change the database
736 static void test_modify_failure(void **state)
738 int ret = LDB_SUCCESS;
739 struct test_ctx *test_ctx = talloc_get_type_abort(*state,
740 struct test_ctx);
741 struct ldb_request *req = NULL;
742 struct ldb_dn *basedn = NULL;
743 struct ldb_result *result = NULL;
744 struct ldb_kv_context *ldb_kv_ctx = NULL;
746 TALLOC_CTX *tmp_ctx = talloc_new(test_ctx);
747 assert_non_null(tmp_ctx);
749 add_record(
750 tmp_ctx,
751 test_ctx->ldb,
752 "test_modify_failure",
753 "0123456789abcdeb",
754 "test_modify_failure_value");
756 req = build_modify_request(
757 tmp_ctx,
758 test_ctx->ldb,
759 "test_modify_failure",
760 "test_modify_failure_value_modified");
762 ldb_kv_ctx = build_ldb_kv_context(tmp_ctx, test_ctx->ldb->modules, req);
763 cmocka_unit_test_fail_modify_internal_after = 2;
765 ret = ldb_transaction_start(test_ctx->ldb);
766 assert_int_equal(ret, LDB_SUCCESS);
768 ret = ldb_kv_modify(ldb_kv_ctx);
769 assert_int_equal(ret, FAILURE_LDB_ERR);
770 TALLOC_FREE(ldb_kv_ctx);
771 TALLOC_FREE(req);
775 * The original value should be present
777 basedn = ldb_dn_new_fmt(
778 tmp_ctx,
779 test_ctx->ldb,
780 "dc=%s",
781 "test_modify_failure");
782 assert_non_null(basedn);
784 ret = ldb_search(
785 test_ctx->ldb, tmp_ctx,
786 &result,
787 basedn,
788 LDB_SCOPE_SUBTREE,
789 NULL,
790 "(cn=%s)",
791 "test_modify_failure_value");
792 assert_int_equal(ret, LDB_SUCCESS);
793 assert_non_null(result);
794 assert_int_equal(result->count, 1);
795 TALLOC_FREE(result);
798 * And the modified record should not be present
800 ret = ldb_search(
801 test_ctx->ldb, tmp_ctx,
802 &result,
803 basedn,
804 LDB_SCOPE_SUBTREE,
805 NULL,
806 "(cn=%s)",
807 "test_modify_failure_value_modified");
808 assert_int_equal(ret, LDB_SUCCESS);
809 assert_non_null(result);
810 assert_int_equal(result->count, 0);
811 TALLOC_FREE(basedn);
812 TALLOC_FREE(result);
814 ldb_transaction_cancel(test_ctx->ldb);
815 delete_record(
816 tmp_ctx,
817 test_ctx->ldb,
818 "test_modify_failure");
819 TALLOC_FREE(tmp_ctx);
822 int main(int argc, const char **argv)
824 const struct CMUnitTest tests[] = {
825 cmocka_unit_test_setup_teardown(
826 test_add_failure,
827 setup,
828 teardown),
829 cmocka_unit_test_setup_teardown(
830 test_delete_failure,
831 setup,
832 teardown),
833 cmocka_unit_test_setup_teardown(
834 test_rename_failure,
835 setup,
836 teardown),
837 cmocka_unit_test_setup_teardown(
838 test_modify_failure,
839 setup,
840 teardown),
843 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
845 return cmocka_run_group_tests(tests, NULL, NULL);