php-src/ext/ldap/tests/ldap_get_option_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

112 lines
2.6 KiB
PHP

--TEST--
ldap_get_option() and ldap_set_option() tests related to ldap controls
--CREDITS--
Côme Chilliet <mcmic@php.net>
--EXTENSIONS--
ldap
--SKIPIF--
<?php
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
insert_dummy_data($link, $base);
function build_ctrl_paged_value($int, $cookie)
{
// This is basic and will only work for small values
$hex = '';
if (!empty($int)) {
$str = sprintf("%'.02x", $int);
$hex .= '02'.sprintf("%'.02x%s", strlen($str)/2, $str);
}
$hex .= '04'.sprintf("%'.02x", strlen($cookie)).bin2hex($cookie);
return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
}
$controls_set = array(
array(
'oid' => LDAP_CONTROL_PAGEDRESULTS,
'iscritical' => TRUE,
'value' => build_ctrl_paged_value(1, 'opaque')
)
);
$controls_set2 = array(
array(
'oid' => LDAP_CONTROL_PAGEDRESULTS,
'iscritical' => TRUE,
'value' => array(
'size' => 1,
'cookie' => '',
)
)
);
var_dump(
bin2hex($controls_set[0]['value']),
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set),
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
$controls_get,
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set2),
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
$controls_get,
$result = ldap_search($link, $base, "(objectClass=person)", array('cn')),
ldap_get_entries($link, $result)['count'],
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array()),
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get)
);
?>
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
remove_dummy_data($link, $base);
?>
--EXPECTF--
string(26) "300b02010104066f7061717565"
bool(false)
bool(true)
bool(true)
array(1) {
["1.2.840.113556.1.4.319"]=>
array(3) {
["oid"]=>
string(22) "1.2.840.113556.1.4.319"
["iscritical"]=>
bool(true)
["value"]=>
array(2) {
["size"]=>
int(1)
["cookie"]=>
string(6) "opaque"
}
}
}
bool(true)
bool(true)
array(1) {
["1.2.840.113556.1.4.319"]=>
array(3) {
["oid"]=>
string(22) "1.2.840.113556.1.4.319"
["iscritical"]=>
bool(true)
["value"]=>
array(2) {
["size"]=>
int(1)
["cookie"]=>
string(0) ""
}
}
}
object(LDAP\Result)#%d (0) {
}
int(1)
bool(true)
bool(false)