]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli/ldap: Test decoding an exop response
authorVolker Lendecke <vl@samba.org>
Tue, 23 Jun 2020 17:14:37 +0000 (19:14 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 9 Jul 2020 20:16:40 +0000 (20:16 +0000)
ldap-starttls-response.dat is a reply to a starttls extended
operation. Right now ldap_decode() does not handle this correctly.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
libcli/ldap/tests/data/ldap-starttls-response.dat [new file with mode: 0644]
libcli/ldap/tests/ldap_message_test.c
selftest/knownfail.d/ldap-exop [new file with mode: 0644]

diff --git a/libcli/ldap/tests/data/ldap-starttls-response.dat b/libcli/ldap/tests/data/ldap-starttls-response.dat
new file mode 100644 (file)
index 0000000..d4294bf
Binary files /dev/null and b/libcli/ldap/tests/data/ldap-starttls-response.dat differ
index f4b49bc47bcbe8c666e4880dabb81785cba46a4e..53636828f934da7083bc182e810fd24ca253cd99 100644 (file)
@@ -261,6 +261,45 @@ static void test_recursion_depth_greater_than_max(void **state)
        assert_ldap_status_equal(LDAP_PROTOCOL_ERROR, status);
 }
 
+/*
+ * Check we can decode an exop response
+ */
+static void test_decode_exop_response(void **state)
+{
+       struct test_ctx *test_ctx = talloc_get_type_abort(
+               *state,
+               struct test_ctx);
+       struct asn1_data *asn1;
+       struct ldap_message *ldap_msg;
+       NTSTATUS status;
+       FILE *f = NULL;
+       uint8_t *buffer = NULL;
+       const size_t BUFF_SIZE = 1048576;
+       size_t len;
+       struct ldap_request_limits limits = {
+               .max_search_size = 256000,
+       };
+
+
+       buffer = talloc_zero_array(test_ctx, uint8_t, BUFF_SIZE);
+       f = fopen("./libcli/ldap/tests/data/ldap-starttls-response.dat", "r");
+       assert_not_ferror(f);
+       len = fread(buffer, sizeof(uint8_t), BUFF_SIZE, f);
+       assert_not_ferror(f);
+       assert_true(len > 0);
+
+       asn1 = asn1_init(test_ctx, 3);
+       assert_non_null(asn1);
+       asn1_load_nocopy(asn1, buffer, len);
+
+       ldap_msg = talloc(test_ctx, struct ldap_message);
+       assert_non_null(ldap_msg);
+
+       status = ldap_decode(
+               asn1, &limits, samba_ldap_control_handlers(), ldap_msg);
+       assert_true(NT_STATUS_IS_OK(status));
+}
+
 int main(_UNUSED_ int argc, _UNUSED_ const char **argv)
 {
        const struct CMUnitTest tests[] = {
@@ -280,6 +319,10 @@ int main(_UNUSED_ int argc, _UNUSED_ const char **argv)
                        test_recursion_depth_greater_than_max,
                        setup,
                        teardown),
+               cmocka_unit_test_setup_teardown(
+                       test_decode_exop_response,
+                       setup,
+                       teardown),
        };
 
        cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
diff --git a/selftest/knownfail.d/ldap-exop b/selftest/knownfail.d/ldap-exop
new file mode 100644 (file)
index 0000000..ee41af0
--- /dev/null
@@ -0,0 +1 @@
+libcli.ldap.ldap_message.test_decode_exop_response\(none\)