MFH: Tests for ext/ldap from PHPBelgium TestFest

This commit is contained in:
Patrick Allaert 2009-07-03 09:21:31 +00:00
parent f31fc6df21
commit 17aa260703
88 changed files with 4653 additions and 0 deletions

53
ext/ldap/tests/README Normal file
View File

@ -0,0 +1,53 @@
Most tests here relies on the availability of an LDAP server configured with TLS.
Client/Server configuration:
===========================================================
OpenLDAP 2.3.43 has been used with the configuration below.
Notes:
1. A self signed certificate can be generated using:
$ openssl req -newkey rsa:1024 -x509 -nodes -out server.pem -keyout server.pem -days 3650
It is used for testing ldap_start_tls(), which also requires "TLS_REQCERT never" in client configuration
2. An empty LDAP structure is required for the tests to be PASSed
(/etc/openldap/)slapd.conf:
-----------------------------------------------------------
TLSCACertificateFile /etc/openldap/ssl/server.pem
TLSCertificateFile /etc/openldap/ssl/server.pem
TLSCertificateKeyFile /etc/openldap/ssl/server.pem
TLSVerifyClient never
# hdb is used instead of bdb as it enables the usage of referrals & aliases
database hdb
suffix "dc=my-domain,dc=com"
checkpoint 32 30
rootdn "cn=Manager,dc=my-domain,dc=com"
rootpw secret
directory /var/lib/openldap-data
index objectClass eq
authz-regexp
uid=Manager,cn=digest-md5,cn=auth
cn=Manager,dc=my-domain,dc=com
(/etc/openldap/)ldap.conf:
-----------------------------------------------------------
TLS_REQCERT never
Tests configuration:
===========================================================
The following environment variables may be defined:
LDAP_TEST_HOST (default: localhost) Host to connect to
LDAP_TEST_PORT (default: 389) Port to connect to
LDAP_TEST_USER (default: cn=Manager,dc=my-domain,dc=com) DN used for binding
LDAP_TEST_SASL_USER (default: Manager) SASL user used for SASL binding
LDAP_TEST_PASSWD (default: secret) Password used for plain and SASL binding
LDAP_TEST_OPT_PROTOCOL_VERSION (default: 3) Version of LDAP protocol to use
LDAP_TEST_SKIP_BIND_FAILURE (default: true) Whether to fail the test or not in case binding fails
Credits:
===========================================================
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrick.allaert@gmail.com>

View File

@ -0,0 +1,83 @@
--TEST--
ldap_add() - Basic add operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
var_dump(
ldap_add($link, "dc=my-domain,dc=com", array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
)),
ldap_get_entries(
$link,
ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,dc=com");
?>
--EXPECT--
bool(true)
array(2) {
["count"]=>
int(1)
[0]=>
array(8) {
["objectclass"]=>
array(4) {
["count"]=>
int(3)
[0]=>
string(3) "top"
[1]=>
string(8) "dcObject"
[2]=>
string(12) "organization"
}
[0]=>
string(11) "objectclass"
["dc"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[1]=>
string(2) "dc"
["o"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[2]=>
string(1) "o"
["count"]=>
int(3)
["dn"]=>
string(19) "dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,136 @@
--TEST--
ldap_add() - Add operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Too few parameters
var_dump(ldap_add());
var_dump(ldap_add($link));
var_dump(ldap_add($link, "dc=my-domain,dc=com"));
// Too many parameters
var_dump(ldap_add($link, "dc=my-domain,dc=com", array(), "Additional data"));
var_dump(ldap_add($link, "dc=my-domain,dc=com", array()));
// Invalid DN
var_dump(
ldap_add($link, "weirdAttribute=val", array(
"weirdAttribute" => "val",
)),
ldap_error($link),
ldap_errno($link)
);
// Duplicate entry
for ($i = 0; $i < 2; $i++)
var_dump(
ldap_add($link, "dc=my-domain,dc=com", array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
))
);
var_dump(ldap_error($link), ldap_errno($link));
// Wrong array indexes
var_dump(
ldap_add($link, "dc=my-domain2,dc=com", array(
"objectClass" => array(
0 => "top",
2 => "dcObject",
5 => "organization"),
"dc" => "my-domain",
"o" => "my-domain",
))
/* Is this correct behaviour to still have "Already exists" as error/errno?
,
ldap_error($link),
ldap_errno($link)
*/
);
// Invalid attribute
var_dump(
ldap_add($link, "dc=my-domain,dc=com", array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
"weirdAttr" => "weirdVal",
)),
ldap_error($link),
ldap_errno($link)
);
var_dump(
ldap_add($link, "dc=my-domain,dc=com", array(array( "Oops"
)))
/* Is this correct behaviour to still have "Undefined attribute type" as error/errno?
,
ldap_error($link),
ldap_errno($link)
*/
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,dc=com");
?>
--EXPECTF--
Warning: ldap_add() expects exactly 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_add() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_add() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_add() expects exactly 3 parameters, 4 given in %s on line %d
NULL
Warning: ldap_add(): Add: Protocol error in %s on line %d
bool(false)
Warning: ldap_add(): Add: Invalid DN syntax in %s on line %d
bool(false)
string(17) "Invalid DN syntax"
int(34)
bool(true)
Warning: ldap_add(): Add: Already exists in %s on line %d
bool(false)
string(14) "Already exists"
int(68)
Warning: ldap_add(): Value array must have consecutive indices 0, 1, ... in %s on line %d
bool(false)
Warning: ldap_add(): Add: Undefined attribute type in %s on line %d
bool(false)
string(24) "Undefined attribute type"
int(17)
Warning: ldap_add(): Unknown attribute in the data in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,19 @@
--TEST--
ldap_bind() - Basic anonymous binding
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
var_dump(ldap_bind($link));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===

View File

@ -0,0 +1,35 @@
--TEST--
ldap_bind() - Binding that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
// Invalid parameter count
var_dump(ldap_bind($link, $user, $passwd, null));
// Invalid password
var_dump(ldap_bind($link, $user, "ThisIsNotCorrect$passwd"));
// Invalid DN syntax
var_dump(ldap_bind($link, "unexistingProperty=weirdValue,$user", $passwd));
?>
===DONE===
--EXPECTF--
Warning: ldap_bind() expects at most 3 parameters, 4 given in %s on line %d
bool(false)
Warning: ldap_bind(): Unable to bind to server: Invalid credentials in %s on line %d
bool(false)
Warning: ldap_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,19 @@
--TEST--
ldap_bind() - Advanced binding
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
var_dump(ldap_bind($link, $user, $passwd));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===

View File

@ -0,0 +1,31 @@
--TEST--
ldap_compare() - Basic ldap_compare test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
ldap_compare($link, "cn=userA,dc=my-domain,dc=com", "sn", "testSN1"),
ldap_compare($link, "cn=userA,dc=my-domain,dc=com", "telephoneNumber", "yy-yy-yy-yy-yy")
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
bool(false)
===DONE===

View File

@ -0,0 +1,55 @@
--TEST--
ldap_compare() - Testing ldap_compare() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
// Too few parameters
var_dump(ldap_compare($link));
var_dump(ldap_compare($link, $link));
var_dump(ldap_compare($link, $link, $link));
// Too many parameters
var_dump(ldap_compare($link, $link, $link, $link, "Additional data"));
var_dump(
ldap_compare($link, "cn=userNotAvailable,dc=my-domain,dc=com", "sn", "testSN1"),
ldap_error($link),
ldap_errno($link)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
Warning: ldap_compare() expects exactly 4 parameters, 1 given in %s on line %d
NULL
Warning: ldap_compare() expects exactly 4 parameters, 2 given in %s on line %d
NULL
Warning: ldap_compare() expects exactly 4 parameters, 3 given in %s on line %d
NULL
Warning: ldap_compare() expects exactly 4 parameters, 5 given in %s on line %d
NULL
Warning: ldap_compare(): Compare: No such object in %s on line %d
int(-1)
string(14) "No such object"
int(32)
===DONE===

View File

@ -0,0 +1,18 @@
--TEST--
ldap_connect() - Basic connection
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump($link);
?>
===DONE===
--EXPECTF--
resource(%d) of type (ldap link)
===DONE===

View File

@ -0,0 +1,31 @@
--TEST--
ldap_connect() - Connection errors
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--INI--
ldap.max_links=1
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
// too many arguments
var_dump(ldap_connect(null, null, null));
var_dump(ldap_connect("ldap://$host:$port/dc=my-domain,dc=com"));
$links = array();
$links[0] = ldap_connect($host, $port);
$links[1] = ldap_connect($host, $port);
?>
===DONE===
--EXPECTF--
Warning: ldap_connect() expects at most 2 parameters, 3 given in %s on line %d
bool(false)
Warning: ldap_connect(): Could not create session handle: %s in %s on line %d
bool(false)
Warning: ldap_connect(): Too many open links (1) in %s on line %d
===DONE===

View File

@ -0,0 +1,39 @@
--TEST--
ldap_connect() - Variation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
// no hostname, no port
$link = ldap_connect();
var_dump($link);
// no port
$link = ldap_connect($host);
var_dump($link);
// URI
$link = ldap_connect("ldap://$host:$port");
var_dump($link);
// URI no port
$link = ldap_connect("ldap://$host");
var_dump($link);
// bad hostname (connect should work, not bind)
$link = ldap_connect("nonexistent" . $host);
var_dump($link);
?>
===DONE===
--EXPECTF--
resource(%d) of type (ldap link)
resource(%d) of type (ldap link)
resource(%d) of type (ldap link)
resource(%d) of type (ldap link)
resource(%d) of type (ldap link)
===DONE===

View File

@ -0,0 +1,28 @@
--TEST--
ldap_count_entries() - Basic counting LDAP entries
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
var_dump(ldap_count_entries($link, $result));
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
int(3)
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_count_entries() - Testing counting LDAP entries that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_count_entries($link));
var_dump(ldap_count_entries($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_count_entries() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_count_entries(): supplied resource is not a valid ldap result resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,40 @@
--TEST--
ldap_delete() - Basic delete operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_add($link, "dc=my-domain,dc=com", array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
));
var_dump(
ldap_delete($link, "dc=my-domain,dc=com"),
@ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,dc=com");
?>
--EXPECT--
bool(true)
bool(false)
===DONE===

View File

@ -0,0 +1,62 @@
--TEST--
ldap_delete() - Delete operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Too few parameters
var_dump(ldap_delete());
var_dump(ldap_delete($link));
// Too many parameters
var_dump(ldap_delete($link, "dc=my-domain,dc=com", "Additional data"));
// Invalid DN
var_dump(
ldap_delete($link, "weirdAttribute=val"),
ldap_error($link),
ldap_errno($link)
);
// Deleting unexisting data
var_dump(
ldap_delete($link, "dc=my-domain,dc=com"),
ldap_error($link),
ldap_errno($link)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
?>
--EXPECTF--
Warning: ldap_delete() expects exactly 2 parameters, 0 given in %s on line %d
NULL
Warning: ldap_delete() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_delete() expects exactly 2 parameters, 3 given in %s on line %d
NULL
Warning: ldap_delete(): Delete: Invalid DN syntax in %s on line %d
bool(false)
string(17) "Invalid DN syntax"
int(34)
Warning: ldap_delete(): Delete: No such object in %s on line %d
bool(false)
string(14) "No such object"
int(32)
===DONE===

View File

@ -0,0 +1,15 @@
--TEST--
ldap_err2str() - Basic error number to string conversion
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
var_dump(ldap_err2str(2));
?>
===DONE===
--EXPECT--
string(14) "Protocol error"
===DONE===

View File

@ -0,0 +1,28 @@
--TEST--
ldap_err2str() - Incorrect usage of number to string conversion
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
// Too few args
var_dump(ldap_err2str());
// Too many args
var_dump(ldap_err2str(1, "Additional data"));
var_dump(ldap_err2str("weird"));
?>
===DONE===
--EXPECTF--
Warning: ldap_err2str() expects exactly 1 parameter, 0 given in %s on line %d
NULL
Warning: ldap_err2str() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Warning: ldap_err2str() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,30 @@
--TEST--
ldap_errno() - Basic ldap_errno() operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
@ldap_add($link, "badDN dc=my-domain,dc=com", array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
));
var_dump(
ldap_errno($link)
);
?>
===DONE===
--EXPECT--
int(34)
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_errno() - ldap_errno() operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
// Too few parameters
var_dump(ldap_errno());
// Too many parameters
var_dump(ldap_errno(null, null));
?>
===DONE===
--EXPECTF--
Warning: ldap_errno() expects exactly 1 parameter, 0 given in %s on line %d
NULL
Warning: ldap_errno() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,30 @@
--TEST--
ldap_error() - Basic ldap_error() operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
@ldap_add($link, "badDN dc=my-domain,dc=com", array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
));
var_dump(
ldap_error($link)
);
?>
===DONE===
--EXPECT--
string(17) "Invalid DN syntax"
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_error() - ldap_error() operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
// Too few parameters
var_dump(ldap_error());
// Too many parameters
var_dump(ldap_error(null, null));
?>
===DONE===
--EXPECTF--
Warning: ldap_error() expects exactly 1 parameter, 0 given in %s on line %d
NULL
Warning: ldap_error() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,31 @@
--TEST--
ldap_first_attribute() - Basic ldap_first_attribute test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
$entry = ldap_first_entry($link, $result);
var_dump(
ldap_first_attribute($link, $entry)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
string(11) "objectClass"
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_first_attribute() - Testing ldap_first_attribute() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_first_attribute($link));
var_dump(ldap_first_attribute($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_first_attribute() expects %s 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_first_attribute(): supplied resource is not a valid ldap result entry resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,37 @@
--TEST--
ldap_first_entry() - Basic ldap_first_entry test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
var_dump(
$entry = ldap_first_entry($link, $result),
ldap_get_values($link, $entry, 'sn')
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result entry)
array(2) {
[0]=>
string(7) "testSN%d"
["count"]=>
int(1)
}
===DONE===

View File

@ -0,0 +1,27 @@
--TEST--
ldap_first_entry() - Testing ldap_first_entry() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_first_entry($link));
var_dump(ldap_first_entry($link, $link, "Additional data"));
var_dump(ldap_first_entry($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_first_entry() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_first_entry() expects exactly 2 parameters, 3 given in %s on line %d
NULL
Warning: ldap_first_entry(): supplied resource is not a valid ldap result resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,43 @@
--TEST--
ldap_first_reference() - Basic ldap_first_reference test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
"objectClass" => array("extensibleObject", "referral"),
"cn" => "userref",
"ref" => "cn=userA,dc=my-domain,dc=com",
));
ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
var_dump($ref = ldap_first_reference($link, $result));
$refs = null;
ldap_parse_reference($link, $ref, $refs);
var_dump($refs);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Referral can only be removed with Manage DSA IT Control
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result entry)
array(1) {
[0]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
===DONE===

View File

@ -0,0 +1,27 @@
--TEST--
ldap_first_reference() - Testing ldap_first_reference() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_first_reference($link));
var_dump(ldap_first_reference($link, $link, "Additional data"));
var_dump(ldap_first_reference($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_first_reference() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_first_reference() expects exactly 2 parameters, 3 given in %s on line %d
NULL
Warning: ldap_first_reference(): supplied resource is not a valid ldap result resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,28 @@
--TEST--
ldap_free_result() - Basic ldap_free_result tests
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)");
var_dump(ldap_free_result($result));
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_free_result() - Testing ldap_free_result() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_free_result($link));
var_dump(ldap_free_result($link, "Additional data"));
?>
===DONE===
--EXPECTF--
Warning: ldap_free_result(): supplied resource is not a valid ldap result resource in %s on line %d
bool(false)
Warning: ldap_free_result() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,65 @@
--TEST--
ldap_get_attributes() - Basic ldap_get_attributes test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
$entry = ldap_first_entry($link, $result);
var_dump(
ldap_get_attributes($link, $entry)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
array(7) {
["objectClass"]=>
array(4) {
["count"]=>
int(3)
[0]=>
string(3) "top"
[1]=>
string(8) "dcObject"
[2]=>
string(12) "organization"
}
[0]=>
string(11) "objectClass"
["dc"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[1]=>
string(2) "dc"
["o"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[2]=>
string(1) "o"
["count"]=>
int(3)
}
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_get_attributes() - Testing ldap_get_attributes() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_get_attributes($link));
var_dump(ldap_get_attributes($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_get_attributes() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_get_attributes(): supplied resource is not a valid ldap result entry resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,31 @@
--TEST--
ldap_get_dn() - Basic ldap_get_dn test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
$entry = ldap_first_entry($link, $result);
var_dump(
ldap_get_dn($link, $entry)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
string(19) "dc=my-domain,dc=com"
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_get_dn() - Testing ldap_get_dn() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_get_dn($link));
var_dump(ldap_get_dn($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_get_dn() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_get_dn(): supplied resource is not a valid ldap result entry resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,74 @@
--TEST--
ldap_get_entries() - Basic modify operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
ldap_get_entries(
$link,
ldap_search($link, "dc=my-domain,dc=com", "(o=my-domain)")
)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
array(2) {
["count"]=>
int(1)
[0]=>
array(8) {
["objectclass"]=>
array(4) {
["count"]=>
int(3)
[0]=>
string(3) "top"
[1]=>
string(8) "dcObject"
[2]=>
string(12) "organization"
}
[0]=>
string(11) "objectclass"
["dc"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[1]=>
string(2) "dc"
["o"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[2]=>
string(1) "o"
["count"]=>
int(3)
["dn"]=>
string(19) "dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,33 @@
--TEST--
ldap_get_entries() - ldap_get_entries() operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
// Too few parameters
var_dump(ldap_get_entries($link));
// Too many parameters
var_dump(ldap_get_entries($link, $link, "Additional data"));
// Bad parameter
var_dump(ldap_get_entries($link, "string"));
?>
===DONE===
--EXPECTF--
Warning: ldap_get_entries() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_get_entries() expects exactly 2 parameters, 3 given in %s on line %d
NULL
Warning: ldap_get_entries() expects parameter 2 to be resource, %unicode_string_optional% given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,33 @@
--TEST--
Test ldap_get_entries() function - variation: used on empty search
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
ldap_get_entries(
$link,
ldap_search($link, "dc=my-domain,dc=com", "(o=my-unexisting-domain)")
)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
NULL
===DONE===

View File

@ -0,0 +1,25 @@
--TEST--
ldap_get_option() - Basic ldap_get_option() operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
$option = null;
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
var_dump(
ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option),
$option
);
?>
===DONE===
--EXPECT--
bool(true)
int(3)
===DONE===

View File

@ -0,0 +1,40 @@
--TEST--
ldap_get_option() - ldap_get_option() operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
$option = null;
// Too few parameters
var_dump(ldap_get_option());
var_dump(ldap_get_option($link));
var_dump(ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION));
// Too many parameters
var_dump(
ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option, "Additional data"),
$option
);
?>
===DONE===
--EXPECTF--
Warning: ldap_get_option() expects exactly 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_get_option() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_get_option() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_get_option() expects exactly 3 parameters, 4 given in %s on line %d
NULL
NULL
===DONE===

View File

@ -0,0 +1,66 @@
--TEST--
ldap_get_option() - More ldap_get_option() operations
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
$option = null;
$controls = array(
array("oid" => "1.2.752.58.10.1", "iscritical" => true),
array("oid" => "1.2.752.58.1.10", "value" => "magic"),
);
ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
ldap_set_option($link, LDAP_OPT_SIZELIMIT, 123);
ldap_set_option($link, LDAP_OPT_TIMELIMIT, 33);
ldap_set_option($link, LDAP_OPT_NETWORK_TIMEOUT, 44);
ldap_set_option($link, LDAP_OPT_REFERRALS, false);
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls);
ldap_set_option($link, LDAP_OPT_CLIENT_CONTROLS, $controls);
ldap_set_option($link, LDAP_OPT_RESTART, false);
var_dump(
ldap_get_option($link, LDAP_OPT_DEREF, $option),
$option,
ldap_get_option($link, LDAP_OPT_SIZELIMIT, $option),
$option,
ldap_get_option($link, LDAP_OPT_TIMELIMIT, $option),
$option,
ldap_get_option($link, LDAP_OPT_NETWORK_TIMEOUT, $option),
$option,
ldap_get_option($link, LDAP_OPT_REFERRALS, $option),
$option,
ldap_get_option($link, LDAP_OPT_RESTART, $option),
$option,
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $option),
$option,
ldap_get_option($link, LDAP_OPT_CLIENT_CONTROLS, $option),
$option
);
?>
===DONE===
--EXPECT--
bool(true)
int(0)
bool(true)
int(123)
bool(true)
int(33)
bool(true)
int(44)
bool(true)
int(0)
bool(true)
int(0)
bool(false)
int(0)
bool(false)
int(0)
===DONE===

View File

@ -0,0 +1,36 @@
--TEST--
ldap_get_values_len() - Basic ldap_get_values_len test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
$entry = ldap_first_entry($link, $result);
var_dump(
ldap_get_values_len($link, $entry, "o")
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
array(2) {
[0]=>
string(9) "my-domain"
["count"]=>
int(1)
}
===DONE===

View File

@ -0,0 +1,45 @@
--TEST--
ldap_get_values_len() - Testing ldap_get_values_len() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
$entry = ldap_first_entry($link, $result);
// Too few parameters
var_dump(ldap_get_values_len($link));
var_dump(ldap_get_values_len($link, $entry));
var_dump(ldap_get_values_len($link, $entry, "weirdAttribute", "Additional data"));
var_dump(ldap_get_values_len($link, $entry, "inexistantAttribute"));
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
Warning: ldap_get_values_len() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_get_values_len() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_get_values_len() expects exactly 3 parameters, 4 given in %s on line %d
NULL
Warning: ldap_get_values_len(): Cannot get the value(s) of attribute %s in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,150 @@
--TEST--
ldap_list() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
$result = ldap_list($link, "dc=my-domain,dc=com", "(objectClass=person)"),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result)
array(3) {
["count"]=>
int(2)
[0]=>
array(14) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userA"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN1"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(4) "oops"
}
[3]=>
string(12) "userpassword"
["telephonenumber"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(14) "xx-xx-xx-xx-xx"
}
[4]=>
string(15) "telephonenumber"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user A"
}
[5]=>
string(11) "description"
["count"]=>
int(6)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
[1]=>
array(12) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userB"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN2"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(15) "oopsIDitItAgain"
}
[3]=>
string(12) "userpassword"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user B"
}
[4]=>
string(11) "description"
["count"]=>
int(5)
["dn"]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,35 @@
--TEST--
ldap_list() - operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect($host, $port);
// Too few parameters
var_dump(ldap_list());
var_dump(ldap_list($link));
var_dump(ldap_list($link, $link));
// Too many parameters
var_dump(ldap_list($link, "dc=my-domain,dc=com", "(objectClass=*)", array(), 0, 0, 0, 0 , "Additional data"));
?>
===DONE===
--EXPECTF--
Warning: ldap_list() expects at least 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_list() expects at least 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_list() expects at least 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_list() expects at most 8 parameters, 9 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,90 @@
--TEST--
ldap_mod_add() - Basic modify operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$entry = array(
"description" => "Domain description",
);
var_dump(
ldap_mod_add($link, "dc=my-domain,dc=com", $entry),
ldap_get_entries(
$link,
ldap_search($link, "dc=my-domain,dc=com", "(Description=Domain description)")
)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
array(2) {
["count"]=>
int(1)
[0]=>
array(10) {
["objectclass"]=>
array(4) {
["count"]=>
int(3)
[0]=>
string(3) "top"
[1]=>
string(8) "dcObject"
[2]=>
string(12) "organization"
}
[0]=>
string(11) "objectclass"
["dc"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[1]=>
string(2) "dc"
["o"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[2]=>
string(1) "o"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(18) "Domain description"
}
[3]=>
string(11) "description"
["count"]=>
int(4)
["dn"]=>
string(19) "dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,83 @@
--TEST--
ldap_mod_add() - ldap_mod_add() operations that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Too few parameters
var_dump(ldap_mod_add());
var_dump(ldap_mod_add($link));
var_dump(ldap_mod_add($link, "dc=my-domain,dc=com"));
// Too many parameters
var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", array(), "Additional data"));
// DN not found
var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", array()));
// Invalid DN
var_dump(ldap_mod_add($link, "weirdAttribute=val", array()));
$entry = array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
);
ldap_add($link, "dc=my-domain,dc=com", $entry);
$entry2 = $entry;
$entry2["dc"] = "Wrong Domain";
var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", $entry2));
$entry2 = $entry;
$entry2["weirdAttribute"] = "weirdVal";
var_dump(ldap_mod_add($link, "dc=my-domain,dc=com", $entry2));
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,dc=com");
?>
--EXPECTF--
Warning: ldap_mod_add() expects exactly 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_mod_add() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_mod_add() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_mod_add() expects exactly 3 parameters, 4 given in %s on line %d
NULL
Warning: ldap_mod_add(): Modify: No such object in %s on line %d
bool(false)
Warning: ldap_mod_add(): Modify: Invalid DN syntax in %s on line %d
bool(false)
Warning: ldap_mod_add(): Modify: Type or value exists in %s on line %d
bool(false)
Warning: ldap_mod_add(): Modify: Undefined attribute type in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,40 @@
--TEST--
ldap_mod_del() - Basic modify operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$entry = array(
"description" => "user A"
);
var_dump(
ldap_mod_del($link, "cn=userA,dc=my-domain,dc=com", $entry),
ldap_get_entries(
$link,
ldap_search($link, "dc=my-domain,dc=com", "(description=user A)")
)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
NULL
===DONE===

View File

@ -0,0 +1,62 @@
--TEST--
ldap_mod_del() - ldap_mod_del() operations that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Too few parameters
var_dump(ldap_mod_del());
var_dump(ldap_mod_del($link));
var_dump(ldap_mod_del($link, "dc=my-domain,dc=com"));
// Too many parameters
var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array(), "Additional data"));
// DN not found
var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array()));
// Invalid DN
var_dump(ldap_mod_del($link, "weirdAttribute=val", array()));
// Invalid attributes
var_dump(ldap_mod_del($link, "dc=my-domain,dc=com", array('dc')));
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,dc=com");
?>
--EXPECTF--
Warning: ldap_mod_del() expects exactly 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_mod_del() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_mod_del() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_mod_del() expects exactly 3 parameters, 4 given in %s on line %d
NULL
Warning: ldap_mod_del(): Modify: No such object in %s on line %d
bool(false)
Warning: ldap_mod_del(): Modify: Invalid DN syntax in %s on line %d
bool(false)
Warning: ldap_mod_del(): Unknown attribute in the data in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,59 @@
--TEST--
ldap_mod_replace() - Basic modify operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$entry = array(
"description" => "user X"
);
var_dump(
ldap_mod_replace($link, "cn=userA,dc=my-domain,dc=com", $entry),
ldap_get_entries(
$link,
ldap_search($link, "dc=my-domain,dc=com", "(description=user X)", array("description"))
)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user X"
}
[0]=>
string(11) "description"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,62 @@
--TEST--
ldap_mod_replace() - ldap_mod_replace() operations that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Too few parameters
var_dump(ldap_mod_replace());
var_dump(ldap_mod_replace($link));
var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com"));
// Too many parameters
var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array(), "Additional data"));
// DN not found
var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array()));
// Invalid DN
var_dump(ldap_mod_replace($link, "weirdAttribute=val", array()));
// Invalid attributes
var_dump(ldap_mod_replace($link, "dc=my-domain,dc=com", array('dc')));
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,dc=com");
?>
--EXPECTF--
Warning: ldap_mod_replace() expects exactly 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_mod_replace() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_mod_replace() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_mod_replace() expects exactly 3 parameters, 4 given in %s on line %d
NULL
Warning: ldap_mod_replace(): Modify: No such object in %s on line %d
bool(false)
Warning: ldap_mod_replace(): Modify: Invalid DN syntax in %s on line %d
bool(false)
Warning: ldap_mod_replace(): Unknown attribute in the data in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,96 @@
--TEST--
ldap_modify() - Basic modify operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$entry = array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
"description" => "Domain description",
);
var_dump(
ldap_modify($link, "dc=my-domain,dc=com", $entry),
ldap_get_entries(
$link,
ldap_search($link, "dc=my-domain,dc=com", "(Description=Domain description)")
)
);
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
array(2) {
["count"]=>
int(1)
[0]=>
array(10) {
["objectclass"]=>
array(4) {
["count"]=>
int(3)
[0]=>
string(3) "top"
[1]=>
string(8) "dcObject"
[2]=>
string(12) "organization"
}
[0]=>
string(11) "objectclass"
["dc"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[1]=>
string(2) "dc"
["o"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[2]=>
string(1) "o"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(18) "Domain description"
}
[3]=>
string(11) "description"
["count"]=>
int(4)
["dn"]=>
string(19) "dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,83 @@
--TEST--
ldap_modify() - Modify operations that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Too few parameters
var_dump(ldap_modify());
var_dump(ldap_modify($link));
var_dump(ldap_modify($link, "dc=my-domain,dc=com"));
// Too many parameters
var_dump(ldap_modify($link, "dc=my-domain,dc=com", array(), "Additional data"));
// DN not found
var_dump(ldap_modify($link, "dc=my-domain,dc=com", array()));
// Invalid DN
var_dump(ldap_modify($link, "weirdAttribute=val", array()));
$entry = array(
"objectClass" => array(
"top",
"dcObject",
"organization"),
"dc" => "my-domain",
"o" => "my-domain",
);
ldap_add($link, "dc=my-domain,dc=com", $entry);
$entry2 = $entry;
$entry2["dc"] = "Wrong Domain";
var_dump(ldap_modify($link, "dc=my-domain,dc=com", $entry2));
$entry2 = $entry;
$entry2["weirdAttribute"] = "weirdVal";
var_dump(ldap_modify($link, "dc=my-domain,dc=com", $entry2));
?>
===DONE===
--CLEAN--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "dc=my-domain,dc=com");
?>
--EXPECTF--
Warning: ldap_modify() expects exactly 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_modify() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_modify() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_modify() expects exactly 3 parameters, 4 given in %s on line %d
NULL
Warning: ldap_modify(): Modify: No such object in %s on line %d
bool(false)
Warning: ldap_modify(): Modify: Invalid DN syntax in %s on line %d
bool(false)
Warning: ldap_modify(): Modify: Naming violation in %s on line %d
bool(false)
Warning: ldap_modify(): Modify: Undefined attribute type in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,36 @@
--TEST--
ldap_next_attribute() - Basic ldap_next_attribute test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
$entry = ldap_first_entry($link, $result);
$attribute = ldap_first_attribute($link, $entry);
var_dump(
ldap_next_attribute($link, $entry),
ldap_next_attribute($link, $entry),
ldap_next_attribute($link, $entry)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
string(%d) "%s"
string(%d) "%s"
bool(false)
===DONE===

View File

@ -0,0 +1,40 @@
--TEST--
ldap_next_attribute() - Testing ldap_next_attribute() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=organization)");
$entry = ldap_first_entry($link, $result);
var_dump(
ldap_next_attribute($link),
ldap_next_attribute($link, $link),
ldap_next_attribute($link, $entry)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
Warning: ldap_next_attribute() expects %s 2 parameters, 1 given in %s on line %d
Warning: ldap_next_attribute(): supplied resource is not a valid ldap result entry resource in %s on line %d
Warning: ldap_next_attribute(): called before calling ldap_first_attribute() or no attributes found in result entry in %s on line %d
NULL
bool(false)
bool(false)
===DONE===

View File

@ -0,0 +1,40 @@
--TEST--
ldap_next_entry() - Basic ldap_first_entry test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$result = ldap_list($link, "dc=my-domain,dc=com", "(objectClass=person)");
$entry = ldap_first_entry($link, $result);
var_dump(
$entry = ldap_next_entry($link, $entry),
ldap_get_values($link, $entry, 'sn'),
$entry = ldap_next_entry($link, $entry)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result entry)
array(2) {
[0]=>
string(7) "testSN%d"
["count"]=>
int(1)
}
bool(false)
===DONE===

View File

@ -0,0 +1,27 @@
--TEST--
ldap_next_entry() - Testing ldap_next_entry() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_next_entry($link));
var_dump(ldap_next_entry($link, $link, "Additional data"));
var_dump(ldap_next_entry($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_next_entry() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_next_entry() expects exactly 2 parameters, 3 given in %s on line %d
NULL
Warning: ldap_next_entry(): supplied resource is not a valid ldap result entry resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,49 @@
--TEST--
ldap_next_reference() - Basic ldap_next_reference test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
"objectClass" => array("extensibleObject", "referral"),
"cn" => "userref",
"ref" => "cn=userA,dc=my-domain,dc=com",
));
ldap_add($link, "cn=userref2,dc=my-domain,dc=com", array(
"objectClass" => array("extensibleObject", "referral"),
"cn" => "userref2",
"ref" => "cn=userB,dc=my-domain,dc=com",
));
ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
$ref = ldap_first_reference($link, $result);
var_dump($ref2 = ldap_next_reference($link, $ref));
ldap_parse_reference($link, $ref2, $refs);
var_dump($refs);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Referral can only be removed with Manage DSA IT Control
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
ldap_delete($link, "cn=userref2,dc=my-domain,dc=com");
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result entry)
array(1) {
[0]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
===DONE===

View File

@ -0,0 +1,27 @@
--TEST--
ldap_next_reference() - Testing ldap_next_reference() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_next_reference($link));
var_dump(ldap_next_reference($link, $link, "Additional data"));
var_dump(ldap_next_reference($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_next_reference() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: ldap_next_reference() expects exactly 2 parameters, 3 given in %s on line %d
NULL
Warning: ldap_next_reference(): supplied resource is not a valid ldap result entry resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,45 @@
--TEST--
ldap_parse_reference() - Basic ldap_parse_reference test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
"objectClass" => array("extensibleObject", "referral"),
"cn" => "userref",
"ref" => "cn=userA,dc=my-domain,dc=com",
));
ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=*)");
$ref = ldap_first_reference($link, $result);
$refs = null;
var_dump(
ldap_parse_reference($link, $ref, $refs),
$refs
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Referral can only be removed with Manage DSA IT Control
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
remove_dummy_data($link);
?>
--EXPECTF--
bool(true)
array(1) {
[0]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
===DONE===

View File

@ -0,0 +1,31 @@
--TEST--
ldap_parse_reference() - ldap_parse_reference() operations that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
$refs = null;
var_dump(
ldap_parse_reference($link, $link),
ldap_parse_reference($link, $link, $refs),
ldap_parse_reference($link, $refs, $refs, "Additional data"),
$refs
);
?>
===DONE===
--EXPECTF--
Warning: ldap_parse_reference() expects exactly 3 parameters, 2 given in %s on line %d
Warning: ldap_parse_reference(): supplied resource is not a valid ldap result entry resource in %s on line %d
Warning: ldap_parse_reference() expects exactly 3 parameters, 4 given in %s on line %d
NULL
bool(false)
NULL
NULL
===DONE===

View File

@ -0,0 +1,47 @@
--TEST--
ldap_parse_result() - Basic ldap_parse_result test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
ldap_add($link, "cn=userref,dc=my-domain,dc=com", array(
"objectClass" => array("extensibleObject", "referral"),
"cn" => "userref",
"ref" => "cn=userA,dc=my-domain,dc=com",
));
$result = ldap_search($link, "cn=userref,dc=my-domain,dc=com", "(cn=user*)");
$errcode = $dn = $errmsg = $refs = null;
var_dump(
ldap_parse_result($link, $result, $errcode, $dn, $errmsg, $refs),
$errcode, $dn, $errmsg, $refs
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Referral can only be removed with Manage DSA IT Control
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array(array("oid" => "2.16.840.1.113730.3.4.2")));
ldap_delete($link, "cn=userref,dc=my-domain,dc=com");
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
int(10)
string(30) "cn=userref,dc=my-domain,dc=com"
string(0) ""
array(1) {
[0]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
===DONE===

View File

@ -0,0 +1,17 @@
--TEST--
ldap_parse_result() - Testing ldap_parse_result() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
var_dump(ldap_parse_result(null, null));
?>
===DONE===
--EXPECTF--
Warning: ldap_parse_result() expects at least 3 parameters, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,75 @@
--TEST--
ldap_read() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
$result = ldap_read($link, "dc=my-domain,dc=com", "(dc=*)"),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result)
array(2) {
["count"]=>
int(1)
[0]=>
array(8) {
["objectclass"]=>
array(4) {
["count"]=>
int(3)
[0]=>
string(3) "top"
[1]=>
string(8) "dcObject"
[2]=>
string(12) "organization"
}
[0]=>
string(11) "objectclass"
["dc"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[1]=>
string(2) "dc"
["o"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[2]=>
string(1) "o"
["count"]=>
int(3)
["dn"]=>
string(19) "dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,35 @@
--TEST--
ldap_read() - operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect($host, $port);
// Too few parameters
var_dump(ldap_read());
var_dump(ldap_read($link));
var_dump(ldap_read($link, $link));
// Too many parameters
var_dump(ldap_read($link, "dc=my-domain,dc=com", "(objectClass=*)", array(), 0, 0, 0, 0 , "Additional data"));
?>
===DONE===
--EXPECTF--
Warning: ldap_read() expects at least 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_read() expects at least 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_read() expects at least 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_read() expects at most 8 parameters, 9 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,62 @@
--TEST--
ldap_rename() - Basic ldap_rename test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
ldap_rename($link, "cn=userA,dc=my-domain,dc=com", "cn=userZ", "dc=my-domain,dc=com", true)
);
$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=userA)", array("cn", "sn"));
$result = ldap_search($link, "dc=my-domain,dc=com", "(cn=userZ)", array("cn", "sn"));
var_dump(ldap_get_entries($link, $result));
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_rename($link, "cn=userZ,dc=my-domain,dc=com", "cn=userA", "dc=my-domain,dc=com", true);
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
array(2) {
["count"]=>
int(1)
[0]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN1"
}
[0]=>
string(2) "sn"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userZ"
}
[1]=>
string(2) "cn"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userZ,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,21 @@
--TEST--
ldap_rename() - Testing ldap_rename() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_rename($link));
var_dump(ldap_rename($link, "cn=userNotFound,dc=my-domain,dc=com", "cn=userZ", "dc=my-domain,dc=com", true));
?>
===DONE===
--EXPECTF--
Warning: ldap_rename() expects exactly 5 parameters, 1 given in %s on line %d
NULL
bool(false)
===DONE===

View File

@ -0,0 +1,20 @@
--TEST--
ldap_sasl_bind() - Basic anonymous binding
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php if (!function_exists("ldap_sasl_bind")) die("skip LDAP extension not compiled with SASL support"); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
var_dump(ldap_sasl_bind($link, null, $passwd, 'DIGEST-MD5', 'realm', $sasl_user));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===

View File

@ -0,0 +1,53 @@
--TEST--
ldap_sasl_bind() - Binding that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
<?php if (!function_exists("ldap_sasl_bind")) die("skip LDAP extension not compiled with SASL support"); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
// Invalid parameter count
var_dump(ldap_sasl_bind());
// Invalid DN
var_dump(ldap_sasl_bind($link, "Invalid DN", $passwd, 'DIGEST-MD5', 'realm', $sasl_user));
// Invalid user
var_dump(ldap_sasl_bind($link, null, "ThisIsNotCorrect$passwd", 'DIGEST-MD5', "realm", "invalid$sasl_user"));
// Invalid password
var_dump(ldap_sasl_bind($link, null, "ThisIsNotCorrect$passwd", 'DIGEST-MD5', "realm", $sasl_user));
var_dump(ldap_sasl_bind($link, null, $passwd, 'DIGEST-MD5', "realm", "Manager", "test"));
// Invalid DN syntax
var_dump(ldap_sasl_bind($link, "unexistingProperty=weirdValue,$user", $passwd));
?>
===DONE===
--EXPECTF--
Warning: ldap_sasl_bind() expects at least 1 parameter, 0 given in %s on line %d
bool(false)
Warning: ldap_sasl_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
bool(false)
Warning: ldap_sasl_bind(): Unable to bind to server: Invalid credentials in %s on line %d
bool(false)
Warning: ldap_sasl_bind(): Unable to bind to server: Invalid credentials in %s on line %d
bool(false)
Warning: ldap_sasl_bind(): Unable to bind to server: Insufficient access in %s on line %d
bool(false)
Warning: ldap_sasl_bind(): Unable to bind to server: Invalid DN syntax in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,194 @@
--TEST--
ldap_search() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectClass=person)"),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result)
array(4) {
["count"]=>
int(3)
[0]=>
array(14) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userA"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN1"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(4) "oops"
}
[3]=>
string(12) "userpassword"
["telephonenumber"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(14) "xx-xx-xx-xx-xx"
}
[4]=>
string(15) "telephonenumber"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user A"
}
[5]=>
string(11) "description"
["count"]=>
int(6)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
[1]=>
array(12) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userB"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN2"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(15) "oopsIDitItAgain"
}
[3]=>
string(12) "userpassword"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user B"
}
[4]=>
string(11) "description"
["count"]=>
int(5)
["dn"]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
[2]=>
array(10) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userC"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN3"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(17) "0r1g1na1 passw0rd"
}
[3]=>
string(12) "userpassword"
["count"]=>
int(4)
["dn"]=>
string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,62 @@
--TEST--
ldap_search() - operation that should fail
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect($host, $port);
$dn = "dc=my-domain,dc=com";
$filter = "(dc=*)";
$result = ldap_search();
var_dump($result);
$result = ldap_search($link, $dn, $filter);
var_dump($result);
$result = ldap_search($link, $dn, $filter, NULL);
var_dump($result);
$result = ldap_search($link, $dn, $filter, array(1 => 'top'));
var_dump($result);
$result = ldap_search(array(), $dn, $filter, array('top'));
var_dump($result);
$result = ldap_search(array($link, $link), array($dn), $filter, array('top'));
var_dump($result);
$result = ldap_search(array($link, $link), $dn, array($filter), array('top'));
var_dump($result);
?>
===DONE===
--EXPECTF--
Warning: ldap_search() expects at least 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_search(): Search: No such object in %s on line %d
bool(false)
Warning: ldap_search(): Expected Array as last element in %s on line %d
bool(false)
Warning: ldap_search(): Array initialization wrong in %s on line %d
bool(false)
Warning: ldap_search(): No links in link array in %s on line %d
bool(false)
Warning: ldap_search(): Base must either be a string, or an array with the same number of elements as the links array in %s on line %d
bool(false)
Warning: ldap_search(): Filter must either be a string, or an array with the same number of elements as the links array in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,56 @@
--TEST--
ldap_search() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$dn = "dc=my-domain,dc=com";
$filter = "(dc=*)";
var_dump(
$result = ldap_search($link, "dc=my-domain,dc=com", "(dc=*)", array('dc')),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result)
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["dc"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(9) "my-domain"
}
[0]=>
string(2) "dc"
["count"]=>
int(1)
["dn"]=>
string(19) "dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,80 @@
--TEST--
ldap_search() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
var_dump(
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array('sn'), 1),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result)
array(4) {
["count"]=>
int(3)
[0]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
[1]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
[2]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,108 @@
--TEST--
ldap_search() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$dn = "dc=my-domain,dc=com";
$filter = "(objectclass=person)";
var_dump(
$result = ldap_search($link, $dn, $filter, array('sn'), 1, 3),
ldap_get_entries($link, $result)
);
var_dump(
$result = ldap_search($link, $dn, $filter, array('sn'), 1, 1),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
resource(%d) of type (ldap result)
array(4) {
["count"]=>
int(3)
[0]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
[1]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
[2]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
}
}
Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
resource(%d) of type (ldap result)
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,55 @@
--TEST--
ldap_search() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$dn = "dc=my-domain,dc=com";
$filter = "(objectclass=person)";
var_dump(
$result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
resource(%d) of type (ldap result)
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,105 @@
--TEST--
ldap_search() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$dn = "dc=my-domain,dc=com";
$filter = "(objectclass=person)";
var_dump(
$result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_SEARCHING),
ldap_get_entries($link, $result)
);
var_dump(
$result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_FINDING),
ldap_get_entries($link, $result)
);
var_dump(
$result = ldap_search($link, $dn, $filter, array('sn'), 1, 1, 3, LDAP_DEREF_ALWAYS),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
resource(%d) of type (ldap result)
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
}
Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
resource(%d) of type (ldap result)
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
}
Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in %s on line %d
resource(%d) of type (ldap result)
array(2) {
["count"]=>
int(1)
[0]=>
array(4) {
["sn"]=>
array(1) {
["count"]=>
int(0)
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,230 @@
--TEST--
ldap_search() test
--CREDITS--
Davide Mendolia <idaf1er@gmail.com>
Patrick Allaert <patrickallaert@php.net>
Belgian PHP Testfest 2009
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifbindfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
$dn = "dc=my-domain,dc=com";
$filter = "(objectclass=person)";
var_dump(
$result = ldap_search(array($link, $link), $dn, $filter),
$result0 = ldap_get_entries($link, $result[0]),
ldap_get_entries($link, $result[1]) === $result0
);
var_dump(
$result = ldap_search(array($link, $link), null, $filter),
ldap_get_entries($link, $result[0]),
ldap_get_entries($link, $result[1])
);
var_dump(
$result = ldap_search(array($link, $link), null, array($filter, $filter)),
ldap_get_entries($link, $result[0]),
ldap_get_entries($link, $result[1])
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
remove_dummy_data($link);
?>
--EXPECTF--
array(2) {
[0]=>
resource(%d) of type (ldap result)
[1]=>
resource(%d) of type (ldap result)
}
array(4) {
["count"]=>
int(3)
[0]=>
array(14) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userA"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN1"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(4) "oops"
}
[3]=>
string(12) "userpassword"
["telephonenumber"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(14) "xx-xx-xx-xx-xx"
}
[4]=>
string(15) "telephonenumber"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user A"
}
[5]=>
string(11) "description"
["count"]=>
int(6)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
[1]=>
array(12) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userB"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN2"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(15) "oopsIDitItAgain"
}
[3]=>
string(12) "userpassword"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user B"
}
[4]=>
string(11) "description"
["count"]=>
int(5)
["dn"]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
[2]=>
array(10) {
["objectclass"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "person"
}
[0]=>
string(11) "objectclass"
["cn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(5) "userC"
}
[1]=>
string(2) "cn"
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN3"
}
[2]=>
string(2) "sn"
["userpassword"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(17) "0r1g1na1 passw0rd"
}
[3]=>
string(12) "userpassword"
["count"]=>
int(4)
["dn"]=>
string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
}
}
bool(true)
array(2) {
[0]=>
resource(%d) of type (ldap result)
[1]=>
resource(%d) of type (ldap result)
}
NULL
NULL
array(2) {
[0]=>
resource(%d) of type (ldap result)
[1]=>
resource(%d) of type (ldap result)
}
NULL
NULL
===DONE===

View File

@ -0,0 +1,23 @@
--TEST--
ldap_set_option() - Basic ldap_set_option() operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
$option = null;
var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version));
ldap_get_option($link, LDAP_OPT_PROTOCOL_VERSION, $option);
var_dump($option);
?>
===DONE===
--EXPECT--
bool(true)
int(3)
===DONE===

View File

@ -0,0 +1,66 @@
--TEST--
ldap_set_option() - ldap_set_option() operation that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
$controls = array(
array(
array("xid" => "1.2.752.58.10.1", "iscritical" => true),
array("xid" => "1.2.752.58.1.10", "value" => "magic"),
),
array(
array("oid" => "1.2.752.58.10.1", "iscritical" => true),
array("oid" => "1.2.752.58.1.10", "value" => "magic"),
"weird"
),
array(
),
);
// Too few parameters
var_dump(ldap_set_option());
var_dump(ldap_set_option($link));
var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION));
// Too many parameters
var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3, "Additional data"));
var_dump(ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 10));
foreach ($controls as $control)
var_dump(ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $control));
var_dump(ldap_set_option($link, 999999, 999999));
?>
===DONE===
--EXPECTF--
Warning: ldap_set_option() expects exactly 3 parameters, 0 given in %s on line %d
NULL
Warning: ldap_set_option() expects exactly 3 parameters, 1 given in %s on line %d
NULL
Warning: ldap_set_option() expects exactly 3 parameters, 2 given in %s on line %d
NULL
Warning: ldap_set_option() expects exactly 3 parameters, 4 given in %s on line %d
NULL
bool(false)
Warning: ldap_set_option(): Control must have an oid key in %s on line %d
bool(false)
Warning: ldap_set_option(): The array value must contain only arrays, where each array is a control in %s on line %d
bool(false)
Warning: ldap_set_option(): Expected non-empty array value for this option in %s on line %d
bool(false)
bool(false)
===DONE===

View File

@ -0,0 +1,84 @@
--TEST--
ldap_set_option() - More ldap_set_option() operations
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
$option = null;
$controls = array(
array("oid" => "1.2.752.58.10.1", "iscritical" => true),
array("oid" => "1.2.752.58.1.10", "value" => "magic"),
);
var_dump(ldap_set_option($link, LDAP_OPT_DEREF, LDAP_DEREF_ALWAYS));
ldap_get_option($link, LDAP_OPT_DEREF, $option);
var_dump(
$option === LDAP_DEREF_ALWAYS,
ldap_set_option($link, LDAP_OPT_SIZELIMIT, 123)
);
ldap_get_option($link, LDAP_OPT_SIZELIMIT, $option);
var_dump(
$option,
ldap_set_option($link, LDAP_OPT_TIMELIMIT, 33)
);
ldap_get_option($link, LDAP_OPT_TIMELIMIT, $option);
var_dump(
$option,
ldap_set_option($link, LDAP_OPT_NETWORK_TIMEOUT, 44)
);
ldap_get_option($link, LDAP_OPT_NETWORK_TIMEOUT, $option);
var_dump(
$option,
ldap_set_option($link, LDAP_OPT_REFERRALS, true)
);
ldap_get_option($link, LDAP_OPT_REFERRALS, $option);
var_dump(
(bool) $option,
ldap_set_option($link, LDAP_OPT_RESTART, false)
);
ldap_get_option($link, LDAP_OPT_RESTART, $option);
var_dump(
(bool) $option,
ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls)
);
ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $option);
var_dump(
$option,
ldap_set_option($link, LDAP_OPT_CLIENT_CONTROLS, $controls)
);
ldap_get_option($link, LDAP_OPT_CLIENT_CONTROLS, $option);
var_dump(
$option,
ldap_set_option($link, LDAP_OPT_MATCHED_DN, "dc=test,dc=com")
);
ldap_get_option($link, LDAP_OPT_MATCHED_DN, $option);
var_dump($option);
?>
===DONE===
--EXPECT--
bool(true)
bool(true)
bool(true)
int(123)
bool(true)
int(33)
bool(true)
int(44)
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
int(0)
bool(true)
int(0)
bool(true)
string(14) "dc=test,dc=com"
===DONE===

View File

@ -0,0 +1,34 @@
--TEST--
ldap_set_rebind_proc() - Basic ldap_set_rebind_proc test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
function rebind_proc ($ds, $ldap_url) {
global $user;
global $passwd;
global $protocol_version;
// required by most modern LDAP servers, use LDAPv3
ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
if (!ldap_bind($a, $user, $passwd)) {
print "Cannot bind";
}
}
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
var_dump(ldap_set_rebind_proc($link, "rebind_proc"));
var_dump(ldap_set_rebind_proc($link, ""));
?>
===DONE===
--EXPECT--
bool(true)
bool(true)
===DONE===

View File

@ -0,0 +1,40 @@
--TEST--
ldap_set_rebind_proc() - Testing ldap_set_rebind_proc() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
function rebind_proc ($ds, $ldap_url) {
global $user;
global $passwd;
global $protocol_version;
// required by most modern LDAP servers, use LDAPv3
ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
if (!ldap_bind($a, $user, $passwd)) {
print "Cannot bind";
}
}
$link = ldap_connect($host, $port);
var_dump(ldap_set_rebind_proc($link));
var_dump(ldap_set_rebind_proc($link, "rebind_proc", "Additional data"));
var_dump(ldap_set_rebind_proc($link, "rebind_proc_inexistant"));
?>
===DONE===
--EXPECTF--
Warning: ldap_set_rebind_proc() expects exactly 2 parameters, 1 given in %s on line %d
bool(false)
Warning: ldap_set_rebind_proc() expects exactly 2 parameters, 3 given in %s on line %d
bool(false)
Warning: ldap_set_rebind_proc(): Two arguments expected for 'rebind_proc_inexistant' to be a valid callback in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,200 @@
--TEST--
ldap_sort() - Basic ldap_sort test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
ldap_add($link, "cn=userC,dc=my-domain,dc=com", array(
"objectclass" => "person",
"cn" => "userC",
"sn" => "zzz",
"userPassword" => "oops",
"description" => "a user",
));
ldap_add($link, "cn=userD,dc=my-domain,dc=com", array(
"objectclass" => "person",
"cn" => "userD",
"sn" => "aaa",
"userPassword" => "oops",
"description" => "another user",
));
ldap_add($link, "cn=userE,dc=my-domain,dc=com", array(
"objectclass" => "person",
"cn" => "userE",
"sn" => "a",
"userPassword" => "oops",
"description" => "yet another user",
));
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array("sn", "description"));
var_dump(
ldap_sort($link, $result, "sn"),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "cn=userC,dc=my-domain,dc=com");
ldap_delete($link, "cn=userD,dc=my-domain,dc=com");
ldap_delete($link, "cn=userE,dc=my-domain,dc=com");
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
array(7) {
["count"]=>
int(6)
[0]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(1) "a"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(16) "yet another user"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userE,dc=my-domain,dc=com"
}
[1]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(3) "aaa"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(12) "another user"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userD,dc=my-domain,dc=com"
}
[2]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN1"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user A"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
[3]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN2"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user B"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
[4]=>
array(4) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN3"
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
}
[5]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(3) "zzz"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "a user"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userC,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,35 @@
--TEST--
ldap_sort() - Testing ldap_sort() that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
var_dump(ldap_sort($link));
var_dump(ldap_sort($link, $link));
var_dump(ldap_sort($link, $link, $link, $link));
var_dump(ldap_sort($link, $link, $link));
var_dump(ldap_sort($link, $link, "sn"));
?>
===DONE===
--EXPECTF--
Warning: ldap_sort() expects exactly 3 parameters, 1 given in %s on line %d
bool(false)
Warning: ldap_sort() expects exactly 3 parameters, 2 given in %s on line %d
bool(false)
Warning: ldap_sort() expects exactly 3 parameters, 4 given in %s on line %d
bool(false)
Warning: ldap_sort() expects parameter 3 to be %binary_string_optional%, resource given in %s on line %d
bool(false)
Warning: ldap_sort(): Supplied resource is not a valid ldap result resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,200 @@
--TEST--
ldap_sort() - Basic ldap_sort test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link);
ldap_add($link, "cn=userC,dc=my-domain,dc=com", array(
"objectclass" => "person",
"cn" => "userC",
"sn" => "zzz",
"userPassword" => "oops",
"description" => "a user",
));
ldap_add($link, "cn=userD,dc=my-domain,dc=com", array(
"objectclass" => "person",
"cn" => "userD",
"sn" => "aaa",
"userPassword" => "oops",
"description" => "another user",
));
ldap_add($link, "cn=userE,dc=my-domain,dc=com", array(
"objectclass" => "person",
"cn" => "userE",
"sn" => "a",
"userPassword" => "oops",
"description" => "yet another user",
));
$result = ldap_search($link, "dc=my-domain,dc=com", "(objectclass=person)", array("sn", "description"));
var_dump(
ldap_sort($link, $result, "description"),
ldap_get_entries($link, $result)
);
?>
===DONE===
--CLEAN--
<?php
include "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_delete($link, "cn=userC,dc=my-domain,dc=com");
ldap_delete($link, "cn=userD,dc=my-domain,dc=com");
ldap_delete($link, "cn=userE,dc=my-domain,dc=com");
remove_dummy_data($link);
?>
--EXPECT--
bool(true)
array(7) {
["count"]=>
int(6)
[0]=>
array(4) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN3"
}
[0]=>
string(2) "sn"
["count"]=>
int(1)
["dn"]=>
string(37) "cn=userC,cn=userB,dc=my-domain,dc=com"
}
[1]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(3) "zzz"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "a user"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userC,dc=my-domain,dc=com"
}
[2]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(3) "aaa"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(12) "another user"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userD,dc=my-domain,dc=com"
}
[3]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN1"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user A"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userA,dc=my-domain,dc=com"
}
[4]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(7) "testSN2"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(6) "user B"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userB,dc=my-domain,dc=com"
}
[5]=>
array(6) {
["sn"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(1) "a"
}
[0]=>
string(2) "sn"
["description"]=>
array(2) {
["count"]=>
int(1)
[0]=>
string(16) "yet another user"
}
[1]=>
string(11) "description"
["count"]=>
int(2)
["dn"]=>
string(28) "cn=userE,dc=my-domain,dc=com"
}
}
===DONE===

View File

@ -0,0 +1,19 @@
--TEST--
ldap_start_tls() - Basic ldap_start_tls test
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
var_dump(ldap_start_tls($link));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===

View File

@ -0,0 +1,27 @@
--TEST--
ldap_start_tls() - Binding that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect($host, $port);
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
// Invalid parameter count
var_dump(ldap_start_tls());
var_dump(ldap_start_tls($link, $link));
?>
===DONE===
--EXPECTF--
Warning: ldap_start_tls() expects exactly 1 parameter, 0 given in %s on line %d
NULL
Warning: ldap_start_tls() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,20 @@
--TEST--
ldap_unbind() - Basic ldap_unbind() operation
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
var_dump(ldap_unbind($link));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===

View File

@ -0,0 +1,42 @@
--TEST--
ldap_unbind() - ldap_unbind() operations that should fail
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
// Too few parameters
var_dump(ldap_unbind());
// Too many parameters
var_dump(ldap_unbind($link, "Additional data"));
// Bad parameter
var_dump(ldap_unbind("string"));
// unbind twice
var_dump(ldap_unbind($link));
var_dump(ldap_unbind($link));
?>
===DONE===
--EXPECTF--
Warning: ldap_unbind() expects exactly 1 parameter, 0 given in %s on line %d
bool(false)
Warning: ldap_unbind() expects exactly 1 parameter, 2 given in %s on line %d
bool(false)
Warning: ldap_unbind() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d
bool(false)
bool(true)
Warning: ldap_unbind(): %d is not a valid ldap link resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,34 @@
--TEST--
ldap_unbind() - Variation of ldap_unbind() function using ldap_set_rebind_proc()
--CREDITS--
Patrick Allaert <patrickallaert@php.net>
# Belgian PHP Testfest 2009
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifbindfailure.inc'); ?>
--FILE--
<?php
require "connect.inc";
function rebind_proc ($ds, $ldap_url) {
global $user;
global $passwd;
global $protocol_version;
// required by most modern LDAP servers, use LDAPv3
ldap_set_option($a, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
if (!ldap_bind($a, $user, $passwd)) {
print "Cannot bind";
}
}
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
ldap_set_rebind_proc($link, "rebind_proc");
var_dump(ldap_unbind($link));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===