xref: /php-src/ext/ldap/tests/ldap_controls.phpt (revision 69a8b63e)
1--TEST--
2Test the use of controls
3--CREDITS--
4Côme Chilliet <mcmic@php.net>
5--EXTENSIONS--
6ldap
7--SKIPIF--
8<?php
9require_once('skipifbindfailure.inc');
10require_once('skipifcontrol.inc');
11skipifunsupportedcontrol(LDAP_CONTROL_ASSERT);
12skipifunsupportedcontrol(LDAP_CONTROL_VALUESRETURNFILTER);
13?>
14--FILE--
15<?php
16include "connect.inc";
17
18$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
19insert_dummy_data($link, $base);
20
21/* Test assertion control */
22var_dump(
23    $result = ldap_search($link, "o=test,$base", "objectClass=*", array('o'), 0, 0, 0, LDAP_DEREF_NEVER,
24        [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(objectClass=organization)']]]),
25    ldap_get_entries($link, $result),
26    $result = ldap_search($link, "o=test,$base", "objectClass=*", array('o'), 0, 0, 0, LDAP_DEREF_NEVER,
27        [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(objectClass=organizationalUnit)']]]),
28    ldap_modify($link, "o=test,$base", ['description' => 'desc'],
29        [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(!(description=*))']]]),
30    $result = ldap_read($link, "o=test,$base", "objectClass=*", array('description')),
31    ldap_get_entries($link, $result),
32    ldap_modify($link, "o=test,$base", ['description' => 'desc2'],
33        [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(!(description=*))']]]),
34    $result = ldap_read($link, "o=test,$base", "objectClass=*", array('description')),
35    ldap_get_entries($link, $result),
36    ldap_delete($link, "o=test,$base", [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]]),
37    ldap_errno($link),
38    ldap_error($link),
39    ldap_rename($link, "o=test,$base", "o=test2", "", TRUE, [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]]),
40    ldap_compare($link, "o=test,$base", "o", "test"),
41    ldap_compare($link, "o=test,$base", "o", "test", [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc2)']]]),
42    ldap_compare($link, "o=test,$base", "o", "test", [['oid' => LDAP_CONTROL_ASSERT, 'iscritical' => TRUE, 'value' => ['filter' => '(description=desc)']]])
43);
44
45/* Test valuesreturnfilter control */
46var_dump(
47    $result = ldap_read($link, "o=test2,$base", "objectClass=*", ["l"]),
48    ldap_get_entries($link, $result)[0]['l'],
49    $result = ldap_read($link, "o=test2,$base", "objectClass=*", ["l"], 0, 0, 0, LDAP_DEREF_NEVER,
50        [['oid' => LDAP_CONTROL_VALUESRETURNFILTER, 'iscritical' => TRUE, 'value' => ['filter' => '(l=*here)']]]),
51    ldap_get_entries($link, $result)[0]['l']
52);
53?>
54--CLEAN--
55<?php
56include "connect.inc";
57
58$link = ldap_connect_and_bind($uri, $user, $passwd, $protocol_version);
59remove_dummy_data($link, $base);
60?>
61--EXPECTF--
62Warning: ldap_search(): Search: Assertion Failed in %s on line %d
63
64Warning: ldap_modify(): Modify: Assertion Failed in %s on line %d
65
66Warning: ldap_delete(): Delete: Assertion Failed in %s on line %d
67
68Warning: ldap_compare(): Compare: Assertion Failed in %s on line %d
69object(LDAP\Result)#%d (0) {
70}
71array(2) {
72  ["count"]=>
73  int(1)
74  [0]=>
75  array(4) {
76    ["o"]=>
77    array(2) {
78      ["count"]=>
79      int(1)
80      [0]=>
81      string(4) "test"
82    }
83    [0]=>
84    string(1) "o"
85    ["count"]=>
86    int(1)
87    ["dn"]=>
88    string(%d) "o=test,%s"
89  }
90}
91bool(false)
92bool(true)
93object(LDAP\Result)#%d (0) {
94}
95array(2) {
96  ["count"]=>
97  int(1)
98  [0]=>
99  array(4) {
100    ["description"]=>
101    array(2) {
102      ["count"]=>
103      int(1)
104      [0]=>
105      string(4) "desc"
106    }
107    [0]=>
108    string(11) "description"
109    ["count"]=>
110    int(1)
111    ["dn"]=>
112    string(%d) "o=test,%s"
113  }
114}
115bool(false)
116object(LDAP\Result)#%d (0) {
117}
118array(2) {
119  ["count"]=>
120  int(1)
121  [0]=>
122  array(4) {
123    ["description"]=>
124    array(2) {
125      ["count"]=>
126      int(1)
127      [0]=>
128      string(4) "desc"
129    }
130    [0]=>
131    string(11) "description"
132    ["count"]=>
133    int(1)
134    ["dn"]=>
135    string(%d) "o=test,%s"
136  }
137}
138bool(false)
139int(122)
140string(16) "Assertion Failed"
141bool(false)
142bool(true)
143int(-1)
144bool(true)
145object(LDAP\Result)#%d (0) {
146}
147array(4) {
148  ["count"]=>
149  int(3)
150  [0]=>
151  string(4) "here"
152  [1]=>
153  string(5) "there"
154  [2]=>
155  string(10) "Antarctica"
156}
157object(LDAP\Result)#%d (0) {
158}
159array(3) {
160  ["count"]=>
161  int(2)
162  [0]=>
163  string(4) "here"
164  [1]=>
165  string(5) "there"
166}
167