|
|
@ -18,12 +18,14 @@ use OCA\User_LDAP\Mapping\UserMapping; |
|
|
|
use OCA\User_LDAP\User\Manager; |
|
|
|
use OCA\User_LDAP\User\OfflineUser; |
|
|
|
use OCA\User_LDAP\User\User; |
|
|
|
use OCP\IAppConfig; |
|
|
|
use OCP\IAvatarManager; |
|
|
|
use OCP\IConfig; |
|
|
|
use OCP\Image; |
|
|
|
use OCP\IUserManager; |
|
|
|
use OCP\Notification\IManager as INotificationManager; |
|
|
|
use OCP\Share\IManager; |
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
use Test\TestCase; |
|
|
|
|
|
|
@ -53,10 +55,12 @@ class AccessTest extends TestCase { |
|
|
|
private $config; |
|
|
|
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
|
|
private $ncUserManager; |
|
|
|
/** @var LoggerInterface|MockObject */ |
|
|
|
private $logger; |
|
|
|
/** @var Access */ |
|
|
|
private $access; |
|
|
|
|
|
|
|
private LoggerInterface&MockObject $logger; |
|
|
|
|
|
|
|
private IAppConfig&MockObject $appConfig; |
|
|
|
|
|
|
|
private Access $access; |
|
|
|
|
|
|
|
protected function setUp(): void { |
|
|
|
$this->connection = $this->createMock(Connection::class); |
|
|
@ -69,28 +73,33 @@ class AccessTest extends TestCase { |
|
|
|
$this->ncUserManager = $this->createMock(IUserManager::class); |
|
|
|
$this->shareManager = $this->createMock(IManager::class); |
|
|
|
$this->logger = $this->createMock(LoggerInterface::class); |
|
|
|
$this->appConfig = $this->createMock(IAppConfig::class); |
|
|
|
|
|
|
|
$this->access = new Access( |
|
|
|
$this->connection, |
|
|
|
$this->ldap, |
|
|
|
$this->connection, |
|
|
|
$this->userManager, |
|
|
|
$this->helper, |
|
|
|
$this->config, |
|
|
|
$this->ncUserManager, |
|
|
|
$this->logger |
|
|
|
$this->logger, |
|
|
|
$this->appConfig, |
|
|
|
); |
|
|
|
$this->access->setUserMapper($this->userMapper); |
|
|
|
$this->access->setGroupMapper($this->groupMapper); |
|
|
|
} |
|
|
|
|
|
|
|
private function getConnectorAndLdapMock() { |
|
|
|
/** @var ILDAPWrapper&MockObject */ |
|
|
|
$lw = $this->createMock(ILDAPWrapper::class); |
|
|
|
/** @var Connection&MockObject */ |
|
|
|
$connector = $this->getMockBuilder(Connection::class) |
|
|
|
->setConstructorArgs([$lw, '', null]) |
|
|
|
->getMock(); |
|
|
|
$connector->expects($this->any()) |
|
|
|
->method('getConnectionResource') |
|
|
|
->willReturn(ldap_connect('ldap://example.com')); |
|
|
|
/** @var Manager&MockObject */ |
|
|
|
$um = $this->getMockBuilder(Manager::class) |
|
|
|
->setConstructorArgs([ |
|
|
|
$this->createMock(IConfig::class), |
|
|
@ -220,7 +229,7 @@ class AccessTest extends TestCase { |
|
|
|
[$lw, $con, $um, $helper] = $this->getConnectorAndLdapMock(); |
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject $config */ |
|
|
|
$config = $this->createMock(IConfig::class); |
|
|
|
$access = new Access($con, $lw, $um, $helper, $config, $this->ncUserManager, $this->logger); |
|
|
|
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig); |
|
|
|
|
|
|
|
$lw->expects($this->exactly(1)) |
|
|
|
->method('explodeDN') |
|
|
@ -243,7 +252,7 @@ class AccessTest extends TestCase { |
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject $config */ |
|
|
|
$config = $this->createMock(IConfig::class); |
|
|
|
$lw = new LDAP(); |
|
|
|
$access = new Access($con, $lw, $um, $helper, $config, $this->ncUserManager, $this->logger); |
|
|
|
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig); |
|
|
|
|
|
|
|
if (!function_exists('ldap_explode_dn')) { |
|
|
|
$this->markTestSkipped('LDAP Module not available'); |
|
|
@ -429,7 +438,7 @@ class AccessTest extends TestCase { |
|
|
|
$attribute => ['count' => 1, $dnFromServer] |
|
|
|
]); |
|
|
|
|
|
|
|
$access = new Access($con, $lw, $um, $helper, $config, $this->ncUserManager, $this->logger); |
|
|
|
$access = new Access($lw, $con, $um, $helper, $config, $this->ncUserManager, $this->logger, $this->appConfig); |
|
|
|
$values = $access->readAttribute('uid=whoever,dc=example,dc=org', $attribute); |
|
|
|
$this->assertSame($values[0], strtolower($dnFromServer)); |
|
|
|
} |
|
|
|