1<?php 2 3/* 4Default values are "localhost", "cn=Manager,dc=my-domain,dc=com", and password "secret". 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$base = getenv("LDAP_TEST_BASE") ? getenv("LDAP_TEST_BASE") : "dc=my-domain,dc=com"; 11$user = getenv("LDAP_TEST_USER") ? getenv("LDAP_TEST_USER") : "cn=Manager,$base"; 12$sasl_user = getenv("LDAP_TEST_SASL_USER") ? getenv("LDAP_TEST_SASL_USER") : "Manager"; 13$passwd = getenv("LDAP_TEST_PASSWD") ? getenv("LDAP_TEST_PASSWD") : "secret"; 14$protocol_version = getenv("LDAP_TEST_OPT_PROTOCOL_VERSION") ? getenv("LDAP_TEST_OPT_PROTOCOL_VERSION") : 3; 15$skip_on_bind_failure = getenv("LDAP_TEST_SKIP_BIND_FAILURE") ? getenv("LDAP_TEST_SKIP_BIND_FAILURE") : true; 16 17function ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version) { 18 $link = ldap_connect($host, $port); 19 ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, $protocol_version); 20 ldap_bind($link, $user, $passwd); 21 return $link; 22} 23 24function insert_dummy_data($link, $base) { 25 // Create root if not there 26 $testBase = ldap_read($link, $base, '(objectClass=*)', array('objectClass')); 27 if (ldap_count_entries($link, $testBase) < 1) { 28 ldap_add( 29 $link, "$base", array( 30 "objectClass" => array( 31 "top", 32 "organization", 33 "dcObject" 34 ), 35 "o" => "php ldap tests" 36 ) 37 ); 38 } 39 ldap_add($link, "o=test,$base", array( 40 "objectClass" => array( 41 "top", 42 "organization"), 43 "o" => "test", 44 )); 45 ldap_add($link, "cn=userA,$base", array( 46 "objectclass" => "person", 47 "cn" => "userA", 48 "sn" => "testSN1", 49 "userPassword" => "oops", 50 "telephoneNumber" => "xx-xx-xx-xx-xx", 51 "description" => "user A", 52 )); 53 ldap_add($link, "cn=userB,$base", array( 54 "objectclass" => "person", 55 "cn" => "userB", 56 "sn" => "testSN2", 57 "userPassword" => "oopsIDitItAgain", 58 "description" => "user B", 59 )); 60 ldap_add($link, "cn=userC,cn=userB,$base", array( 61 "objectclass" => "person", 62 "cn" => "userC", 63 "sn" => "testSN3", 64 "userPassword" => "0r1g1na1 passw0rd", 65 )); 66} 67 68function remove_dummy_data($link, $base) { 69 ldap_delete($link, "cn=userC,cn=userB,$base"); 70 ldap_delete($link, "cn=userA,$base"); 71 ldap_delete($link, "cn=userB,$base"); 72 ldap_delete($link, "o=test,$base"); 73} 74?> 75