diff options
author | Côme Chilliet <mcmic@php.net> | 2017-06-20 15:18:16 +0200 |
---|---|---|
committer | Côme Chilliet <mcmic@php.net> | 2017-07-03 10:58:12 +0200 |
commit | ae76c8ba2c41a3883672f3ddc6d93fd65aaa3b4e (patch) | |
tree | 669655f8043d911422b09eb7b3742da9764bf5dc /ext/ldap/tests | |
parent | def09c7cab2f30fbe8e7a34c978284eedd8bf3ad (diff) | |
download | php-git-ae76c8ba2c41a3883672f3ddc6d93fd65aaa3b4e.tar.gz |
Fixed ldap_exop_passwd and added tests for it
Diffstat (limited to 'ext/ldap/tests')
-rw-r--r-- | ext/ldap/tests/connect.inc | 6 | ||||
-rw-r--r-- | ext/ldap/tests/ldap_exop_passwd.phpt | 41 | ||||
-rw-r--r-- | ext/ldap/tests/ldap_exop_passwd_error.phpt | 33 |
3 files changed, 80 insertions, 0 deletions
diff --git a/ext/ldap/tests/connect.inc b/ext/ldap/tests/connect.inc index f7379ac954..1c2205056e 100644 --- a/ext/ldap/tests/connect.inc +++ b/ext/ldap/tests/connect.inc @@ -21,6 +21,12 @@ function ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version) return $link; } +function test_bind($host, $port, $user, $passwd, $protocol_version) { + $link = ldap_connect($host, $port); + ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version); + return ldap_bind($link, $user, $passwd); +} + function insert_dummy_data($link, $base) { // Create root if not there $testBase = ldap_read($link, $base, '(objectClass=*)', array('objectClass')); diff --git a/ext/ldap/tests/ldap_exop_passwd.phpt b/ext/ldap/tests/ldap_exop_passwd.phpt new file mode 100644 index 0000000000..5ab926eb4a --- /dev/null +++ b/ext/ldap/tests/ldap_exop_passwd.phpt @@ -0,0 +1,41 @@ +--TEST-- +ldap_exop_passwd() - Changing password through EXOP +--CREDITS-- +Côme Chilliet <mcmic@php.net> +--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, $base); + +// ldap_exop_passwd() allows to pass the DN, OLD and NEW passwords, +// and optionally returns the NEW password if none was passed. +// ldap_exop_passwd(resource link [, string user [, string oldpw [, string newpw [, string newpasswd ]]]]) +var_dump( + ldap_exop_passwd($link, "cn=userA,$base", "oops", "", $genpw), + $genpw, + test_bind($host, $port, "cn=userA,$base", $genpw, $protocol_version), + ldap_exop_passwd($link, "cn=userA,$base", $genpw, "newPassword"), + test_bind($host, $port, "cn=userA,$base", "newPassword", $protocol_version) +); +?> +===DONE=== +--CLEAN-- +<?php +require "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); + +remove_dummy_data($link, $base); +?> +--EXPECTF-- +bool(true) +string(%d) "%s" +bool(true) +bool(true) +bool(true) +===DONE=== diff --git a/ext/ldap/tests/ldap_exop_passwd_error.phpt b/ext/ldap/tests/ldap_exop_passwd_error.phpt new file mode 100644 index 0000000000..0476cb5a89 --- /dev/null +++ b/ext/ldap/tests/ldap_exop_passwd_error.phpt @@ -0,0 +1,33 @@ +--TEST-- +ldap_exop_passwd() - Giving wrong value for old password +--CREDITS-- +Côme Chilliet <mcmic@php.net> +--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, $base); + +var_dump(ldap_exop_passwd($link, "cn=userA,$base", "wrongPassword", "newPassword")); +var_dump(test_bind($host, $port, "cn=userA,$base", "newPassword", $protocol_version)); +?> +===DONE=== +--CLEAN-- +<?php +require "connect.inc"; + +$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version); + +remove_dummy_data($link, $base); +?> +--EXPECTF-- +Warning: ldap_exop_passwd(): Passwd modify extended operation failed: Server is unwilling to perform (53) in %s on line %d +bool(false) + +Warning: ldap_bind(): Unable to bind to server: Invalid credentials in %s on line %d +bool(false) +===DONE=== |