diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-06-29 15:41:40 +0200 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2023-08-08 09:14:16 +0200 |
commit | 1e06b61f591d74bfaa554578e2ca647d915fcb8f (patch) | |
tree | 8c73bf57a5552dd05a0b8fabcbc3b87eb38d81c0 /apps/encryption/tests | |
parent | d7e2813eca2da348fde85472e7b9fcb9b4843a93 (diff) | |
download | nextcloud-server-1e06b61f591d74bfaa554578e2ca647d915fcb8f.tar.gz nextcloud-server-1e06b61f591d74bfaa554578e2ca647d915fcb8f.zip |
Migrate away from ILogger in encryption
And modernize code a bit
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r-- | apps/encryption/tests/Command/FixEncryptedVersionTest.php | 3 | ||||
-rw-r--r-- | apps/encryption/tests/Crypto/CryptTest.php | 6 | ||||
-rw-r--r-- | apps/encryption/tests/Crypto/EncryptionTest.php | 6 | ||||
-rw-r--r-- | apps/encryption/tests/Hooks/UserHooksTest.php | 5 | ||||
-rw-r--r-- | apps/encryption/tests/KeyManagerTest.php | 12 | ||||
-rw-r--r-- | apps/encryption/tests/Settings/AdminTest.php | 6 | ||||
-rw-r--r-- | apps/encryption/tests/UtilTest.php | 5 |
7 files changed, 23 insertions, 20 deletions
diff --git a/apps/encryption/tests/Command/FixEncryptedVersionTest.php b/apps/encryption/tests/Command/FixEncryptedVersionTest.php index 2a6c86ef5b2..54e8b41ed6c 100644 --- a/apps/encryption/tests/Command/FixEncryptedVersionTest.php +++ b/apps/encryption/tests/Command/FixEncryptedVersionTest.php @@ -24,6 +24,7 @@ namespace OCA\Encryption\Tests\Command; use OC\Files\View; use OCA\Encryption\Command\FixEncryptedVersion; use OCA\Encryption\Util; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Tester\CommandTester; use Test\TestCase; use Test\Traits\EncryptionTrait; @@ -70,7 +71,7 @@ class FixEncryptedVersionTest extends TestCase { $this->fixEncryptedVersion = new FixEncryptedVersion( \OC::$server->getConfig(), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), \OC::$server->getRootFolder(), \OC::$server->getUserManager(), $this->util, diff --git a/apps/encryption/tests/Crypto/CryptTest.php b/apps/encryption/tests/Crypto/CryptTest.php index 0bb2c652d8b..06caa5aba1a 100644 --- a/apps/encryption/tests/Crypto/CryptTest.php +++ b/apps/encryption/tests/Crypto/CryptTest.php @@ -29,12 +29,12 @@ namespace OCA\Encryption\Tests\Crypto; use OCA\Encryption\Crypto\Crypt; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use OCP\IUserSession; use Test\TestCase; class CryptTest extends TestCase { - /** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject */ @@ -52,7 +52,7 @@ class CryptTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->logger = $this->getMockBuilder(ILogger::class) + $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->logger->expects($this->any()) diff --git a/apps/encryption/tests/Crypto/EncryptionTest.php b/apps/encryption/tests/Crypto/EncryptionTest.php index 675a8bf8e29..115b9054278 100644 --- a/apps/encryption/tests/Crypto/EncryptionTest.php +++ b/apps/encryption/tests/Crypto/EncryptionTest.php @@ -36,7 +36,7 @@ use OCA\Encryption\Session; use OCA\Encryption\Util; use OCP\Files\Storage; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; @@ -63,7 +63,7 @@ class EncryptionTest extends TestCase { /** @var \OCA\Encryption\Util|\PHPUnit\Framework\MockObject\MockObject */ private $utilMock; - /** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $loggerMock; /** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */ @@ -95,7 +95,7 @@ class EncryptionTest extends TestCase { $this->decryptAllMock = $this->getMockBuilder(DecryptAll::class) ->disableOriginalConstructor() ->getMock(); - $this->loggerMock = $this->getMockBuilder(ILogger::class) + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->l10nMock = $this->getMockBuilder(IL10N::class) diff --git a/apps/encryption/tests/Hooks/UserHooksTest.php b/apps/encryption/tests/Hooks/UserHooksTest.php index e06feb1e370..add7e375f04 100644 --- a/apps/encryption/tests/Hooks/UserHooksTest.php +++ b/apps/encryption/tests/Hooks/UserHooksTest.php @@ -34,7 +34,7 @@ use OCA\Encryption\Recovery; use OCA\Encryption\Session; use OCA\Encryption\Users\Setup; use OCA\Encryption\Util; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -160,7 +160,6 @@ class UserHooksTest extends TestCase { * @dataProvider dataTestPreSetPassphrase */ public function testPreSetPassphrase($canChange) { - /** @var UserHooks | \PHPUnit\Framework\MockObject\MockObject $instance */ $instance = $this->getMockBuilder(UserHooks::class) ->setConstructorArgs( @@ -332,7 +331,7 @@ class UserHooksTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->loggerMock = $this->createMock(ILogger::class); + $this->loggerMock = $this->createMock(LoggerInterface::class); $this->keyManagerMock = $this->getMockBuilder(KeyManager::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/encryption/tests/KeyManagerTest.php b/apps/encryption/tests/KeyManagerTest.php index be116318185..89956b7558c 100644 --- a/apps/encryption/tests/KeyManagerTest.php +++ b/apps/encryption/tests/KeyManagerTest.php @@ -41,7 +41,7 @@ use OCP\Encryption\Keys\IStorage; use OCP\Files\Cache\ICache; use OCP\Files\Storage; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use OCP\IUserSession; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; @@ -73,7 +73,7 @@ class KeyManagerTest extends TestCase { /** @var \OCA\Encryption\Session|\PHPUnit\Framework\MockObject\MockObject */ private $sessionMock; - /** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logMock; /** @var \OCA\Encryption\Util|\PHPUnit\Framework\MockObject\MockObject */ @@ -101,7 +101,7 @@ class KeyManagerTest extends TestCase { $this->sessionMock = $this->getMockBuilder(Session::class) ->disableOriginalConstructor() ->getMock(); - $this->logMock = $this->createMock(ILogger::class); + $this->logMock = $this->createMock(LoggerInterface::class); $this->utilMock = $this->getMockBuilder(Util::class) ->disableOriginalConstructor() ->getMock(); @@ -600,6 +600,9 @@ class KeyManagerTest extends TestCase { )->setMethods(['getPublicMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword']) ->getMock(); + $this->utilMock->expects($this->once())->method('isMasterKeyEnabled') + ->willReturn(true); + $instance->expects($this->once())->method('getPublicMasterKey') ->willReturn($masterKey); @@ -645,6 +648,9 @@ class KeyManagerTest extends TestCase { )->setMethods(['getPublicMasterKey', 'getPrivateMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword']) ->getMock(); + $this->utilMock->expects($this->once())->method('isMasterKeyEnabled') + ->willReturn(true); + $instance->expects($this->once())->method('getPublicMasterKey') ->willReturn(''); $instance->expects($this->once())->method('getPrivateMasterKey') diff --git a/apps/encryption/tests/Settings/AdminTest.php b/apps/encryption/tests/Settings/AdminTest.php index e4b2933dd3b..055b65e2e28 100644 --- a/apps/encryption/tests/Settings/AdminTest.php +++ b/apps/encryption/tests/Settings/AdminTest.php @@ -29,7 +29,7 @@ use OCA\Encryption\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use OCP\ISession; use OCP\IUserManager; use OCP\IUserSession; @@ -40,7 +40,7 @@ class AdminTest extends TestCase { private $admin; /** @var IL10N */ private $l; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; /** @var IUserSession */ private $userSession; @@ -55,7 +55,7 @@ class AdminTest extends TestCase { parent::setUp(); $this->l = $this->getMockBuilder(IL10N::class)->getMock(); - $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); + $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $this->userSession = $this->getMockBuilder(IUserSession::class)->getMock(); $this->config = $this->getMockBuilder(IConfig::class)->getMock(); $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); diff --git a/apps/encryption/tests/UtilTest.php b/apps/encryption/tests/UtilTest.php index 9d5d93809bc..3c3a8ba371a 100644 --- a/apps/encryption/tests/UtilTest.php +++ b/apps/encryption/tests/UtilTest.php @@ -33,7 +33,6 @@ use OCA\Encryption\Util; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage; use OCP\IConfig; -use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -89,8 +88,6 @@ class UtilTest extends TestCase { $cryptMock = $this->getMockBuilder(Crypt::class) ->disableOriginalConstructor() ->getMock(); - /** @var \OCP\ILogger $loggerMock */ - $loggerMock = $this->createMock(ILogger::class); $user = $this->createMock(IUser::class); $user->expects($this->any()) @@ -116,7 +113,7 @@ class UtilTest extends TestCase { ->method('setUserValue') ->willReturnCallback([$this, 'setValueTester']); - $this->instance = new Util($this->filesMock, $cryptMock, $loggerMock, $userSessionMock, $this->configMock, $this->userManagerMock); + $this->instance = new Util($this->filesMock, $cryptMock, $userSessionMock, $this->configMock, $this->userManagerMock); } /** |