summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-10-09 21:08:28 +0200
committerJulius Härtl <jus@bitgrid.net>2023-10-30 10:24:02 +0100
commit78792023094fcd18bd8bd401358292bf882e9a08 (patch)
treed8bd78df3bd22f98fc30b4f3a271098a1a657a8a /apps/user_ldap
parente178815b83aa5f05b2fee559499a82b00a4f3008 (diff)
downloadnextcloud-server-78792023094fcd18bd8bd401358292bf882e9a08.tar.gz
nextcloud-server-78792023094fcd18bd8bd401358292bf882e9a08.zip
test(Group LDAP): add test for getting groups of OfflineUser
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index edcb4be8819..2eef5f94d74 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -37,7 +37,10 @@ use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\User\Manager;
+use OCA\User_LDAP\User\OfflineUser;
use OCP\GroupInterface;
+use OCP\IConfig;
+use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -49,6 +52,14 @@ use Test\TestCase;
* @package OCA\User_LDAP\Tests
*/
class Group_LDAPTest extends TestCase {
+
+ public function tearDown(): void {
+ parent::tearDown();
+
+ $realConfig = Server::get(IConfig::class);
+ $realConfig->deleteUserValue('userX', 'user_ldap', 'cached-group-memberships-');
+ }
+
public function testCountEmptySearchString() {
$access = $this->getAccessMock();
$pluginManager = $this->getPluginManagerMock();
@@ -923,6 +934,40 @@ class Group_LDAPTest extends TestCase {
$groupBackend->getUserGroups('userX');
}
+ public function testGetUserGroupsOfflineUser() {
+ $access = $this->getAccessMock();
+ $pluginManager = $this->getPluginManagerMock();
+
+ $access->connection = $this->createMock(Connection::class);
+ $access->connection->expects($this->any())
+ ->method('__get')
+ ->willReturnCallback(function ($name) {
+ if ($name === 'useMemberOfToDetectMembership') {
+ return 0;
+ } elseif ($name === 'ldapDynamicGroupMemberURL') {
+ return '';
+ }
+ return 1;
+ });
+
+ $offlineUser = $this->createMock(OfflineUser::class);
+
+ // FIXME: should be available via CI
+ $realConfig = Server::get(IConfig::class);
+ $realConfig->setUserValue('userX', 'user_ldap', 'cached-group-memberships-', \json_encode(['groupB', 'groupF']));
+
+ $access->userManager->expects($this->any())
+ ->method('get')
+ ->with('userX')
+ ->willReturn($offlineUser);
+
+ $groupBackend = new GroupLDAP($access, $pluginManager);
+ $returnedGroups = $groupBackend->getUserGroups('userX');
+ $this->assertCount(2, $returnedGroups);
+ $this->assertTrue(in_array('groupB', $returnedGroups));
+ $this->assertTrue(in_array('groupF', $returnedGroups));
+ }
+
public function nestedGroupsProvider(): array {
return [
[true],