From: Volker Lendecke Date: Tue, 23 Jun 2020 17:14:37 +0000 (+0200) Subject: libcli/ldap: Test decoding an exop response X-Git-Tag: talloc-2.3.2~1129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60b0928945c9be3785b5e2855b066f9f97beb2df;p=thirdparty%2Fsamba.git libcli/ldap: Test decoding an exop response 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 Reviewed-by: Stefan Metzmacher --- diff --git a/libcli/ldap/tests/data/ldap-starttls-response.dat b/libcli/ldap/tests/data/ldap-starttls-response.dat new file mode 100644 index 00000000000..d4294bf9173 Binary files /dev/null and b/libcli/ldap/tests/data/ldap-starttls-response.dat differ diff --git a/libcli/ldap/tests/ldap_message_test.c b/libcli/ldap/tests/ldap_message_test.c index f4b49bc47bc..53636828f93 100644 --- a/libcli/ldap/tests/ldap_message_test.c +++ b/libcli/ldap/tests/ldap_message_test.c @@ -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 index 00000000000..ee41af082c7 --- /dev/null +++ b/selftest/knownfail.d/ldap-exop @@ -0,0 +1 @@ +libcli.ldap.ldap_message.test_decode_exop_response\(none\)