php-src/ext/ldap/tests/ldap_controls.phpt
Andreas Heigl 69a8b63ecf
Deprecate ldap_connect with two parameters (#5177)
* Deprecate ldap_connect with two parameters

ldap_connect should be called with an LDAP-URI as parameter and not with
2 parameters as that allows much more flexibility like differentiating
between ldap and ldaps or setting multiple ldap-servers.

This change requires one to add null as second parameter in case the
underlying library is Oracle and one wants to add wallet-details.

* Modify all ldap-tests to use ldap_connect right

All tests are using ldap_connect now with an URI and not with host and
port as two separarte parameters.

* Verify deprecation of ldap_connect w/h 2 params

This adds a test to verify that calling ldap_connect with 2 parameters
triggers a deprecation notice

* Remove empty test

`ldap_control_paged_result()` is removed as of PHP 8.0.0, so this test
needs to be removed as well.

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
2023-07-10 10:44:01 +01:00

166 lines
4.4 KiB
PHP

--TEST--
Test the use of controls
--CREDITS--
Côme Chilliet <mcmic@php.net>
--EXTENSIONS--
ldap
--SKIPIF--
<?php
require_once('skipifbindfailure.inc');
require_once('skipifcontrol.inc');
skipifunsupportedcontrol(LDAP_CONTROL_ASSERT);
skipifunsupportedcontrol(LDAP_CONTROL_VALUESRETURNFILTER);
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
insert_dummy_data($link, $base);
/* Test assertion control */
var_dump(
$result = ldap_search($link, "o=test,$base", "objectClass=*", array('o'), 0, 0, 0, LDAP_DEREF_NEVER,
[['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(objectClass=organization)']]]),
ldap_get_entries($link, $result),
$result = ldap_search($link, "o=test,$base", "objectClass=*", array('o'), 0, 0, 0, LDAP_DEREF_NEVER,
[['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(objectClass=organizationalUnit)']]]),
ldap_modify($link, "o=test,$base", ['description' => 'desc'],
[['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(!(description=*))']]]),
$result = ldap_read($link, "o=test,$base", "objectClass=*", array('description')),
ldap_get_entries($link, $result),
ldap_modify($link, "o=test,$base", ['description' => 'desc2'],
[['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(!(description=*))']]]),
$result = ldap_read($link, "o=test,$base", "objectClass=*", array('description')),
ldap_get_entries($link, $result),
ldap_delete($link, "o=test,$base", [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]]),
ldap_errno($link),
ldap_error($link),
ldap_rename($link, "o=test,$base", "o=test2", "", TRUE, [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]]),
ldap_compare($link, "o=test,$base", "o", "test"),
ldap_compare($link, "o=test,$base", "o", "test", [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]]),
ldap_compare($link, "o=test,$base", "o", "test", [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc)']]])
);
/* Test valuesreturnfilter control */
var_dump(
$result = ldap_read($link, "o=test2,$base", "objectClass=*", ["l"]),
ldap_get_entries($link, $result)[0]['l'],
$result = ldap_read($link, "o=test2,$base", "objectClass=*", ["l"], 0, 0, 0, LDAP_DEREF_NEVER,
[['oid' => LDAP_CONTROL_VALUESRETURNFILTER, 'iscritical' => TRUE, 'value' => ['filter' => '(l=*here)']]]),
ldap_get_entries($link, $result)[0]['l']
);
?>
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
remove_dummy_data($link, $base);
?>
--EXPECTF--
Warning: ldap_search(): Search: Assertion Failed in %s on line %d
Warning: ldap_modify(): Modify: Assertion Failed in %s on line %d
Warning: ldap_delete(): Delete: Assertion Failed in %s on line %d
Warning: ldap_compare(): Compare: Assertion Failed in %s on line %d
object(LDAP\Result)#%d (0) {
}
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["o"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(4) "test"
}
[0]=>
string(1) "o"
["count"]=>
int(1)
["dn"]=>
string(%d) "o=test,%s"
}
}
bool(false)
bool(true)
object(LDAP\Result)#%d (0) {
}
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(4) "desc"
}
[0]=>
string(11) "description"
["count"]=>
int(1)
["dn"]=>
string(%d) "o=test,%s"
}
}
bool(false)
object(LDAP\Result)#%d (0) {
}
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(4) "desc"
}
[0]=>
string(11) "description"
["count"]=>
int(1)
["dn"]=>
string(%d) "o=test,%s"
}
}
bool(false)
int(122)
string(16) "Assertion Failed"
bool(false)
bool(true)
int(-1)
bool(true)
object(LDAP\Result)#%d (0) {
}
array(4) {
["count"]=>
int(3)
[0]=>
string(4) "here"
[1]=>
string(5) "there"
[2]=>
string(10) "Antarctica"
}
object(LDAP\Result)#%d (0) {
}
array(3) {
["count"]=>
int(2)
[0]=>
string(4) "here"
[1]=>
string(5) "there"
}