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