-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Coutadeur
committed
Apr 24, 2024
1 parent
65c7c80
commit b9e97e8
Showing
2 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,13 +100,13 @@ public function test_ldap_get_first_available_value(): void | |
|
||
# Test ldap_get_first_available_value | ||
$ent = Ltb\AttributeValue::ldap_get_first_available_value($ldap, $entry, $this->attributes); | ||
$this->assertEquals($ent->attribute, "cn", "not getting attribute cn"); | ||
$this->assertEquals($ent->value, "test1", "not getting value test1 as cn first value"); | ||
$this->assertEquals("cn", $ent->attribute, "not getting attribute cn"); | ||
$this->assertEquals("test1", $ent->value, "not getting value test1 as cn first value"); | ||
} | ||
|
||
public function test_ldap_get_mail_for_notification(): void | ||
{ | ||
|
||
$mail_attributes = array("mail"); | ||
|
||
$ldap = ldap_connect($this->host); | ||
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
|
@@ -119,15 +119,25 @@ public function test_ldap_get_mail_for_notification(): void | |
$entry = ldap_first_entry($ldap, $sr); | ||
|
||
# Test ldap_get_first_available_value | ||
$mail = Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry); | ||
$this->assertEquals($mail, '[email protected]', "not getting [email protected] as mail for notification"); | ||
$mail = Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry, $mail_attributes); | ||
$this->assertEquals('[email protected]', $mail, "not getting [email protected] as mail for notification"); | ||
|
||
} | ||
|
||
public function test_connect(): void | ||
{ | ||
|
||
list($ldap, $msg) = Ltb\Ldap::connect($this->host, false, $this->managerDN, $this->managerPW, 10, null); | ||
$ldapInstance = new \Ltb\Ldap( | ||
$this->host, | ||
false, | ||
$this->managerDN, | ||
$this->managerPW, | ||
10, | ||
null, | ||
null, | ||
null | ||
); | ||
list($ldap, $msg) = $ldapInstance->connect(); | ||
|
||
$this->assertNotFalse($ldap, "Error while connecting to LDAP server"); | ||
$this->assertFalse($msg, "Error message returned while connecting to LDAP server"); | ||
|
@@ -136,17 +146,24 @@ public function test_connect(): void | |
public function test_get_list(): void | ||
{ | ||
|
||
$ldap = ldap_connect($this->host); | ||
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); | ||
$ldapInstance = new \Ltb\Ldap( | ||
$this->host, | ||
false, | ||
$this->managerDN, | ||
$this->managerPW, | ||
10, | ||
$this->user_branch, | ||
0, | ||
null | ||
); | ||
|
||
// binding to ldap server | ||
$ldapbind = ldap_bind($ldap, $this->managerDN, $this->managerPW); | ||
list($ldap, $msg) = $ldapInstance->connect(); | ||
|
||
// return hashmap: [ cn_value => sn_value ] | ||
$result = Ltb\Ldap::get_list($ldap, $this->user_branch, "(uid=test)", "cn","sn"); | ||
$result = $ldapInstance->get_list($this->user_branch, "(uid=test)", "cn","sn"); | ||
|
||
$this->assertEquals(array_keys($result)[0], 'test1', "not getting test1 as key in get_list function"); | ||
$this->assertEquals($result["test1"], 'test', "not getting test as value in get_list function"); | ||
$this->assertEquals('test1', array_keys($result)[0], "not getting test1 as key in get_list function"); | ||
$this->assertEquals('test', $result["test1"], "not getting test as value in get_list function"); | ||
|
||
} | ||
|
||
|