summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2019-08-27 13:16:50 +1200
committerKarolin Seeger <kseeger@samba.org>2019-09-04 08:31:25 +0000
commit9392ee7d29081118afd2dfd531946cbdcaba729d (patch)
tree3ccb5d78141b69bb64b8399a2aae02468da3edc9 /lib
parente019f3a6aac62460ee9768fec4001e00f00f8096 (diff)
downloadsamba-9392ee7d29081118afd2dfd531946cbdcaba729d.tar.gz
ldb: Extend the ldb_dn_explode test matrix
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14049 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> (cherry picked from commit 10058bcfa16d5029e61252d64d142a8aab9ec296)
Diffstat (limited to 'lib')
-rw-r--r--lib/ldb/tests/test_ldb_dn.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/lib/ldb/tests/test_ldb_dn.c b/lib/ldb/tests/test_ldb_dn.c
index 7c202399a21..05f30e4ac67 100644
--- a/lib/ldb/tests/test_ldb_dn.c
+++ b/lib/ldb/tests/test_ldb_dn.c
@@ -113,10 +113,42 @@ struct explode_test {
bool special;
bool invalid;
const char *linearized;
- const char *ext_linearized;
+ const char *ext_linearized_1;
bool explode_result;
};
+static int extended_dn_read_ID(struct ldb_context *ldb, void *mem_ctx,
+ const struct ldb_val *in, struct ldb_val *out)
+{
+
+ /* Allow to check we can cope with validity checks */
+ if (in->length != 4) {
+ return -1;
+ }
+
+ *out = *in;
+ out->data = talloc_memdup(mem_ctx, in->data, in->length);
+ if (out->data == NULL) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/* write out (resued for both HEX and clear for now) */
+static int extended_dn_write_ID(struct ldb_context *ldb, void *mem_ctx,
+ const struct ldb_val *in, struct ldb_val *out)
+{
+ *out = *in;
+
+ out->data = talloc_memdup(mem_ctx, in->data, in->length);
+ if (out->data == NULL) {
+ return -1;
+ }
+ return 0;
+}
+
+
static void test_ldb_dn_explode(void **state)
{
size_t i;
@@ -130,9 +162,22 @@ static void test_ldb_dn_explode(void **state)
{"<><", 0, 0, false, false, "", NULL, true},
{"<><>", 0, 0, false, false, "", NULL, true},
{"A=B,C=D", 2, 0, false, false, "A=B,C=D", "A=B,C=D", true},
+ {"<X=Y>A=B,C=D", -1, -1, false, false, "", NULL, false},
+ {"<X=Y>;A=B,C=D", -1, -1, false, false, "A=B,C=D", NULL, false},
+ {"<ID=ABC>;A=B,C=D", -1, -1, false, true, "A=B,C=D", NULL, false},
+ {"<ID=ABCD>;A=B,C=D", 2, 1, false, false, "A=B,C=D", "<ID=ABCD>;A=B,C=D", true},
{"x=🔥", 1, 0, false, false, "x=🔥", "x=🔥", true},
+ {"@FOO", 0, 0, true, false, "@FOO", "@FOO", true},
+ };
+
+ struct ldb_dn_extended_syntax syntax = {
+ .name = "ID",
+ .read_fn = extended_dn_read_ID,
+ .write_clear_fn = extended_dn_write_ID,
+ .write_hex_fn = extended_dn_write_ID
};
+ ldb_dn_extended_add_syntax(ldb, 0, &syntax);
for (i = 0; i < ARRAY_SIZE(tests); i++) {
bool result;
@@ -152,11 +197,11 @@ static void test_ldb_dn_explode(void **state)
ext_linear = ldb_dn_get_extended_linearized(ldb, dn, 1);
assert_true((ext_linear == NULL) ==
- (tests[i].ext_linearized == NULL));
+ (tests[i].ext_linearized_1 == NULL));
- if (tests[i].ext_linearized != NULL) {
+ if (tests[i].ext_linearized_1 != NULL) {
assert_string_equal(ext_linear,
- tests[i].ext_linearized);
+ tests[i].ext_linearized_1);
}
assert_true(ldb_dn_is_special(dn) == tests[i].special);
assert_true(ldb_dn_is_valid(dn) != tests[i].invalid);