1--TEST-- 2ldap_modify_batch() - ValueErrors and TypeErrors 3--EXTENSIONS-- 4ldap 5--FILE-- 6<?php 7 8/* We are assuming 3333 is not connectable */ 9$ldap = ldap_connect('ldap://127.0.0.1:3333'); 10 11$valid_dn = "cn=userA,something"; 12 13$dn = "dn_with\0nul_byte"; 14try { 15 var_dump(ldap_modify_batch($ldap, $dn, [])); 16} catch (Throwable $e) { 17 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 18} 19 20$empty_list = []; 21try { 22 var_dump(ldap_modify_batch($ldap, $valid_dn, $empty_list)); 23} catch (Throwable $e) { 24 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 25} 26 27$not_list1 = [ 28 'entry1' => [], 29 'entry2' => [], 30]; 31try { 32 var_dump(ldap_modify_batch($ldap, $valid_dn, $not_list1)); 33} catch (Throwable $e) { 34 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 35} 36 37$not_list2 = [ 38 [ 39 "attrib" => "attrib1", 40 "modtype" => LDAP_MODIFY_BATCH_ADD, 41 "values" => ["value1"], 42 ], 43 2 => [], 44]; 45try { 46 var_dump(ldap_modify_batch($ldap, $valid_dn, $not_list2)); 47} catch (Throwable $e) { 48 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 49} 50 51 52$not_list_of_arrays = [ 53 [ 54 "attrib" => "attrib1", 55 "modtype" => LDAP_MODIFY_BATCH_ADD, 56 "values" => ["value1"], 57 ], 58 'not an array', 59]; 60try { 61 var_dump(ldap_modify_batch($ldap, $valid_dn, $not_list_of_arrays)); 62} catch (Throwable $e) { 63 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 64} 65 66$modifications_not_all_dicts = [ 67 [ 68 "attrib" => "attrib1", 69 "modtype" => LDAP_MODIFY_BATCH_ADD, 70 "values" => ["value1"], 71 ], 72 [ 73 "attrib" => "attrib2", 74 "modtype" => LDAP_MODIFY_BATCH_REMOVE_ALL, 75 4 => ["value2"], 76 ], 77 [ 78 "attrib" => "attrib3", 79 "modtype" => LDAP_MODIFY_BATCH_ADD, 80 "values" => ["value3"], 81 ], 82]; 83try { 84 var_dump(ldap_modify_batch($ldap, $valid_dn, $modifications_not_all_dicts)); 85} catch (Throwable $e) { 86 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 87} 88 89$modification_has_invalid_key = [ 90 [ 91 "attrib" => "attrib1", 92 "modtype" => LDAP_MODIFY_BATCH_ADD, 93 "values" => ["value1"], 94 "random" => "what", 95 ], 96]; 97try { 98 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_has_invalid_key)); 99} catch (Throwable $e) { 100 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 101} 102 103$modification_attrib_not_string = [ 104 [ 105 "attrib" => 25, 106 "modtype" => LDAP_MODIFY_BATCH_ADD, 107 "values" => ["value1"], 108 ], 109]; 110try { 111 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_attrib_not_string)); 112} catch (Throwable $e) { 113 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 114} 115 116$modification_attrib_has_nul_byte = [ 117 [ 118 "attrib" => "attrib\0with\0nul\0byte", 119 "modtype" => LDAP_MODIFY_BATCH_ADD, 120 "values" => ["value1"], 121 ], 122]; 123try { 124 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_attrib_has_nul_byte)); 125} catch (Throwable $e) { 126 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 127} 128 129$modification_modtype_not_int = [ 130 [ 131 "attrib" => "attrib1", 132 "modtype" => new stdClass(), 133 "values" => ["value1"], 134 ], 135]; 136try { 137 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_modtype_not_int)); 138} catch (Throwable $e) { 139 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 140} 141 142$modification_modtype_invalid_value = [ 143 [ 144 "attrib" => "attrib1", 145 "modtype" => 42, 146 "values" => ["value1"], 147 ], 148]; 149try { 150 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_modtype_invalid_value)); 151} catch (Throwable $e) { 152 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 153} 154 155$modification_modtype_remove_all_with_values_key = [ 156 [ 157 "attrib" => "attrib1", 158 "modtype" => LDAP_MODIFY_BATCH_REMOVE_ALL, 159 "values" => ["value1"], 160 ], 161]; 162try { 163 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_modtype_remove_all_with_values_key)); 164} catch (Throwable $e) { 165 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 166} 167 168$modification_modtype_not_remove_all_without_values_key = [ 169 [ 170 "attrib" => "attrib1", 171 "modtype" => LDAP_MODIFY_BATCH_ADD, 172 ], 173]; 174try { 175 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_modtype_not_remove_all_without_values_key)); 176} catch (Throwable $e) { 177 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 178} 179 180$modification_values_invalid_value = [ 181 [ 182 "attrib" => "attrib1", 183 "modtype" => LDAP_MODIFY_BATCH_ADD, 184 "values" => "value1", 185 ], 186]; 187try { 188 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_values_invalid_value)); 189} catch (Throwable $e) { 190 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 191} 192 193$modification_values_empty_array = [ 194 [ 195 "attrib" => "attrib1", 196 "modtype" => LDAP_MODIFY_BATCH_ADD, 197 "values" => [], 198 ], 199]; 200try { 201 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_values_empty_array)); 202} catch (Throwable $e) { 203 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 204} 205 206$modification_values_not_list1 = [ 207 [ 208 "attrib" => "attrib1", 209 "modtype" => LDAP_MODIFY_BATCH_ADD, 210 "values" => $not_list1, 211 ], 212]; 213try { 214 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_values_not_list1)); 215} catch (Throwable $e) { 216 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 217} 218 219$modification_values_not_list2 = [ 220 [ 221 "attrib" => "attrib1", 222 "modtype" => LDAP_MODIFY_BATCH_ADD, 223 "values" => $not_list2, 224 ], 225]; 226try { 227 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_values_not_list2)); 228} catch (Throwable $e) { 229 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 230} 231 232$modification_missing_attrib_key = [ 233 [ 234 "modtype" => LDAP_MODIFY_BATCH_ADD, 235 "values" => ["value1"], 236 ], 237]; 238try { 239 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_missing_attrib_key)); 240} catch (Throwable $e) { 241 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 242} 243 244$modification_missing_modtype_key = [ 245 [ 246 "attrib" => "attrib1", 247 "values" => ["value1"], 248 ], 249]; 250try { 251 var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_missing_modtype_key)); 252} catch (Throwable $e) { 253 echo $e::class, ': ', $e->getMessage(), PHP_EOL; 254} 255 256?> 257--EXPECT-- 258ValueError: ldap_modify_batch(): Argument #2 ($dn) must not contain any null bytes 259ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) must not be empty 260ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) must be a list 261ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) must be a list 262TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) must only contain arrays 263ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must not contain the "values" option when option "modtype" is LDAP_MODIFY_BATCH_REMOVE_ALL 264ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must only contain the keys "attrib", "modtype", and "values" 265TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "attrib" must be of type string, int given 266ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "attrib" must not contain null bytes 267TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be of type int, string given 268ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "modtype" must be LDAP_MODIFY_BATCH_ADD, LDAP_MODIFY_BATCH_REMOVE, LDAP_MODIFY_BATCH_REPLACE, or LDAP_MODIFY_BATCH_REMOVE_ALL 269ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must not contain the "values" option when option "modtype" is LDAP_MODIFY_BATCH_REMOVE_ALL 270ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must contain the "values" option when the "modtype" option is not LDAP_MODIFY_BATCH_REMOVE_ALL 271TypeError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be of type array, string given 272ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must not be empty 273ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be a list 274ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) the value for option "values" must be a list 275ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must contain the "attrib" option 276ValueError: ldap_modify_batch(): Argument #3 ($modifications_info) a modification entry must contain the "modtype" option 277