From 10058bcfa16d5029e61252d64d142a8aab9ec296 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 27 Aug 2019 13:16:50 +1200 Subject: [PATCH] ldb: Extend the ldb_dn_explode test matrix BUG: https://bugzilla.samba.org/show_bug.cgi?id=14049 Signed-off-by: Andrew Bartlett Reviewed-by: Gary Lockyer --- lib/ldb/tests/test_ldb_dn.c | 53 ++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/lib/ldb/tests/test_ldb_dn.c b/lib/ldb/tests/test_ldb_dn.c index d8ea65d08989..109ee53c8ab6 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}, + {"A=B,C=D", -1, -1, false, false, "", NULL, false}, + {";A=B,C=D", -1, -1, false, false, "A=B,C=D", NULL, false}, + {";A=B,C=D", -1, -1, false, true, "A=B,C=D", NULL, false}, + {";A=B,C=D", 2, 1, false, false, "A=B,C=D", ";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);