summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/LDAPProviderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/LDAPProviderTest.php')
-rw-r--r--apps/user_ldap/tests/LDAPProviderTest.php191
1 files changed, 191 insertions, 0 deletions
diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php
index 607cf8f4293..59f51f204bf 100644
--- a/apps/user_ldap/tests/LDAPProviderTest.php
+++ b/apps/user_ldap/tests/LDAPProviderTest.php
@@ -31,8 +31,10 @@ namespace OCA\User_LDAP\Tests;
use OC\User\Manager;
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
+use OCA\User_LDAP\Group_LDAP;
use OCA\User_LDAP\IGroupLDAP;
use OCA\User_LDAP\IUserLDAP;
+use OCA\User_LDAP\User_LDAP;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ICacheFactory;
use OCP\IConfig;
@@ -697,4 +699,193 @@ class LDAPProviderTest extends \Test\TestCase {
$ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group'));
}
+
+ public function testGetMultiValueUserAttributeUserNotFound() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('User id not found in LDAP');
+
+ $userBackend = $this->createMock(User_LDAP::class);
+ $userBackend->expects(self::once())
+ ->method('userExists')
+ ->with('admin')
+ ->willReturn(false);
+ $groupBackend = $this->createMock(Group_LDAP::class);
+ $server = $this->getServerMock($userBackend, $groupBackend);
+
+ $ldapProvider = $this->getLDAPProvider($server);
+ $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias');
+ }
+
+ public function testGetMultiValueUserAttributeCacheHit() {
+ $connection = $this->createMock(Connection::class);
+ $connection->expects(self::once())
+ ->method('getFromCache')
+ ->with('admin-mailAlias')
+ ->willReturn(['aliasA@test.local', 'aliasB@test.local']);
+ $access = $this->createMock(Access::class);
+ $access->expects(self::once())
+ ->method('getConnection')
+ ->willReturn($connection);
+ $userBackend = $this->createMock(User_LDAP::class);
+ $userBackend->expects(self::once())
+ ->method('userExists')
+ ->with('admin')
+ ->willReturn(true);
+ $userBackend->expects(self::once())
+ ->method('getLDAPAccess')
+ ->willReturn($access);
+ $groupBackend = $this->createMock(Group_LDAP::class);
+ $server = $this->getServerMock($userBackend, $groupBackend);
+
+ $ldapProvider = $this->getLDAPProvider($server);
+ $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias');
+ }
+
+ public function testGetMultiValueUserAttributeLdapError() {
+ $connection = $this->createMock(Connection::class);
+ $connection->expects(self::once())
+ ->method('getFromCache')
+ ->with('admin-mailAlias')
+ ->willReturn(null);
+ $access = $this->createMock(Access::class);
+ $access->expects(self::once())
+ ->method('getConnection')
+ ->willReturn($connection);
+ $access->expects(self::once())
+ ->method('username2dn')
+ ->with('admin')
+ ->willReturn('admin');
+ $access->expects(self::once())
+ ->method('readAttribute')
+ ->with('admin', 'mailAlias')
+ ->willReturn(false);
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userBackend->method('userExists')
+ ->with('admin')
+ ->willReturn(true);
+ $userBackend->method('getLDAPAccess')
+ ->willReturn($access);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $server = $this->getServerMock($userBackend, $groupBackend);
+
+ $ldapProvider = $this->getLDAPProvider($server);
+ $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias');
+
+ self::assertCount(0, $values);
+ }
+
+ public function testGetMultiValueUserAttribute() {
+ $connection = $this->createMock(Connection::class);
+ $connection->expects(self::once())
+ ->method('getFromCache')
+ ->with('admin-mailAlias')
+ ->willReturn(null);
+ $access = $this->createMock(Access::class);
+ $access->expects(self::once())
+ ->method('getConnection')
+ ->willReturn($connection);
+ $access->expects(self::once())
+ ->method('username2dn')
+ ->with('admin')
+ ->willReturn('admin');
+ $access->expects(self::once())
+ ->method('readAttribute')
+ ->with('admin', 'mailAlias')
+ ->willReturn(['aliasA@test.local', 'aliasB@test.local']);
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userBackend->method('userExists')
+ ->with('admin')
+ ->willReturn(true);
+ $userBackend->method('getLDAPAccess')
+ ->willReturn($access);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $server = $this->getServerMock($userBackend, $groupBackend);
+
+ $ldapProvider = $this->getLDAPProvider($server);
+ $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias');
+
+ self::assertCount(2, $values);
+ }
+
+ public function testGetUserAttributeLdapError() {
+ $connection = $this->createMock(Connection::class);
+ $connection->expects(self::once())
+ ->method('getFromCache')
+ ->with('admin-mailAlias')
+ ->willReturn(null);
+ $access = $this->createMock(Access::class);
+ $access->expects(self::once())
+ ->method('getConnection')
+ ->willReturn($connection);
+ $access->expects(self::once())
+ ->method('username2dn')
+ ->with('admin')
+ ->willReturn('admin');
+ $access->expects(self::once())
+ ->method('readAttribute')
+ ->with('admin', 'mailAlias')
+ ->willReturn(false);
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userBackend->method('userExists')
+ ->with('admin')
+ ->willReturn(true);
+ $userBackend->method('getLDAPAccess')
+ ->willReturn($access);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $server = $this->getServerMock($userBackend, $groupBackend);
+
+ $ldapProvider = $this->getLDAPProvider($server);
+ $value = $ldapProvider->getUserAttribute('admin', 'mailAlias');
+
+ self::assertNull($value);
+ }
+
+ public function testGetUserAttribute() {
+ $connection = $this->createMock(Connection::class);
+ $connection->expects(self::once())
+ ->method('getFromCache')
+ ->with('admin-mailAlias')
+ ->willReturn(null);
+ $access = $this->createMock(Access::class);
+ $access->expects(self::once())
+ ->method('getConnection')
+ ->willReturn($connection);
+ $access->expects(self::once())
+ ->method('username2dn')
+ ->with('admin')
+ ->willReturn('admin');
+ $access->expects(self::once())
+ ->method('readAttribute')
+ ->with('admin', 'mailAlias')
+ ->willReturn(['aliasA@test.local', 'aliasB@test.local']);
+ $userBackend = $this->getMockBuilder(User_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userBackend->method('userExists')
+ ->with('admin')
+ ->willReturn(true);
+ $userBackend->method('getLDAPAccess')
+ ->willReturn($access);
+ $groupBackend = $this->getMockBuilder(Group_LDAP::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $server = $this->getServerMock($userBackend, $groupBackend);
+
+ $ldapProvider = $this->getLDAPProvider($server);
+ $value = $ldapProvider->getUserAttribute('admin', 'mailAlias');
+
+ self::assertEquals('aliasA@test.local', $value);
+ }
}