Commit 6d01ff8a authored by Dainis Abols's avatar Dainis Abols
Browse files

LDAPConnectionTest

parent a5993f16
<?php
declare(strict_types=1);
namespace Lu\LuAuth\Tests\Functional;
use Lu\LuAuth\Models\LDAP;
use Vendor\MyExtension\Service\AbstractSomethingService;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* Test for LDAP connection
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 21.02.2022
*/
class LDAPConnectionTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
/**
* LocalConfiguration file name and relative location
*
* @var string
*/
private $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Test connection
*
* @test
*/
public function connectionTest(): void
{
// Fetch config data
$conf = @include $this->LocalConfiguration;
// Assert configuration file fouind
$this->assertNotEmpty($conf, 'LocalConfiguration file not found ['.$this->LocalConfiguration.']');
$conf = @$conf['EXTENSIONS']['lu_auth'];
// Assert LDAP configured
$this->assertNotEmpty($conf['ldapServer'], 'LDAP Server not configured');
$this->assertNotEmpty($conf['ldapDC'], 'LDAP DC not configured');
// Assert connection
$ldap = new LDAP($conf['ldapServer'], $conf['ldapDC']);
$this->assertIsResource($ldap->getConn(), 'LDAP Resource not created');
// Assert test user configured
$this->assertNotEmpty($conf['ldapTestUser'], 'LDAP Test user not configured');
$this->assertNotEmpty($conf['ldapTestPass'], 'LDAP Test pass not configured');
// Assert user check
$user = $ldap->authorize($conf['ldapTestUser'], $conf['ldapTestPass']);
$this->assertIsArray($user, 'LDAP User data not received');
$this->assertNotEmpty($user, 'LDAP User data is empty');
// Assert clear
$ldap->delConn();
$this->assertNull($ldap->getConn(), 'LDAP Resource not cleared');
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment