diff options
author | Volker Lendecke <vl@samba.org> | 2020-06-23 19:14:37 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2020-07-09 20:16:40 +0000 |
commit | 60b0928945c9be3785b5e2855b066f9f97beb2df (patch) | |
tree | c403af6220b78995e9a3ba7e9b9397cd7e34a7a3 /libcli | |
parent | 92b1078e1e0ff89e190e9ee9941de778f7bc6d27 (diff) | |
download | samba-60b0928945c9be3785b5e2855b066f9f97beb2df.tar.gz |
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 <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'libcli')
-rw-r--r-- | libcli/ldap/tests/data/ldap-starttls-response.dat | bin | 0 -> 38 bytes | |||
-rw-r--r-- | libcli/ldap/tests/ldap_message_test.c | 43 |
2 files changed, 43 insertions, 0 deletions
diff --git a/libcli/ldap/tests/data/ldap-starttls-response.dat b/libcli/ldap/tests/data/ldap-starttls-response.dat Binary files differnew file mode 100644 index 00000000000..d4294bf9173 --- /dev/null +++ b/libcli/ldap/tests/data/ldap-starttls-response.dat 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); |