Skip to content

Commit

Permalink
test(Group LDAP): add test for getting groups of OfflineUser
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Oct 9, 2023
1 parent cb3faad commit 9e2d9d5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions apps/user_ldap/tests/Group_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
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;

Expand All @@ -49,6 +52,14 @@
* @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();
Expand Down Expand Up @@ -923,6 +934,40 @@ public function testGetUserGroupsMemberOfDisabled() {
$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],
Expand Down

0 comments on commit 9e2d9d5

Please sign in to comment.