mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
test(encryption): adjust test code for PHPUnit 10 deprecations
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
9422b6d6d0
commit
d0758fe6ac
15 changed files with 264 additions and 367 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2019 ownCloud GmbH
|
||||
|
|
@ -16,6 +18,7 @@ use OCP\IConfig;
|
|||
use OCP\ITempManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Server;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Test\TestCase;
|
||||
|
|
@ -34,16 +37,13 @@ class FixEncryptedVersionTest extends TestCase {
|
|||
use EncryptionTrait;
|
||||
use UserTrait;
|
||||
|
||||
private $userId;
|
||||
private string $userId;
|
||||
|
||||
/** @var FixEncryptedVersion */
|
||||
private $fixEncryptedVersion;
|
||||
private FixEncryptedVersion $fixEncryptedVersion;
|
||||
|
||||
/** @var CommandTester */
|
||||
private $commandTester;
|
||||
private CommandTester $commandTester;
|
||||
|
||||
/** @var Util|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $util;
|
||||
protected Util&MockObject $util;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -13,26 +15,23 @@ use OCP\AppFramework\Http;
|
|||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class RecoveryControllerTest extends TestCase {
|
||||
/** @var RecoveryController */
|
||||
private $controller;
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $requestMock;
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $configMock;
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10nMock;
|
||||
/** @var Recovery|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $recoveryMock;
|
||||
protected RecoveryController $controller;
|
||||
|
||||
public function adminRecoveryProvider() {
|
||||
protected IRequest&MockObject $requestMock;
|
||||
protected IConfig&MockObject $configMock;
|
||||
protected IL10N&MockObject $l10nMock;
|
||||
protected Recovery&MockObject $recoveryMock;
|
||||
|
||||
public static function adminRecoveryProvider(): array {
|
||||
return [
|
||||
['test', 'test', '1', 'Recovery key successfully enabled', Http::STATUS_OK],
|
||||
['', 'test', '1', 'Missing recovery key password', Http::STATUS_BAD_REQUEST],
|
||||
['test', '', '1', 'Please repeat the recovery key password', Http::STATUS_BAD_REQUEST],
|
||||
['test', 'soimething that doesn\'t match', '1', 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST],
|
||||
['test', 'something that doesn\'t match', '1', 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST],
|
||||
['test', 'test', '0', 'Recovery key successfully disabled', Http::STATUS_OK],
|
||||
];
|
||||
}
|
||||
|
|
@ -63,7 +62,7 @@ class RecoveryControllerTest extends TestCase {
|
|||
$this->assertEquals($expectedStatus, $response->getStatus());
|
||||
}
|
||||
|
||||
public function changeRecoveryPasswordProvider() {
|
||||
public static function changeRecoveryPasswordProvider(): array {
|
||||
return [
|
||||
['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', Http::STATUS_BAD_REQUEST],
|
||||
['test', 'test', 'oldtest', 'Password successfully changed.', Http::STATUS_OK],
|
||||
|
|
@ -98,7 +97,7 @@ class RecoveryControllerTest extends TestCase {
|
|||
$this->assertEquals($expectedStatus, $response->getStatus());
|
||||
}
|
||||
|
||||
public function userSetRecoveryProvider() {
|
||||
public static function userSetRecoveryProvider(): array {
|
||||
return [
|
||||
['1', 'Recovery Key enabled', Http::STATUS_OK],
|
||||
['0', 'Could not enable the recovery key, please try again or contact your administrator', Http::STATUS_BAD_REQUEST]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -24,37 +26,18 @@ use Test\TestCase;
|
|||
|
||||
class SettingsControllerTest extends TestCase {
|
||||
|
||||
/** @var SettingsController */
|
||||
private $controller;
|
||||
protected SettingsController $controller;
|
||||
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $requestMock;
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10nMock;
|
||||
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userManagerMock;
|
||||
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userSessionMock;
|
||||
|
||||
/** @var KeyManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $keyManagerMock;
|
||||
|
||||
/** @var Crypt|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cryptMock;
|
||||
|
||||
/** @var Session|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $sessionMock;
|
||||
/** @var MockObject|IUser */
|
||||
private $user;
|
||||
|
||||
/** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $ocSessionMock;
|
||||
|
||||
/** @var Util|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $utilMock;
|
||||
protected IRequest&MockObject $requestMock;
|
||||
protected IL10N&MockObject $l10nMock;
|
||||
protected IUserManager&MockObject $userManagerMock;
|
||||
protected IUserSession&MockObject $userSessionMock;
|
||||
protected KeyManager&MockObject $keyManagerMock;
|
||||
protected Crypt&MockObject $cryptMock;
|
||||
protected Session&MockObject $sessionMock;
|
||||
protected IUser&MockObject $user;
|
||||
protected ISession&MockObject $ocSessionMock;
|
||||
protected Util&MockObject $utilMock;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -171,21 +154,17 @@ class SettingsControllerTest extends TestCase {
|
|||
$newPassword = 'new';
|
||||
|
||||
$this->ocSessionMock->expects($this->once())
|
||||
->method('get')->with('loginname')->willReturn('testUser');
|
||||
->method('get')
|
||||
->with('loginname')
|
||||
->willReturn('testUser');
|
||||
|
||||
$this->userManagerMock
|
||||
->expects($this->exactly(2))
|
||||
->method('checkPassword')
|
||||
->withConsecutive(
|
||||
['testUserUid', 'new'],
|
||||
['testUser', 'new'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
false,
|
||||
true,
|
||||
);
|
||||
|
||||
|
||||
->willReturnMap([
|
||||
['testUserUid', 'new', false],
|
||||
['testUser', 'new', true],
|
||||
]);
|
||||
|
||||
$this->cryptMock
|
||||
->expects($this->once())
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -12,24 +14,17 @@ use OCA\Encryption\Session;
|
|||
use OCP\Encryption\IManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class StatusControllerTest extends TestCase {
|
||||
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $requestMock;
|
||||
protected IRequest&MockObject $requestMock;
|
||||
protected IL10N&MockObject $l10nMock;
|
||||
protected Session&MockObject $sessionMock;
|
||||
protected IManager&MockObject $encryptionManagerMock;
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10nMock;
|
||||
|
||||
/** @var Session|\PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $sessionMock;
|
||||
|
||||
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $encryptionManagerMock;
|
||||
|
||||
/** @var StatusController */
|
||||
protected $controller;
|
||||
protected StatusController $controller;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -68,7 +63,7 @@ class StatusControllerTest extends TestCase {
|
|||
$this->assertSame($expectedStatus, $data['status']);
|
||||
}
|
||||
|
||||
public function dataTestGetStatus() {
|
||||
public static function dataTestGetStatus(): array {
|
||||
return [
|
||||
[Session::INIT_EXECUTED, 'interactionNeeded'],
|
||||
[Session::INIT_SUCCESSFUL, 'success'],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -12,24 +14,17 @@ use OCP\Encryption\Exceptions\GenericEncryptionException;
|
|||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class CryptTest extends TestCase {
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logger;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected IUserSession&MockObject $userSession;
|
||||
protected IConfig&MockObject $config;
|
||||
protected IL10N&MockObject $l;
|
||||
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userSession;
|
||||
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l;
|
||||
|
||||
/** @var Crypt */
|
||||
private $crypt;
|
||||
protected Crypt $crypt;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -113,10 +108,7 @@ class CryptTest extends TestCase {
|
|||
$this->crypt->generateHeader('unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataTestGenerateHeader() {
|
||||
public static function dataTestGenerateHeader(): array {
|
||||
return [
|
||||
[null, 'HBEGIN:cipher:AES-128-CFB:keyFormat:hash2:encoding:binary:HEND'],
|
||||
['password', 'HBEGIN:cipher:AES-128-CFB:keyFormat:password:encoding:binary:HEND'],
|
||||
|
|
@ -155,10 +147,8 @@ class CryptTest extends TestCase {
|
|||
|
||||
/**
|
||||
* data provider for testGetCipher
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderGetCipher() {
|
||||
public static function dataProviderGetCipher(): array {
|
||||
return [
|
||||
['AES-128-CFB', 'AES-128-CFB'],
|
||||
['AES-256-CFB', 'AES-256-CFB'],
|
||||
|
|
@ -201,7 +191,7 @@ class CryptTest extends TestCase {
|
|||
$this->assertSame($expected['signature'], $result['signature']);
|
||||
}
|
||||
|
||||
public function dataTestSplitMetaData() {
|
||||
public static function dataTestSplitMetaData(): array {
|
||||
return [
|
||||
['encryptedContent00iv001234567890123456xx',
|
||||
['encrypted' => 'encryptedContent', 'iv' => '1234567890123456', 'signature' => false]],
|
||||
|
|
@ -222,7 +212,7 @@ class CryptTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestHasSignature() {
|
||||
public static function dataTestHasSignature(): array {
|
||||
return [
|
||||
['encryptedContent00iv001234567890123456xx', false],
|
||||
['encryptedContent00iv00123456789012345600sig00e1992521e437f6915f9173b190a512cfc38a00ac24502db44e0ba10c2bb0cc86xxx', true]
|
||||
|
|
@ -239,7 +229,7 @@ class CryptTest extends TestCase {
|
|||
$this->invokePrivate($this->crypt, 'hasSignature', [$data, $cipher]);
|
||||
}
|
||||
|
||||
public function dataTestHasSignatureFail() {
|
||||
public static function dataTestHasSignatureFail(): array {
|
||||
return [
|
||||
['AES-256-CTR'],
|
||||
['aes-256-ctr'],
|
||||
|
|
@ -270,10 +260,8 @@ class CryptTest extends TestCase {
|
|||
|
||||
/**
|
||||
* data provider for testRemovePadding
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderRemovePadding() {
|
||||
public static function dataProviderRemovePadding(): array {
|
||||
return [
|
||||
['dataxx', 'data'],
|
||||
['data', false]
|
||||
|
|
@ -357,10 +345,7 @@ class CryptTest extends TestCase {
|
|||
$this->invokePrivate($this->crypt, 'getKeySize', ['foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataTestGetKeySize() {
|
||||
public static function dataTestGetKeySize(): array {
|
||||
return [
|
||||
['AES-256-CFB', 32],
|
||||
['AES-128-CFB', 16],
|
||||
|
|
@ -374,28 +359,25 @@ class CryptTest extends TestCase {
|
|||
*/
|
||||
public function testDecryptPrivateKey($header, $privateKey, $expectedCipher, $isValidKey, $expected): void {
|
||||
$this->config->method('getSystemValueBool')
|
||||
->withConsecutive(['encryption.legacy_format_support', false],
|
||||
['encryption.use_legacy_base64_encoding', false])
|
||||
->willReturnOnConsecutiveCalls(true, false);
|
||||
->willReturnMap([
|
||||
['encryption.legacy_format_support', false, true],
|
||||
['encryption.use_legacy_base64_encoding', false, false],
|
||||
]);
|
||||
|
||||
/** @var Crypt|\PHPUnit\Framework\MockObject\MockObject $crypt */
|
||||
$crypt = $this->getMockBuilder(Crypt::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
$this->logger,
|
||||
$this->userSession,
|
||||
$this->config,
|
||||
$this->l
|
||||
]
|
||||
)
|
||||
->setMethods(
|
||||
[
|
||||
'parseHeader',
|
||||
'generatePasswordHash',
|
||||
'symmetricDecryptFileContent',
|
||||
'isValidPrivateKey'
|
||||
]
|
||||
)
|
||||
->setConstructorArgs([
|
||||
$this->logger,
|
||||
$this->userSession,
|
||||
$this->config,
|
||||
$this->l
|
||||
])
|
||||
->onlyMethods([
|
||||
'parseHeader',
|
||||
'generatePasswordHash',
|
||||
'symmetricDecryptFileContent',
|
||||
'isValidPrivateKey'
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$crypt->expects($this->once())->method('parseHeader')->willReturn($header);
|
||||
|
|
@ -416,10 +398,7 @@ class CryptTest extends TestCase {
|
|||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataTestDecryptPrivateKey() {
|
||||
public static function dataTestDecryptPrivateKey(): array {
|
||||
return [
|
||||
[['cipher' => 'AES-128-CFB', 'keyFormat' => 'password'], 'HBEGIN:HENDprivateKey', 'AES-128-CFB', true, 'key'],
|
||||
[['cipher' => 'AES-256-CFB', 'keyFormat' => 'password'], 'HBEGIN:HENDprivateKey', 'AES-256-CFB', true, 'key'],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -12,28 +14,19 @@ use OCA\Encryption\Crypto\DecryptAll;
|
|||
use OCA\Encryption\KeyManager;
|
||||
use OCA\Encryption\Session;
|
||||
use OCA\Encryption\Util;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Test\TestCase;
|
||||
|
||||
class DecryptAllTest extends TestCase {
|
||||
|
||||
/** @var DecryptAll */
|
||||
protected $instance;
|
||||
protected DecryptAll $instance;
|
||||
|
||||
/** @var Util | \PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $util;
|
||||
|
||||
/** @var KeyManager | \PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $keyManager;
|
||||
|
||||
/** @var Crypt | \PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $crypt;
|
||||
|
||||
/** @var Session | \PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $session;
|
||||
|
||||
/** @var QuestionHelper | \PHPUnit\Framework\MockObject\MockObject */
|
||||
protected $questionHelper;
|
||||
protected Util&MockObject $util;
|
||||
protected KeyManager&MockObject $keyManager;
|
||||
protected Crypt&MockObject $crypt;
|
||||
protected Session&MockObject $session;
|
||||
protected QuestionHelper&MockObject $questionHelper;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -75,6 +68,7 @@ class DecryptAllTest extends TestCase {
|
|||
$password = 'passwd';
|
||||
$recoveryKey = 'recoveryKey';
|
||||
$userKey = 'userKey';
|
||||
$masterKey = 'userKey';
|
||||
$unencryptedKey = 'unencryptedKey';
|
||||
|
||||
$this->keyManager->expects($this->any())->method('getRecoveryKeyId')
|
||||
|
|
@ -105,7 +99,7 @@ class DecryptAllTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestGetPrivateKey() {
|
||||
public static function dataTestGetPrivateKey() {
|
||||
return [
|
||||
['user1', 'recoveryKey', 'masterKeyId'],
|
||||
['recoveryKeyId', 'recoveryKeyId', 'masterKeyId'],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -20,6 +22,7 @@ use OCP\L10N\IFactory;
|
|||
use OCP\Mail\IMailer;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use OCP\UserInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
|
|
@ -29,50 +32,22 @@ use Test\TestCase;
|
|||
|
||||
class EncryptAllTest extends TestCase {
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|KeyManager */
|
||||
protected $keyManager;
|
||||
protected KeyManager&MockObject $keyManager;
|
||||
protected Util&MockObject $util;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected Setup&MockObject $setupUser;
|
||||
protected View&MockObject $view;
|
||||
protected IConfig&MockObject $config;
|
||||
protected IMailer&MockObject $mailer;
|
||||
protected IL10N&MockObject $l;
|
||||
protected IFactory&MockObject $l10nFactory;
|
||||
protected \Symfony\Component\Console\Helper\QuestionHelper&MockObject $questionHelper;
|
||||
protected \Symfony\Component\Console\Input\InputInterface&MockObject $inputInterface;
|
||||
protected \Symfony\Component\Console\Output\OutputInterface&MockObject $outputInterface;
|
||||
protected UserInterface&MockObject $userInterface;
|
||||
protected ISecureRandom&MockObject $secureRandom;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|Util */
|
||||
protected $util;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|IUserManager */
|
||||
protected $userManager;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|Setup */
|
||||
protected $setupUser;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|View */
|
||||
protected $view;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */
|
||||
protected $config;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|IMailer */
|
||||
protected $mailer;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|IL10N */
|
||||
protected $l;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | IFactory */
|
||||
protected $l10nFactory;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Helper\QuestionHelper */
|
||||
protected $questionHelper;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Input\InputInterface */
|
||||
protected $inputInterface;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject | \Symfony\Component\Console\Output\OutputInterface */
|
||||
protected $outputInterface;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|UserInterface */
|
||||
protected $userInterface;
|
||||
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|ISecureRandom */
|
||||
protected $secureRandom;
|
||||
|
||||
/** @var EncryptAll */
|
||||
protected $encryptAll;
|
||||
protected EncryptAll $encryptAll;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -153,7 +128,7 @@ class EncryptAllTest extends TestCase {
|
|||
$this->secureRandom
|
||||
]
|
||||
)
|
||||
->setMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords'])
|
||||
->onlyMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords'])
|
||||
->getMock();
|
||||
|
||||
$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false);
|
||||
|
|
@ -182,7 +157,7 @@ class EncryptAllTest extends TestCase {
|
|||
$this->secureRandom
|
||||
]
|
||||
)
|
||||
->setMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords'])
|
||||
->onlyMethods(['createKeyPairs', 'encryptAllUsersFiles', 'outputPasswords'])
|
||||
->getMock();
|
||||
|
||||
$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(true);
|
||||
|
|
@ -212,7 +187,7 @@ class EncryptAllTest extends TestCase {
|
|||
$this->secureRandom
|
||||
]
|
||||
)
|
||||
->setMethods(['setupUserFS', 'generateOneTimePassword'])
|
||||
->onlyMethods(['setupUserFS', 'generateOneTimePassword'])
|
||||
->getMock();
|
||||
|
||||
|
||||
|
|
@ -245,7 +220,7 @@ class EncryptAllTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testEncryptAllUsersFiles(): void {
|
||||
/** @var EncryptAll | \PHPUnit\Framework\MockObject\MockObject $encryptAll */
|
||||
/** @var EncryptAll&MockObject $encryptAll */
|
||||
$encryptAll = $this->getMockBuilder(EncryptAll::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -262,7 +237,7 @@ class EncryptAllTest extends TestCase {
|
|||
$this->secureRandom
|
||||
]
|
||||
)
|
||||
->setMethods(['encryptUsersFiles'])
|
||||
->onlyMethods(['encryptUsersFiles'])
|
||||
->getMock();
|
||||
|
||||
$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false);
|
||||
|
|
@ -271,17 +246,22 @@ class EncryptAllTest extends TestCase {
|
|||
$this->invokePrivate($encryptAll, 'output', [$this->outputInterface]);
|
||||
$this->invokePrivate($encryptAll, 'userPasswords', [['user1' => 'pwd1', 'user2' => 'pwd2']]);
|
||||
|
||||
$encryptAll->expects($this->exactly(2))->method('encryptUsersFiles')
|
||||
->withConsecutive(
|
||||
['user1'],
|
||||
['user2'],
|
||||
);
|
||||
$encryptAllCalls = [];
|
||||
$encryptAll->expects($this->exactly(2))
|
||||
->method('encryptUsersFiles')
|
||||
->willReturnCallback(function ($uid) use (&$encryptAllCalls) {
|
||||
$encryptAllCalls[] = $uid;
|
||||
});
|
||||
|
||||
$this->invokePrivate($encryptAll, 'encryptAllUsersFiles');
|
||||
self::assertEquals([
|
||||
'user1',
|
||||
'user2',
|
||||
], $encryptAllCalls);
|
||||
}
|
||||
|
||||
public function testEncryptUsersFiles(): void {
|
||||
/** @var EncryptAll | \PHPUnit\Framework\MockObject\MockObject $encryptAll */
|
||||
/** @var EncryptAll&MockObject $encryptAll */
|
||||
$encryptAll = $this->getMockBuilder(EncryptAll::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -298,24 +278,31 @@ class EncryptAllTest extends TestCase {
|
|||
$this->secureRandom
|
||||
]
|
||||
)
|
||||
->setMethods(['encryptFile', 'setupUserFS'])
|
||||
->onlyMethods(['encryptFile', 'setupUserFS'])
|
||||
->getMock();
|
||||
|
||||
$this->util->expects($this->any())->method('isMasterKeyEnabled')->willReturn(false);
|
||||
|
||||
$this->view->expects($this->exactly(2))->method('getDirectoryContent')
|
||||
->withConsecutive(
|
||||
['/user1/files'],
|
||||
['/user1/files/foo'],
|
||||
)->willReturnOnConsecutiveCalls(
|
||||
->willReturnMap([
|
||||
[
|
||||
['name' => 'foo', 'type' => 'dir'],
|
||||
['name' => 'bar', 'type' => 'file'],
|
||||
'/user1/files',
|
||||
'',
|
||||
null,
|
||||
[
|
||||
['name' => 'foo', 'type' => 'dir'],
|
||||
['name' => 'bar', 'type' => 'file'],
|
||||
],
|
||||
],
|
||||
[
|
||||
['name' => 'subfile', 'type' => 'file']
|
||||
]
|
||||
);
|
||||
'/user1/files/foo',
|
||||
'',
|
||||
null,
|
||||
[
|
||||
['name' => 'subfile', 'type' => 'file']
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->view->expects($this->any())->method('is_dir')
|
||||
->willReturnCallback(
|
||||
|
|
@ -327,11 +314,12 @@ class EncryptAllTest extends TestCase {
|
|||
}
|
||||
);
|
||||
|
||||
$encryptAll->expects($this->exactly(2))->method('encryptFile')
|
||||
->withConsecutive(
|
||||
['/user1/files/bar'],
|
||||
['/user1/files/foo/subfile'],
|
||||
);
|
||||
$encryptAllCalls = [];
|
||||
$encryptAll->expects($this->exactly(2))
|
||||
->method('encryptFile')
|
||||
->willReturnCallback(function (string $path) use (&$encryptAllCalls) {
|
||||
$encryptAllCalls[] = $path;
|
||||
});
|
||||
|
||||
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
|
||||
$outputFormatter->method('isDecorated')->willReturn(false);
|
||||
|
|
@ -341,6 +329,10 @@ class EncryptAllTest extends TestCase {
|
|||
$progressBar = new ProgressBar($this->outputInterface);
|
||||
|
||||
$this->invokePrivate($encryptAll, 'encryptUsersFiles', ['user1', $progressBar, '']);
|
||||
self::assertEquals([
|
||||
'/user1/files/bar',
|
||||
'/user1/files/foo/subfile',
|
||||
], $encryptAllCalls);
|
||||
}
|
||||
|
||||
public function testGenerateOneTimePassword(): void {
|
||||
|
|
@ -378,7 +370,7 @@ class EncryptAllTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestEncryptFile() {
|
||||
public static function dataTestEncryptFile(): array {
|
||||
return [
|
||||
[true],
|
||||
[false],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -26,34 +28,18 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class EncryptionTest extends TestCase {
|
||||
/** @var Encryption */
|
||||
private $instance;
|
||||
|
||||
/** @var KeyManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $keyManagerMock;
|
||||
protected Encryption $instance;
|
||||
|
||||
/** @var EncryptAll|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $encryptAllMock;
|
||||
|
||||
/** @var DecryptAll|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $decryptAllMock;
|
||||
|
||||
/** @var Session|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $sessionMock;
|
||||
|
||||
/** @var Crypt|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cryptMock;
|
||||
|
||||
/** @var Util|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $utilMock;
|
||||
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $loggerMock;
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10nMock;
|
||||
|
||||
private IStorage&MockObject $storageMock;
|
||||
protected KeyManager&MockObject $keyManagerMock;
|
||||
protected EncryptAll&MockObject $encryptAllMock;
|
||||
protected DecryptAll&MockObject $decryptAllMock;
|
||||
protected Session&MockObject $sessionMock;
|
||||
protected Crypt&MockObject $cryptMock;
|
||||
protected Util&MockObject $utilMock;
|
||||
protected LoggerInterface&MockObject $loggerMock;
|
||||
protected IL10N&MockObject $l10nMock;
|
||||
protected IStorage&MockObject $storageMock;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -175,7 +161,7 @@ class EncryptionTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataProviderForTestGetPathToRealFile() {
|
||||
public static function dataProviderForTestGetPathToRealFile(): array {
|
||||
return [
|
||||
['/user/files/foo/bar.txt', '/user/files/foo/bar.txt'],
|
||||
['/user/files/foo.txt', '/user/files/foo.txt'],
|
||||
|
|
@ -228,7 +214,7 @@ class EncryptionTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function dataTestBegin() {
|
||||
public static function dataTestBegin(): array {
|
||||
return [
|
||||
['w', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'defaultCipher'],
|
||||
['r', ['cipher' => 'myCipher'], 'legacyCipher', 'defaultCipher', 'fileKey', 'myCipher'],
|
||||
|
|
@ -305,7 +291,7 @@ class EncryptionTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestUpdate() {
|
||||
public static function dataTestUpdate(): array {
|
||||
return [
|
||||
['', false],
|
||||
['fileKey', true]
|
||||
|
|
@ -387,7 +373,7 @@ class EncryptionTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestShouldEncrypt() {
|
||||
public static function dataTestShouldEncrypt(): array {
|
||||
return [
|
||||
['/user1/files/foo.txt', true, true, true],
|
||||
['/user1/files_versions/foo.txt', true, true, true],
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -28,41 +30,19 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class KeyManagerTest extends TestCase {
|
||||
/**
|
||||
* @var KeyManager
|
||||
*/
|
||||
private $instance;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $userId;
|
||||
|
||||
/** @var string */
|
||||
private $systemKeyId;
|
||||
protected KeyManager $instance;
|
||||
|
||||
/** @var \OCP\Encryption\Keys\IStorage|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $keyStorageMock;
|
||||
|
||||
/** @var Crypt|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cryptMock;
|
||||
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userMock;
|
||||
|
||||
/** @var Session|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $sessionMock;
|
||||
|
||||
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logMock;
|
||||
|
||||
/** @var Util|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $utilMock;
|
||||
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $configMock;
|
||||
|
||||
/** @var ILockingProvider|MockObject */
|
||||
private $lockingProviderMock;
|
||||
protected string $userId;
|
||||
protected string $systemKeyId;
|
||||
protected IStorage&MockObject $keyStorageMock;
|
||||
protected Crypt&MockObject $cryptMock;
|
||||
protected IUserSession&MockObject $userMock;
|
||||
protected Session&MockObject $sessionMock;
|
||||
protected LoggerInterface&MockObject $logMock;
|
||||
protected Util&MockObject $utilMock;
|
||||
protected IConfig&MockObject $configMock;
|
||||
protected ILockingProvider&MockObject $lockingProviderMock;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -201,7 +181,7 @@ class KeyManagerTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestUserHasKeys() {
|
||||
public static function dataTestUserHasKeys(): array {
|
||||
return [
|
||||
['key', true],
|
||||
['', false]
|
||||
|
|
@ -246,7 +226,7 @@ class KeyManagerTest extends TestCase {
|
|||
* @param bool $useMasterKey
|
||||
*/
|
||||
public function testInit($useMasterKey): void {
|
||||
/** @var KeyManager|\PHPUnit\Framework\MockObject\MockObject $instance */
|
||||
/** @var KeyManager&MockObject $instance */
|
||||
$instance = $this->getMockBuilder(KeyManager::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -259,17 +239,18 @@ class KeyManagerTest extends TestCase {
|
|||
$this->utilMock,
|
||||
$this->lockingProviderMock
|
||||
]
|
||||
)->setMethods(['getMasterKeyId', 'getMasterKeyPassword', 'getSystemPrivateKey', 'getPrivateKey'])
|
||||
)->onlyMethods(['getMasterKeyId', 'getMasterKeyPassword', 'getSystemPrivateKey', 'getPrivateKey'])
|
||||
->getMock();
|
||||
|
||||
$this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
|
||||
->willReturn($useMasterKey);
|
||||
|
||||
$this->sessionMock->expects($this->exactly(2))->method('setStatus')
|
||||
->withConsecutive(
|
||||
[Session::INIT_EXECUTED],
|
||||
[Session::INIT_SUCCESSFUL],
|
||||
);
|
||||
$sessionSetStatusCalls = [];
|
||||
$this->sessionMock->expects($this->exactly(2))
|
||||
->method('setStatus')
|
||||
->willReturnCallback(function (string $status) use (&$sessionSetStatusCalls) {
|
||||
$sessionSetStatusCalls[] = $status;
|
||||
});
|
||||
|
||||
$instance->expects($this->any())->method('getMasterKeyId')->willReturn('masterKeyId');
|
||||
$instance->expects($this->any())->method('getMasterKeyPassword')->willReturn('masterKeyPassword');
|
||||
|
|
@ -290,9 +271,13 @@ class KeyManagerTest extends TestCase {
|
|||
->with('key');
|
||||
|
||||
$this->assertTrue($instance->init($this->userId, 'pass'));
|
||||
self::assertEquals([
|
||||
Session::INIT_EXECUTED,
|
||||
Session::INIT_SUCCESSFUL,
|
||||
], $sessionSetStatusCalls);
|
||||
}
|
||||
|
||||
public function dataTestInit() {
|
||||
public static function dataTestInit(): array {
|
||||
return [
|
||||
[true],
|
||||
[false]
|
||||
|
|
@ -349,7 +334,7 @@ class KeyManagerTest extends TestCase {
|
|||
$this->assertTrue($this->instance->getEncryptedFileKey('/'));
|
||||
}
|
||||
|
||||
public function dataTestGetFileKey() {
|
||||
public static function dataTestGetFileKey(): array {
|
||||
return [
|
||||
['user1', false, 'privateKey', 'legacyKey', 'multiKeyDecryptResult'],
|
||||
['user1', false, 'privateKey', '', 'multiKeyDecryptResult'],
|
||||
|
|
@ -395,14 +380,10 @@ class KeyManagerTest extends TestCase {
|
|||
|
||||
$this->keyStorageMock->expects($this->exactly(2))
|
||||
->method('getFileKey')
|
||||
->withConsecutive(
|
||||
[$path, 'fileKey', 'OC_DEFAULT_MODULE'],
|
||||
[$path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$encryptedFileKey,
|
||||
'fileKey',
|
||||
);
|
||||
->willReturnMap([
|
||||
[$path, 'fileKey', 'OC_DEFAULT_MODULE', $encryptedFileKey],
|
||||
[$path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE', 'fileKey'],
|
||||
]);
|
||||
|
||||
$this->utilMock->expects($this->any())->method('isMasterKeyEnabled')
|
||||
->willReturn($isMasterKeyEnabled);
|
||||
|
|
@ -515,7 +496,7 @@ class KeyManagerTest extends TestCase {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataTestAddSystemKeys() {
|
||||
public static function dataTestAddSystemKeys(): array {
|
||||
return [
|
||||
[['public' => true],[], 'user1', ['publicShareKey', 'recoveryKey']],
|
||||
[['public' => false], [], 'user1', ['recoveryKey']],
|
||||
|
|
@ -563,7 +544,7 @@ class KeyManagerTest extends TestCase {
|
|||
* @param $masterKey
|
||||
*/
|
||||
public function testValidateMasterKey($masterKey): void {
|
||||
/** @var KeyManager|\PHPUnit\Framework\MockObject\MockObject $instance */
|
||||
/** @var KeyManager&MockObject $instance */
|
||||
$instance = $this->getMockBuilder(KeyManager::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
|
@ -576,7 +557,7 @@ class KeyManagerTest extends TestCase {
|
|||
$this->utilMock,
|
||||
$this->lockingProviderMock
|
||||
]
|
||||
)->setMethods(['getPublicMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword'])
|
||||
)->onlyMethods(['getPublicMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword'])
|
||||
->getMock();
|
||||
|
||||
$this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
|
||||
|
|
@ -611,20 +592,19 @@ class KeyManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testValidateMasterKeyLocked(): void {
|
||||
/** @var KeyManager|\PHPUnit_Framework_MockObject_MockObject $instance */
|
||||
/** @var KeyManager&MockObject $instance */
|
||||
$instance = $this->getMockBuilder(KeyManager::class)
|
||||
->setConstructorArgs(
|
||||
[
|
||||
$this->keyStorageMock,
|
||||
$this->cryptMock,
|
||||
$this->configMock,
|
||||
$this->userMock,
|
||||
$this->sessionMock,
|
||||
$this->logMock,
|
||||
$this->utilMock,
|
||||
$this->lockingProviderMock
|
||||
]
|
||||
)->setMethods(['getPublicMasterKey', 'getPrivateMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword'])
|
||||
->setConstructorArgs([
|
||||
$this->keyStorageMock,
|
||||
$this->cryptMock,
|
||||
$this->configMock,
|
||||
$this->userMock,
|
||||
$this->sessionMock,
|
||||
$this->logMock,
|
||||
$this->utilMock,
|
||||
$this->lockingProviderMock
|
||||
])
|
||||
->onlyMethods(['getPublicMasterKey', 'getPrivateMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword'])
|
||||
->getMock();
|
||||
|
||||
$this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
|
||||
|
|
@ -646,7 +626,7 @@ class KeyManagerTest extends TestCase {
|
|||
$instance->validateMasterKey();
|
||||
}
|
||||
|
||||
public function dataTestValidateMasterKey() {
|
||||
public static function dataTestValidateMasterKey(): array {
|
||||
return [
|
||||
['masterKey'],
|
||||
['']
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -10,17 +12,14 @@ namespace OCA\Encryption\Tests;
|
|||
use OCA\Encryption\Exceptions\PrivateKeyMissingException;
|
||||
use OCA\Encryption\Session;
|
||||
use OCP\ISession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class SessionTest extends TestCase {
|
||||
private static $tempStorage = [];
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
private $instance;
|
||||
/** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $sessionMock;
|
||||
|
||||
protected Session $instance;
|
||||
protected ISession&MockObject $sessionMock;
|
||||
|
||||
public function testThatGetPrivateKeyThrowsExceptionWhenNotSet(): void {
|
||||
$this->expectException(PrivateKeyMissingException::class);
|
||||
|
|
@ -122,10 +121,11 @@ class SessionTest extends TestCase {
|
|||
* @param bool $expected
|
||||
*/
|
||||
public function testIsReady($status, $expected): void {
|
||||
/** @var Session | \PHPUnit\Framework\MockObject\MockObject $instance */
|
||||
/** @var Session&MockObject $instance */
|
||||
$instance = $this->getMockBuilder(Session::class)
|
||||
->setConstructorArgs([$this->sessionMock])
|
||||
->setMethods(['getStatus'])->getMock();
|
||||
->onlyMethods(['getStatus'])
|
||||
->getMock();
|
||||
|
||||
$instance->expects($this->once())->method('getStatus')
|
||||
->willReturn($status);
|
||||
|
|
@ -133,7 +133,7 @@ class SessionTest extends TestCase {
|
|||
$this->assertSame($expected, $instance->isReady());
|
||||
}
|
||||
|
||||
public function dataTestIsReady() {
|
||||
public static function dataTestIsReady(): array {
|
||||
return [
|
||||
[Session::INIT_SUCCESSFUL, true],
|
||||
[Session::INIT_EXECUTED, false],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -12,24 +15,20 @@ use OCP\IL10N;
|
|||
use OCP\ISession;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var ISession */
|
||||
private $session;
|
||||
|
||||
protected Admin $admin;
|
||||
|
||||
protected IL10N&MockObject $l;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected IUserSession&MockObject $userSession;
|
||||
protected IConfig&MockObject $config;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected ISession&MockObject $session;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -10,21 +12,15 @@ namespace OCA\Encryption\Tests\Users;
|
|||
use OCA\Encryption\Crypto\Crypt;
|
||||
use OCA\Encryption\KeyManager;
|
||||
use OCA\Encryption\Users\Setup;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class SetupTest extends TestCase {
|
||||
/**
|
||||
* @var KeyManager|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $keyManagerMock;
|
||||
/**
|
||||
* @var Crypt|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $cryptMock;
|
||||
/**
|
||||
* @var Setup
|
||||
*/
|
||||
private $instance;
|
||||
|
||||
protected Setup $instance;
|
||||
|
||||
protected KeyManager&MockObject $keyManagerMock;
|
||||
protected Crypt&MockObject $cryptMock;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -72,7 +68,7 @@ class SetupTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestSetupUser() {
|
||||
public static function dataTestSetupUser(): array {
|
||||
return [
|
||||
[true, true],
|
||||
[false, true]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
||||
|
|
@ -20,22 +22,14 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class UtilTest extends TestCase {
|
||||
private static $tempStorage = [];
|
||||
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $configMock;
|
||||
protected Util $instance;
|
||||
protected static $tempStorage = [];
|
||||
|
||||
/** @var View|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $filesMock;
|
||||
|
||||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userManagerMock;
|
||||
|
||||
/** @var IMountPoint|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $mountMock;
|
||||
|
||||
/** @var Util */
|
||||
private $instance;
|
||||
protected IConfig&MockObject $configMock;
|
||||
protected View&MockObject $filesMock;
|
||||
protected IUserManager&MockObject $userManagerMock;
|
||||
protected IMountPoint&MockObject $mountMock;
|
||||
|
||||
public function testSetRecoveryForUser(): void {
|
||||
$this->instance->setRecoveryForUser('1');
|
||||
|
|
@ -134,7 +128,7 @@ class UtilTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataTestIsMasterKeyEnabled() {
|
||||
public static function dataTestIsMasterKeyEnabled(): array {
|
||||
return [
|
||||
['0', false],
|
||||
['1', true]
|
||||
|
|
@ -155,7 +149,7 @@ class UtilTest extends TestCase {
|
|||
$this->instance->shouldEncryptHomeStorage());
|
||||
}
|
||||
|
||||
public function dataTestShouldEncryptHomeStorage() {
|
||||
public static function dataTestShouldEncryptHomeStorage(): array {
|
||||
return [
|
||||
['1', true],
|
||||
['0', false]
|
||||
|
|
@ -173,7 +167,7 @@ class UtilTest extends TestCase {
|
|||
$this->instance->setEncryptHomeStorage($value);
|
||||
}
|
||||
|
||||
public function dataTestSetEncryptHomeStorage() {
|
||||
public static function dataTestSetEncryptHomeStorage(): array {
|
||||
return [
|
||||
[true, '1'],
|
||||
[false, '0']
|
||||
|
|
|
|||
Loading…
Reference in a new issue