diff --git a/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php b/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php index f5f64142..7a4dcb3c 100644 --- a/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php +++ b/app/modules/web/Controllers/Helpers/Grid/PluginGrid.php @@ -69,12 +69,6 @@ final class PluginGrid extends GridBase $grid->addDataAction($this->getDisableAction()); $grid->addDataAction($this->getResetAction()); $grid->addDataAction($this->getDeleteAction()); - $grid->addDataAction( - $this->getDeleteAction() - ->setName(__('Delete Selected')) - ->setTitle(__('Delete Selected')) - ->setIsSelection(true), - true); $grid->setTime(round(getElapsedTime($this->queryTimeStart), 5)); diff --git a/lib/SP/Providers/Auth/Ldap/LdapConnection.php b/lib/SP/Providers/Auth/Ldap/LdapConnection.php index f9450148..b857d537 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapConnection.php +++ b/lib/SP/Providers/Auth/Ldap/LdapConnection.php @@ -136,7 +136,7 @@ final class LdapConnection implements LdapConnectionInterface @ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7); } - $this->ldapHandler = @ldap_connect($this->getServer(), $this->ldapParams->getPort()); + $this->ldapHandler = @ldap_connect($this->getServerUri()); // Conexión al servidor LDAP if (!is_resource($this->ldapHandler)) { @@ -165,9 +165,9 @@ final class LdapConnection implements LdapConnectionInterface */ public function checkParams() { - if (!$this->ldapParams->getSearchBase() - || !$this->getServer() - || !$this->ldapParams->getBindDn() + if (empty($this->ldapParams->getSearchBase()) + || empty($this->getServer()) + || empty($this->ldapParams->getBindDn()) ) { $this->eventDispatcher->notifyEvent('ldap.check.params', new Event($this, EventMessage::factory() @@ -197,6 +197,25 @@ final class LdapConnection implements LdapConnectionInterface return $this; } + /** + * @inheritDoc + */ + public function getServerUri(): string + { + $server = $this->getServer(); + $port = $this->ldapParams->getPort(); + + if (strpos($server, '://') !== false) { + return $server . ':' . $port; + } elseif ($port === 389 || $port === null) { + return 'ldap://' . $server; + } elseif ($port === 636) { + return 'ldaps://' . $server; + } + + return 'ldap://' . $server . ':' . $port; + } + /** * Connect through TLS * diff --git a/tests/SP/Providers/Auth/Ldap/LdapConnectionTest.php b/tests/SP/Providers/Auth/Ldap/LdapConnectionTest.php new file mode 100644 index 00000000..b3bae92d --- /dev/null +++ b/tests/SP/Providers/Auth/Ldap/LdapConnectionTest.php @@ -0,0 +1,150 @@ +. + */ + +namespace SP\Tests\Providers\Auth\Ldap; + +use PHPUnit\Framework\TestCase; +use SP\Core\Events\EventDispatcher; +use SP\Providers\Auth\Ldap\LdapConnection; +use SP\Providers\Auth\Ldap\LdapException; +use SP\Providers\Auth\Ldap\LdapParams; +use SP\Providers\Auth\Ldap\LdapTypeInterface; + +/** + * Class LdapConnectionTest + * + * @package SP\Tests\Providers\Auth\Ldap + */ +class LdapConnectionTest extends TestCase +{ + /** + * @throws LdapException + */ + public function testCheckParams() + { + $ldapConnection = $this->getLdapConnection(); + + $ldapConnection->checkParams(); + + $this->assertTrue(true); + } + + /** + * @param LdapParams|null $params + * + * @return LdapConnection + */ + public function getLdapConnection(LdapParams $params = null) + { + $ev = new EventDispatcher(); + + if ($params === null) { + $params = new LdapParams(); + $params->setServer('test.example.com'); + $params->setPort(10389); + $params->setBindDn('cn=test,dc=example,dc=com'); + $params->setBindPass('testpass'); + $params->setGroup('cn=Test Group,ou=Groups,dc=example,dc=con'); + $params->setSearchBase('dc=example,dc=com'); + $params->setTlsEnabled(true); + $params->setType(LdapTypeInterface::LDAP_STD); + } + + return new LdapConnection($params, $ev); + } + + /** + * @throws LdapException + */ + public function testCheckParamsNoSearchBase() + { + $ldapConnection = $this->getLdapConnection(); + + $params = $ldapConnection->getLdapParams(); + $params->setSearchBase(''); + + $this->expectException(LdapException::class); + $ldapConnection->checkParams(); + } + + /** + * @throws LdapException + */ + public function testCheckParamsNoServer() + { + $ldapConnection = $this->getLdapConnection(); + + $params = $ldapConnection->getLdapParams(); + $params->setServer(''); + + $this->expectException(LdapException::class); + $ldapConnection->checkParams(); + } + + /** + * @throws LdapException + */ + public function testCheckParamsNoBindDn() + { + $ldapConnection = $this->getLdapConnection(); + + $params = $ldapConnection->getLdapParams(); + $params->setBindDn(''); + + $this->expectException(LdapException::class); + $ldapConnection->checkParams(); + } + + public function testGetServerUri() + { + $ldapConnection = $this->getLdapConnection(); + + $this->assertEquals('ldap://test.example.com:10389', $ldapConnection->getServerUri()); + } + + public function testGetServerUriNoSchema() + { + $ldapConnection = $this->getLdapConnection(); + + $params = $ldapConnection->getLdapParams(); + $params->setServer('test.example.com'); + $params->setPort(389); + + $this->assertEquals('ldap://test.example.com', $ldapConnection->getServerUri()); + + $params->setPort(10389); + $this->assertEquals('ldap://test.example.com:10389', $ldapConnection->getServerUri()); + } + + public function testGetServerUriLdaps() + { + $ldapConnection = $this->getLdapConnection(); + + $params = $ldapConnection->getLdapParams(); + $params->setServer('ldaps://test.example.com'); + $params->setPort(10636); + + $this->assertEquals('ldaps://test.example.com:10636', $ldapConnection->getServerUri()); + } +}