1--TEST--
2Programming errors (Value/Type errors) for ldap_list(), ldap_read(), and ldap_search()
3--EXTENSIONS--
4ldap
5--FILE--
6<?php
7
8/* ldap_list(), ldap_read(), and ldap_search() share an underlying C function */
9/* We are assuming 3333 is not connectable */
10$ldap = ldap_connect('ldap://127.0.0.1:3333');
11$valid_dn = "cn=userA,something";
12$valid_filter = "";
13
14try {
15    var_dump(ldap_list(42, $valid_dn, $valid_filter));
16} catch (Throwable $e) {
17    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
18}
19
20try {
21    var_dump(ldap_list($ldap, [$valid_dn], $valid_filter));
22} catch (Throwable $e) {
23    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
24}
25
26try {
27    var_dump(ldap_list($ldap, $valid_dn, [$valid_filter]));
28} catch (Throwable $e) {
29    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
30}
31
32$not_list = [
33    "attrib1",
34    "wat" => "attrib2",
35    "attrib3",
36];
37try {
38    var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $not_list));
39} catch (Throwable $e) {
40    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
41}
42
43$not_list_of_strings = [
44    "attrib1",
45    42,
46    "attrib3",
47];
48try {
49    var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $not_list_of_strings));
50} catch (Throwable $e) {
51    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
52}
53
54$list_of_strings_with_null_byte = [
55    "attrib1",
56    "attrib_with\0nul_byte",
57    "attrib3",
58];
59try {
60    var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $list_of_strings_with_null_byte));
61} catch (Throwable $e) {
62    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
63}
64
65$str = "attrib_with\0nul_byte";
66
67$list_with_ref_nul_byte = [
68    "attrib1",
69    &$str,
70    "attrib3",
71];
72try {
73    var_dump(ldap_list($ldap, $valid_dn, $valid_filter, $list_with_ref_nul_byte));
74} catch (Throwable $e) {
75    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
76}
77
78?>
79--EXPECT--
80TypeError: ldap_list(): Argument #1 ($ldap) must be of type LDAP\Connection|array, int given
81TypeError: ldap_list(): Argument #2 ($base) must be of type string when argument #1 ($ldap) is an LDAP\Connection instance
82TypeError: ldap_list(): Argument #3 ($filter) must be of type string when argument #1 ($ldap) is an LDAP\Connection instance
83ValueError: ldap_list(): Argument #4 ($attributes) must be a list
84TypeError: ldap_list(): Argument #4 ($attributes) must be a list of strings, int given
85ValueError: ldap_list(): Argument #4 ($attributes) must not contain strings with any null bytes
86ValueError: ldap_list(): Argument #4 ($attributes) must not contain strings with any null bytes
87