diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-06-09 00:01:38 +0300 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2022-06-09 00:01:38 +0300 |
commit | de93d1722b6e5c17c3699246204a761aa16b0ebd (patch) | |
tree | 170a7ae1562d8fd9e14bcd9bf521f0f17f285fd4 | |
parent | 32cab8102f24fdd2b552a9e7f6f514c6944d12dc (diff) |
Fix encryption util tests for files_externalbugfix/noid/risky-test-without-assertion
Don't rely on files_external being enabled and mock all the classes from
it.
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
-rw-r--r-- | lib/private/Encryption/Util.php | 4 | ||||
-rw-r--r-- | tests/lib/Encryption/UtilTest.php | 29 |
2 files changed, 27 insertions, 6 deletions
diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index 174af2e8b89..541a4ed24f5 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -37,6 +37,7 @@ use OCA\Files_External\Service\GlobalStoragesService; use OCP\Encryption\IEncryptionModule; use OCP\IConfig; use OCP\IUser; +use OCP\App\IAppManager; class Util { public const HEADER_START = 'HBEGIN'; @@ -299,7 +300,8 @@ class Util { * @return boolean */ public function isSystemWideMountPoint($path, $uid) { - if (\OCP\App::isEnabled("files_external")) { + $appManager = \OC::$server->get(IAppManager::class); + if ($appManager->isEnabledForUser('files_external', null)) { /** @var GlobalStoragesService $storageService */ $storageService = \OC::$server->get(GlobalStoragesService::class); $storages = $storageService->getAllStorages(); diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index 7f7fc862aac..ab6101b7027 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -4,8 +4,7 @@ namespace Test\Encryption; use OC\Encryption\Util; use OC\Files\View; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\Service\GlobalStoragesService; +use OCP\App\IAppManager; use OCP\Encryption\IEncryptionModule; use OCP\IConfig; use Test\TestCase; @@ -207,6 +206,15 @@ class UtilTest extends TestCase { * @dataProvider dataTestIsSystemWideMountPoint */ public function testIsSystemWideMountPoint($expectedResult, $expectationText, $applicableUsers, $applicableGroups, $mountPointName = '/mp') { + $appManager = $this->createMock(IAppManager::class); + $appManager + ->expects($this->once()) + ->method('isEnabledForUser') + ->with('files_external') + ->willReturn(true); + + $this->overwriteService(IAppManager::class, $appManager); + $this->groupManager->method('isInGroup') ->will($this->returnValueMap([ ['user1', 'group1', true], // user is only in group1 @@ -215,17 +223,28 @@ class UtilTest extends TestCase { $storages = []; - $storageConfig = $this->createMock(StorageConfig::class); + // StorageConfig + $storageConfig = $this->getMockBuilder('OCA\\Files_External\\Lib\\StorageConfig') + ->setMethods([ + 'getMountPoint', + 'getApplicableUsers', + 'getApplicableGroups', + ]) + ->getMock(); $storageConfig->method('getMountPoint')->willReturn($mountPointName); $storageConfig->method('getApplicableUsers')->willReturn($applicableUsers); $storageConfig->method('getApplicableGroups')->willReturn($applicableGroups); $storages[] = $storageConfig; - $storagesServiceMock = $this->createMock(GlobalStoragesService::class); + $storagesServiceMock = $this->getMockBuilder('OCA\\Files_External\\Service\\GlobalStoragesService') + ->setMethods([ + 'getAllStorages', + ]) + ->getMock(); $storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages') ->willReturn($storages); - $this->overwriteService(GlobalStoragesService::class, $storagesServiceMock); + $this->overwriteService('OCA\\Files_External\\Service\\GlobalStoragesService', $storagesServiceMock); $this->assertEquals($expectedResult, $this->util->isSystemWideMountPoint('/files/mp', 'user1'), 'Test case: ' . $expectationText); } |