ldb: test for parse errors
authorAaron Haslett <aaronhaslett@catalyst.net.nz>
Tue, 28 May 2019 05:22:10 +0000 (17:22 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 29 May 2019 04:41:24 +0000 (04:41 +0000)
Parse errors aren't passed up correctly by the tdb backend. This
patch modifies a test to expose the issue, next patch will fix it.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13959

Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/tests/ldb_kv_ops_test.c

index c16297e136b1ab2c188d528bff683ae989b365e4..ab9d75bc69c0610a90a72886e7f5e84442844b06 100644 (file)
@@ -206,6 +206,17 @@ static int parse(struct ldb_val key,
        return LDB_SUCCESS;
 }
 
+/*
+ * Parse function that just returns the int we pass it.
+ */
+static int parse_return(struct ldb_val key,
+                       struct ldb_val data,
+                       void *private_data)
+{
+       int *rcode = private_data;
+       return *rcode;
+}
+
 /*
  * Test that data can be written to the kv store and be read back.
  */
@@ -228,6 +239,7 @@ static void test_add_get(void **state)
        };
 
        struct ldb_val read;
+       int rcode;
 
        int flags = 0;
        TALLOC_CTX *tmp_ctx;
@@ -265,6 +277,17 @@ static void test_add_get(void **state)
        assert_int_equal(sizeof(value), read.length);
        assert_memory_equal(value, read.data, sizeof(value));
 
+       /*
+        * Now check that the error code we return in the
+        * parse function is returned by fetch_and_parse.
+        */
+       for (rcode=0; rcode<50; rcode++) {
+               ret = ldb_kv->kv_ops->fetch_and_parse(ldb_kv, key,
+                                                     parse_return,
+                                                     &rcode);
+               assert_int_equal(ret, rcode);
+       }
+
        ret = ldb_kv->kv_ops->unlock_read(test_ctx->ldb->modules);
        assert_int_equal(ret, 0);
        talloc_free(tmp_ctx);