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