diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-10-26 14:44:15 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-10-26 16:05:28 +0100 |
commit | fd1fd5afa4712166cbb136d4df197bf7e37545af (patch) | |
tree | 7dcf7f64c5e3b409e5c5fc40681965a42a4d47b9 /apps/user_ldap/tests | |
parent | 951887e922bfc47613f0cfda5e7798df2b4286d6 (diff) | |
download | nextcloud-server-fd1fd5afa4712166cbb136d4df197bf7e37545af.tar.gz nextcloud-server-fd1fd5afa4712166cbb136d4df197bf7e37545af.zip |
user share manager to determine share ownership
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/AccessTest.php | 9 | ||||
-rw-r--r-- | apps/user_ldap/tests/Integration/AbstractIntegrationTest.php | 5 | ||||
-rw-r--r-- | apps/user_ldap/tests/Jobs/CleanUpTest.php | 2 | ||||
-rw-r--r-- | apps/user_ldap/tests/Jobs/SyncTest.php | 3 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/DeletedUsersIndexTest.php | 6 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/ManagerTest.php | 11 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/OfflineUserTest.php | 50 | ||||
-rw-r--r-- | apps/user_ldap/tests/User_LDAPTest.php | 2 |
8 files changed, 46 insertions, 42 deletions
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index d01cd80b3a0..4f89fc51568 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -48,10 +48,10 @@ use OCA\User_LDAP\User\OfflineUser; use OCA\User_LDAP\User\User; use OCP\IAvatarManager; use OCP\IConfig; -use OCP\IDBConnection; use OCP\Image; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; +use OCP\Share\IManager; use Test\TestCase; /** @@ -64,6 +64,8 @@ use Test\TestCase; class AccessTest extends TestCase { /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */ protected $userMapper; + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $shareManager; /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */ private $connection; /** @var LDAP|\PHPUnit\Framework\MockObject\MockObject */ @@ -87,6 +89,7 @@ class AccessTest extends TestCase { $this->config = $this->createMock(IConfig::class); $this->userMapper = $this->createMock(UserMapping::class); $this->ncUserManager = $this->createMock(IUserManager::class); + $this->shareManager = $this->createMock(IManager::class); $this->access = new Access( $this->connection, @@ -111,9 +114,9 @@ class AccessTest extends TestCase { $this->createMock(LogWrapper::class), $this->createMock(IAvatarManager::class), $this->createMock(Image::class), - $this->createMock(IDBConnection::class), $this->createMock(IUserManager::class), - $this->createMock(INotificationManager::class)]) + $this->createMock(INotificationManager::class), + $this->shareManager]) ->getMock(); $helper = new Helper(\OC::$server->getConfig()); diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php index b94016e352d..095c61544b0 100644 --- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php +++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php @@ -37,6 +37,7 @@ use OCA\User_LDAP\LDAP; use OCA\User_LDAP\LogWrapper; use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\UserPluginManager; +use OCP\Share\IManager; abstract class AbstractIntegrationTest { /** @var LDAP */ @@ -126,9 +127,9 @@ abstract class AbstractIntegrationTest { new LogWrapper(), \OC::$server->getAvatarManager(), new \OCP\Image(), - \OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), - \OC::$server->getNotificationManager() + \OC::$server->getNotificationManager(), + \OC::$server->get(IManager::class) ); } diff --git a/apps/user_ldap/tests/Jobs/CleanUpTest.php b/apps/user_ldap/tests/Jobs/CleanUpTest.php index 533bb041f75..2e66d114755 100644 --- a/apps/user_ldap/tests/Jobs/CleanUpTest.php +++ b/apps/user_ldap/tests/Jobs/CleanUpTest.php @@ -44,7 +44,7 @@ class CleanUpTest extends TestCase { public function setUp(): void { $this->createMocks(); - $this->bgJob = new CleanUp($this->mocks['userBackend']); + $this->bgJob = new CleanUp($this->mocks['userBackend'], $this->mocks['deletedUsersIndex']); $this->bgJob->setArguments($this->mocks); } diff --git a/apps/user_ldap/tests/Jobs/SyncTest.php b/apps/user_ldap/tests/Jobs/SyncTest.php index a6a70493739..6ee186d0da4 100644 --- a/apps/user_ldap/tests/Jobs/SyncTest.php +++ b/apps/user_ldap/tests/Jobs/SyncTest.php @@ -89,7 +89,6 @@ class SyncTest extends TestCase { $this->arguments = [ 'helper' => $this->helper, 'ldapWrapper' => $this->ldapWrapper, - 'userManager' => $this->userManager, 'mapper' => $this->mapper, 'config' => $this->config, 'avatarManager' => $this->avatarManager, @@ -100,7 +99,7 @@ class SyncTest extends TestCase { 'accessFactory' => $this->accessFactory, ]; - $this->sync = new Sync(); + $this->sync = new Sync($this->userManager); } public function intervalDataProvider() { diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php index 77fdd31c173..8435078051c 100644 --- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php +++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php @@ -30,6 +30,7 @@ use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\DeletedUsersIndex; use OCP\IConfig; use OCP\IDBConnection; +use OCP\Share\IManager; /** * Class DeletedUsersIndexTest @@ -50,6 +51,8 @@ class DeletedUsersIndexTest extends \Test\TestCase { /** @var UserMapping|\PHPUnit\Framework\MockObject\MockObject */ protected $mapping; + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $shareManager; protected function setUp(): void { parent::setUp(); @@ -62,8 +65,9 @@ class DeletedUsersIndexTest extends \Test\TestCase { $this->config->deleteAppFromAllUsers('user_ldap'); $this->mapping = $this->createMock(UserMapping::class); + $this->shareManager = $this->createMock(IManager::class); - $this->dui = new DeletedUsersIndex($this->config, $this->db, $this->mapping); + $this->dui = new DeletedUsersIndex($this->config, $this->mapping, $this->shareManager); } protected function tearDown(): void { diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php index 18499da9a86..9f6d43a9a24 100644 --- a/apps/user_ldap/tests/User/ManagerTest.php +++ b/apps/user_ldap/tests/User/ManagerTest.php @@ -42,6 +42,7 @@ use OCP\IDBConnection; use OCP\Image; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; +use OCP\Share\IManager; /** * Class Test_User_Manager @@ -86,6 +87,8 @@ class ManagerTest extends \Test\TestCase { /** @var Manager */ protected $manager; + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $shareManager; protected function setUp(): void { parent::setUp(); @@ -96,11 +99,11 @@ class ManagerTest extends \Test\TestCase { $this->log = $this->createMock(LogWrapper::class); $this->avatarManager = $this->createMock(IAvatarManager::class); $this->image = $this->createMock(Image::class); - $this->dbc = $this->createMock(IDBConnection::class); $this->ncUserManager = $this->createMock(IUserManager::class); $this->notificationManager = $this->createMock(INotificationManager::class); - $this->ldapWrapper = $this->createMock(ILDAPWrapper::class); + $this->shareManager = $this->createMock(IManager::class); + $this->connection = new Connection($this->ldapWrapper, '', null); $this->access->expects($this->any()) @@ -114,9 +117,9 @@ class ManagerTest extends \Test\TestCase { $this->log, $this->avatarManager, $this->image, - $this->dbc, $this->ncUserManager, - $this->notificationManager + $this->notificationManager, + $this->shareManager ); $this->manager->setLdapAccess($this->access); diff --git a/apps/user_ldap/tests/User/OfflineUserTest.php b/apps/user_ldap/tests/User/OfflineUserTest.php index 298e1708a58..5736b2664d9 100644 --- a/apps/user_ldap/tests/User/OfflineUserTest.php +++ b/apps/user_ldap/tests/User/OfflineUserTest.php @@ -25,11 +25,11 @@ declare(strict_types=1); namespace OCA\User_LDAP\Tests\User; -use Doctrine\DBAL\Driver\Statement; use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\User\OfflineUser; use OCP\IConfig; -use OCP\IDBConnection; +use OCP\Share\IManager; +use OCP\Share\IShare; use Test\TestCase; class OfflineUserTest extends TestCase { @@ -42,53 +42,47 @@ class OfflineUserTest extends TestCase { protected $uid; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */ - protected $dbc; + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + protected $shareManager; public function setUp(): void { $this->uid = 'deborah'; $this->config = $this->createMock(IConfig::class); - $this->dbc = $this->createMock(IDBConnection::class); $this->mapping = $this->createMock(UserMapping::class); + $this->shareManager = $this->createMock(IManager::class); $this->offlineUser = new OfflineUser( $this->uid, $this->config, - $this->dbc, - $this->mapping + $this->mapping, + $this->shareManager ); } public function shareOwnerProvider(): array { - // tests for none, one, many return [ - [ 0, 0, false], - [ 1, 0, true], - [ 0, 1, true], - [ 1, 1, true], - [ 2, 0, true], - [ 0, 2, true], - [ 2, 2, true], + [[], false], + [[IShare::TYPE_USER], true], + [[IShare::TYPE_GROUP, IShare::TYPE_LINK], true], + [[IShare::TYPE_EMAIL, IShare::TYPE_REMOTE, IShare::TYPE_CIRCLE], true], + [[IShare::TYPE_GUEST, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_ROOM], true], ]; } /** * @dataProvider shareOwnerProvider */ - public function testHasActiveShares(int $internalOwnerships, int $externalOwnerships, bool $expected) { - $queryMock = $this->createMock(Statement::class); - $queryMock->expects($this->atLeastOnce()) - ->method('execute'); - $queryMock->expects($this->atLeastOnce()) - ->method('rowCount') - ->willReturnOnConsecutiveCalls( - $internalOwnerships > 0 ? 1 : 0, - $externalOwnerships > 0 ? 1 : 0 - ); + public function testHasActiveShares(array $existingShareTypes, bool $expected) { + $shareMock = $this->createMock(IShare::class); - $this->dbc->expects($this->atLeastOnce()) - ->method('prepare') - ->willReturn($queryMock); + $this->shareManager->expects($this->atLeastOnce()) + ->method('getSharesBy') + ->willReturnCallback(function (string $uid, int $shareType) use ($existingShareTypes, $shareMock) { + if (in_array($shareType, $existingShareTypes)) { + return [$shareMock]; + } + return []; + }); $this->assertSame($expected, $this->offlineUser->getHasActiveShares()); } diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index ca9ff841ec0..6840a4c6dac 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -1410,7 +1410,7 @@ class User_LDAPTest extends TestCase { ->with($this->isInstanceOf(AbstractMapping::class), $this->anything(), $uid, $uuid, true); $this->access->expects($this->any()) ->method('getUserMapper') - ->willReturn($this->createMock(AbstractMapping::class)); + ->willReturn($this->createMock(UserMapping::class)); $this->assertEquals($this->backend->createUser($uid, $pwd),true); } |