xref: /PHP-5.4/ext/ldap/tests/connect.inc (revision f78a0b58)
1<?php
2
3/*
4Default values are "localhost", "root", database "test" and empty password.
5Change the LDAP_TEST_* environment values if you want to use another configuration.
6*/
7
8$host			= getenv("LDAP_TEST_HOST")	? getenv("LDAP_TEST_HOST")	: "localhost";
9$port			= getenv("LDAP_TEST_PORT")	? getenv("LDAP_TEST_PORT")	: 389;
10$user			= getenv("LDAP_TEST_USER")	? getenv("LDAP_TEST_USER")	: "cn=Manager,dc=my-domain,dc=com";
11$sasl_user		= getenv("LDAP_TEST_SASL_USER")	? getenv("LDAP_TEST_SASL_USER")	: "Manager";
12$passwd			= getenv("LDAP_TEST_PASSWD")	? getenv("LDAP_TEST_PASSWD")	: "secret";
13$protocol_version	= getenv("LDAP_TEST_OPT_PROTOCOL_VERSION")	? getenv("LDAP_TEST_OPT_PROTOCOL_VERSION")	: 3;
14$skip_on_bind_failure	= getenv("LDAP_TEST_SKIP_BIND_FAILURE") ? getenv("LDAP_TEST_SKIP_BIND_FAILURE") : true;
15
16function ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version) {
17	$link = ldap_connect($host, $port);
18	ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version);
19	ldap_bind($link, $user, $passwd);
20	return $link;
21}
22
23function insert_dummy_data($link) {
24	ldap_add($link, "dc=my-domain,dc=com", array(
25	        "objectClass"   => array(
26	                "top",
27	                "dcObject",
28	                "organization"),
29	        "dc"                    => "my-domain",
30	        "o"                             => "my-domain",
31	));
32	ldap_add($link, "cn=userA,dc=my-domain,dc=com", array(
33	        "objectclass" => "person",
34	        "cn" => "userA",
35	        "sn" => "testSN1",
36	        "userPassword" => "oops",
37	        "telephoneNumber" => "xx-xx-xx-xx-xx",
38	        "description" => "user A",
39	));
40	ldap_add($link, "cn=userB,dc=my-domain,dc=com", array(
41	        "objectclass" => "person",
42	        "cn" => "userB",
43	        "sn" => "testSN2",
44	        "userPassword" => "oopsIDitItAgain",
45	        "description" => "user B",
46	));
47	ldap_add($link, "cn=userC,cn=userB,dc=my-domain,dc=com", array(
48	        "objectclass" => "person",
49	        "cn" => "userC",
50	        "sn" => "testSN3",
51	        "userPassword" => "0r1g1na1 passw0rd",
52	));
53}
54
55function remove_dummy_data($link) {
56	ldap_delete($link, "cn=userC,cn=userB,dc=my-domain,dc=com");
57	ldap_delete($link, "cn=userA,dc=my-domain,dc=com");
58	ldap_delete($link, "cn=userB,dc=my-domain,dc=com");
59	ldap_delete($link, "dc=my-domain,dc=com");
60}
61?>
62