diff --git a/tests/acceptance/bootstrap/Provisioning.php b/tests/acceptance/bootstrap/Provisioning.php index 2a9d08fb6ec..dfb4bb9c775 100644 --- a/tests/acceptance/bootstrap/Provisioning.php +++ b/tests/acceptance/bootstrap/Provisioning.php @@ -48,6 +48,7 @@ trait Provisioning { private array $createdGroups = []; private array $userTokens = []; private array $createdKeycloakUsers = []; + private ?Ldap $idmLdap = null; /** * @param array $user @@ -364,8 +365,7 @@ trait Provisioning { 'baseDn' => $this->ldapBaseDN, 'username' => $this->ldapAdminUser, ]; - $this->ldap = new Ldap($options); - $this->ldap->bind(); + $this->ldap = $this->bindLdap($options); $ldifFile = __DIR__ . $suiteParameters['ldapInitialUserFilePath']; if (!$this->skipImportLdif) { @@ -379,6 +379,78 @@ trait Provisioning { } } + /** + * Connects to the LDAP server bundled with oCIS (IDM) to allow direct + * inspection of entries that oCIS services write, e.g. the objectClass + * that the graph service sets on group entries. Connection parameters + * match the IDM defaults used by the acceptance test environment. + * + * @return void + */ + private function connectToIdm(): void { + if ($this->idmLdap !== null) { + return; + } + \putenv('LDAPTLS_REQCERT=never'); + $idmHost = ''; + $hostSourceEnvs = ['TEST_SERVER_URL', 'OCIS_WRAPPER_URL']; + foreach ($hostSourceEnvs as $envName) { + $envValue = \getenv($envName); + if ($envValue !== false && $envValue !== '') { + $idmHost = \parse_url($envValue, PHP_URL_HOST) ?: $envValue; + break; + } + } + $options = [ + 'host' => $idmHost ?: '127.0.0.1', + 'port' => 9235, + 'useSsl' => true, + 'baseDn' => 'o=libregraph-idm', + 'bindRequiresDn' => true, + 'username' => 'uid=admin,ou=users,o=libregraph-idm', + 'password' => \getenv('IDM_ADMIN_PASSWORD') ?: 'admin', + ]; + $this->idmLdap = $this->bindLdap($options); + } + + /** + * Creates a bound Ldap connection from the given options. + * + * @param array $options + * + * @return Ldap + */ + private function bindLdap(array $options): Ldap { + $ldap = new Ldap($options); + $ldap->bind(); + return $ldap; + } + + /** + * @Then /^the LDAP entry "([^"]*)" should (not|)\s?have the object class "([^"]*)"$/ + * + * @param string $dn + * @param string $shouldOrNot (not|) + * @param string $objectClass + * + * @return void + */ + public function theLdapEntryShouldHaveObjectClass(string $dn, string $shouldOrNot, string $objectClass): void { + $this->connectToIdm(); + $entry = $this->idmLdap->getEntry($dn); + Assert::assertNotNull($entry, "LDAP entry '$dn' does not exist"); + $objectClasses = \array_map('strtolower', Laminas\Ldap\Attribute::getAttribute($entry, 'objectClass')); + $shouldHave = ($shouldOrNot !== "not"); + $message = "Expected LDAP entry '$dn' to " + . ($shouldHave ? 'have' : 'not have') + . " the object class '$objectClass', but the entry has: " + . \implode(', ', $objectClasses); + Assert::assertTrue( + \in_array(\strtolower($objectClass), $objectClasses, true) === $shouldHave, + $message, + ); + } + /** * prepares a suitable nested array with user-attributes for multiple users to be created * diff --git a/tests/acceptance/features/apiGraphGroup/createGroup.feature b/tests/acceptance/features/apiGraphGroup/createGroup.feature index b1b2c2a82b9..caf085a95a7 100644 --- a/tests/acceptance/features/apiGraphGroup/createGroup.feature +++ b/tests/acceptance/features/apiGraphGroup/createGroup.feature @@ -47,3 +47,11 @@ Feature: create group Scenario: admin user tries to create a group that is the empty string When user "Alice" tries to create a group "" using the Graph API Then the HTTP status code should be "400" + + @env-config @issue-11775 + Scenario: admin creates a group with the configured LDAP group object class + Given the config "OCIS_LDAP_GROUP_OBJECTCLASS" has been set to "groupOfUniqueNames" for "graph" service + When the administrator creates a group "uniquegroup" using the Graph API + Then the HTTP status code should be "201" + And the LDAP entry "cn=uniquegroup,ou=groups,o=libregraph-idm" should have the object class "groupOfUniqueNames" + And the LDAP entry "cn=uniquegroup,ou=groups,o=libregraph-idm" should not have the object class "groupOfNames"