ldb_mdb/tests: test large index key value
authorGary Lockyer <gary@catalyst.net.nz>
Mon, 12 Mar 2018 19:14:09 +0000 (08:14 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 23 May 2018 00:27:12 +0000 (02:27 +0200)
Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/tests/ldb_lmdb_test.c

index f2b04ecd0d7c410890ac9f2cb88e3b85bbe79009..e8f8e4f8ab1a62270e62eb54d89424b057abb56c 100644 (file)
@@ -201,6 +201,46 @@ static void test_ldb_add_key_len_gt_max(void **state)
        talloc_free(tmp_ctx);
 }
 
+static void test_ldb_add_key_len_2x_gt_max(void **state)
+{
+       int ret;
+       int xs_size = 0;
+       struct ldb_message *msg;
+       struct ldbtest_ctx *test_ctx = talloc_get_type_abort(*state,
+                                                       struct ldbtest_ctx);
+       char *xs = NULL;
+       TALLOC_CTX *tmp_ctx;
+
+       tmp_ctx = talloc_new(test_ctx);
+       assert_non_null(tmp_ctx);
+
+       msg = ldb_msg_new(tmp_ctx);
+       assert_non_null(msg);
+
+       /*
+        * The zero terminator is part of the key if we were not in
+        * GUID mode
+        */
+
+       xs_size = 2 * LMDB_MAX_KEY_SIZE;
+       xs = talloc_zero_size(tmp_ctx, (xs_size + 1));
+       memset(xs, 'x', xs_size);
+
+       msg->dn = ldb_dn_new_fmt(msg, test_ctx->ldb, "dc=%s", xs);
+       assert_non_null(msg->dn);
+
+       ret = ldb_msg_add_string(msg, "cn", "test_cn_val");
+       assert_int_equal(ret, 0);
+
+       ret = ldb_msg_add_string(msg, "objectUUID", "0123456789abcdef");
+       assert_int_equal(ret, 0);
+
+       ret = ldb_add(test_ctx->ldb, msg);
+       assert_int_equal(ret, LDB_SUCCESS);
+
+       talloc_free(tmp_ctx);
+}
+
 static void test_ldb_add_key_len_eq_max(void **state)
 {
        int ret;
@@ -443,6 +483,10 @@ int main(int argc, const char **argv)
                        test_ldb_add_key_len_gt_max,
                        ldbtest_setup,
                        ldbtest_teardown),
+               cmocka_unit_test_setup_teardown(
+                       test_ldb_add_key_len_2x_gt_max,
+                       ldbtest_setup,
+                       ldbtest_teardown),
                cmocka_unit_test_setup_teardown(
                        test_ldb_add_special_key_len_eq_max,
                        ldbtest_setup_noguid,