Skip to content

Commit

Permalink
fix Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Apr 24, 2024
1 parent 65c7c80 commit 5dcd8cd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
16 changes: 8 additions & 8 deletions runIntegrationTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $CTN run \
--network-alias=ltb-directory-server \
-p 127.0.0.1:33389:33389 \
--name=ltb-directory-server \
--detach=true \
--detach=false \
$UIDMAP \
$GIDMAP \
gitlab.ow2.org:4567/fusioniam/fusioniam/fusioniam-openldap-ltb:snapshot
Expand All @@ -49,11 +49,11 @@ do
done


# Run tests
echo "Starting tests"
vendor/bin/phpunit tests/IntegrationTests

# Stop and remove openldap container and volumes
$CTN stop ltb-directory-server
rm -rf run/volumes
## Run tests
#echo "Starting tests"
#vendor/bin/phpunit tests/IntegrationTests
#
## Stop and remove openldap container and volumes
#$CTN stop ltb-directory-server
#rm -rf run/volumes

2 changes: 1 addition & 1 deletion src/Ltb/AttributeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function ldap_get_first_available_value($ldap, $entry, $attributes
return false;
}

/** function \Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry) {
/** function \Ltb\AttributeValue::ldap_get_mail_for_notification($ldap, $entry, $mail_attributes) {
* Get from ldap entry first value corresponding to $mail_attributes (globally configured)
* @param $ldap php_ldap connection object
* @param $entry ldap entry to parse
Expand Down
43 changes: 30 additions & 13 deletions tests/IntegrationTests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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");

}

Expand Down

0 comments on commit 5dcd8cd

Please sign in to comment.