From 20d3ae4f80cf31a3e8c33e407a8a10467dfafce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sat, 26 Oct 2024 08:14:27 +0200 Subject: [PATCH] test(IT): Test Ldap Dave use cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../Controllers/ConfigLdap/SaveController.php | 15 ++--- .../Controllers/ConfigLdap/ConfigLdapTest.php | 64 +++++++++++++++++++ 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/app/modules/web/Controllers/ConfigLdap/SaveController.php b/app/modules/web/Controllers/ConfigLdap/SaveController.php index f2ba55db..6a899fda 100644 --- a/app/modules/web/Controllers/ConfigLdap/SaveController.php +++ b/app/modules/web/Controllers/ConfigLdap/SaveController.php @@ -60,18 +60,13 @@ final class SaveController extends SimpleControllerBase $configData = $this->config->getConfigData(); $ldapEnabled = $this->request->analyzeBool('ldap_enabled', false); - $ldapDefaultGroup = $this->request->analyzeInt('ldap_defaultgroup'); - $ldapDefaultProfile = $this->request->analyzeInt('ldap_defaultprofile'); - - $ldapParams = LdapParams::fromRequest($this->request); - - if ($ldapEnabled - && !($ldapParams->getServer() || $ldapParams->getSearchBase() || $ldapParams->getBindDn()) - ) { - throw ValidationException::error(__u('Missing LDAP parameters')); - } if ($ldapEnabled) { + $ldapParams = LdapParams::fromRequest($this->request); + + $ldapDefaultGroup = $this->request->analyzeInt('ldap_defaultgroup'); + $ldapDefaultProfile = $this->request->analyzeInt('ldap_defaultprofile'); + $configData->setLdapEnabled(true); $configData->setLdapType($ldapParams->getType()->value); $configData->setLdapTlsEnabled($ldapParams->isTlsEnabled()); diff --git a/tests/SP/Modules/Web/Controllers/ConfigLdap/ConfigLdapTest.php b/tests/SP/Modules/Web/Controllers/ConfigLdap/ConfigLdapTest.php index 55509290..a46a7124 100644 --- a/tests/SP/Modules/Web/Controllers/ConfigLdap/ConfigLdapTest.php +++ b/tests/SP/Modules/Web/Controllers/ConfigLdap/ConfigLdapTest.php @@ -245,6 +245,70 @@ class ConfigLdapTest extends IntegrationTestCase IntegrationTestCase::runApp($container); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws Exception + */ + #[Test] + public function save() + { + $data = [ + 'ldap_enabled' => true, + 'ldap_server' => self::$faker->domainName(), + 'ldap_server_type' => 1, + 'ldap_binduser' => self::$faker->userName(), + 'ldap_bindpass' => self::$faker->password(), + 'ldap_base' => 'dc=test', + 'ldap_group' => 'cn=group,dc=test', + 'ldap_tls_enabled' => self::$faker->boolean(), + 'ldap_defaultgroup' => 100, + 'ldap_defaultprofile' => 200, + 'ldap_filter_user_object' => 'a_filter', + 'ldap_filter_group_object' => 'a_filter', + 'ldap_filter_user_attributes' => 'a_filter', + 'ldap_filter_group_attributes' => 'a_filter', + 'ldap_database_enabled' => self::$faker->boolean(), + ]; + + $container = $this->buildContainer( + IntegrationTestCase::buildRequest('post', 'index.php', ['r' => 'configLdap/save'], $data) + ); + + $this->expectOutputString('{"status":"OK","description":"Configuration updated","data":null}'); + + IntegrationTestCase::runApp($container); + } + + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws Exception + */ + #[Test] + public function saveWithNoChanges() + { + $data = [ + 'ldap_enabled' => false + ]; + + $container = $this->buildContainer( + IntegrationTestCase::buildRequest('post', 'index.php', ['r' => 'configLdap/save'], $data) + ); + + $this->expectOutputString('{"status":"OK","description":"Configuration updated","data":null}'); + + IntegrationTestCase::runApp($container); + } + + protected function getConfigData(): array + { + $configData = parent::getConfigData(); + $configData['isLdapEnabled'] = true; + + return $configData; + } + /** * @param string $output * @return void