Move Encryption app to PSR-4 (#24524)
* Move Encryption to PSR-4 * Move encryption tests to PSR-4 * Fix the tests
This commit is contained in:
parent
c5ae14453a
commit
4a3311f430
|
@ -24,6 +24,7 @@ namespace OCA\Encryption\Tests\Command;
|
||||||
|
|
||||||
|
|
||||||
use OCA\Encryption\Command\EnableMasterKey;
|
use OCA\Encryption\Command\EnableMasterKey;
|
||||||
|
use OCA\Encryption\Util;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class TestEnableMasterKey extends TestCase {
|
class TestEnableMasterKey extends TestCase {
|
|
@ -28,47 +28,36 @@ use OCP\AppFramework\Http;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class RecoveryControllerTest extends TestCase {
|
class RecoveryControllerTest extends TestCase {
|
||||||
/**
|
/** @var RecoveryController */
|
||||||
* @var RecoveryController
|
|
||||||
*/
|
|
||||||
private $controller;
|
private $controller;
|
||||||
private $appName;
|
/** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
/**
|
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
||||||
*/
|
|
||||||
private $requestMock;
|
private $requestMock;
|
||||||
/**
|
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
||||||
*/
|
|
||||||
private $configMock;
|
private $configMock;
|
||||||
/**
|
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
||||||
*/
|
|
||||||
private $l10nMock;
|
private $l10nMock;
|
||||||
/**
|
/** @var \OCA\Encryption\Recovery|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
||||||
*/
|
|
||||||
private $recoveryMock;
|
private $recoveryMock;
|
||||||
|
|
||||||
public function adminRecoveryProvider() {
|
public function adminRecoveryProvider() {
|
||||||
return [
|
return [
|
||||||
['test', 'test', '1', 'Recovery key successfully enabled', HTTP::STATUS_OK],
|
['test', 'test', '1', 'Recovery key successfully enabled', Http::STATUS_OK],
|
||||||
['', 'test', '1', 'Missing recovery key password', HTTP::STATUS_BAD_REQUEST],
|
['', 'test', '1', 'Missing recovery key password', Http::STATUS_BAD_REQUEST],
|
||||||
['test', '', '1', 'Please repeat the 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', 'soimething 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],
|
['test', 'test', '0', 'Recovery key successfully disabled', Http::STATUS_OK],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider adminRecoveryProvider
|
* @dataProvider adminRecoveryProvider
|
||||||
* @param $recoveryPassword
|
* @param $recoveryPassword
|
||||||
* @param $passconfirm
|
* @param $passConfirm
|
||||||
* @param $enableRecovery
|
* @param $enableRecovery
|
||||||
* @param $expectedMessage
|
* @param $expectedMessage
|
||||||
* @param $expectedStatus
|
* @param $expectedStatus
|
||||||
*/
|
*/
|
||||||
public function testAdminRecovery($recoveryPassword, $passconfirm, $enableRecovery, $expectedMessage, $expectedStatus) {
|
public function testAdminRecovery($recoveryPassword, $passConfirm, $enableRecovery, $expectedMessage, $expectedStatus) {
|
||||||
|
|
||||||
|
|
||||||
$this->recoveryMock->expects($this->any())
|
$this->recoveryMock->expects($this->any())
|
||||||
|
@ -80,7 +69,7 @@ class RecoveryControllerTest extends TestCase {
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
|
|
||||||
$response = $this->controller->adminRecovery($recoveryPassword,
|
$response = $this->controller->adminRecovery($recoveryPassword,
|
||||||
$passconfirm,
|
$passConfirm,
|
||||||
$enableRecovery);
|
$enableRecovery);
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,11 +81,11 @@ class RecoveryControllerTest extends TestCase {
|
||||||
|
|
||||||
public function changeRecoveryPasswordProvider() {
|
public function changeRecoveryPasswordProvider() {
|
||||||
return [
|
return [
|
||||||
['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', HTTP::STATUS_BAD_REQUEST],
|
['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],
|
['test', 'test', 'oldtest', 'Password successfully changed.', Http::STATUS_OK],
|
||||||
['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', HTTP::STATUS_BAD_REQUEST],
|
['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST],
|
||||||
['', 'test', 'oldtest', 'Please provide a new recovery password', HTTP::STATUS_BAD_REQUEST],
|
['', 'test', 'oldtest', 'Please provide a new recovery password', Http::STATUS_BAD_REQUEST],
|
||||||
['test', 'test', '', 'Please provide the old recovery password', HTTP::STATUS_BAD_REQUEST]
|
['test', 'test', '', 'Please provide the old recovery password', Http::STATUS_BAD_REQUEST]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,8 +149,7 @@ class RecoveryControllerTest extends TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->appName = 'encryption';
|
$this->requestMock = $this->getMockBuilder('OCP\IRequest')
|
||||||
$this->requestMock = $this->getMockBuilder('\OCP\IRequest')
|
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -182,7 +170,7 @@ class RecoveryControllerTest extends TestCase {
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$this->controller = new RecoveryController($this->appName,
|
$this->controller = new RecoveryController('encryption',
|
||||||
$this->requestMock,
|
$this->requestMock,
|
||||||
$this->configMock,
|
$this->configMock,
|
||||||
$this->l10nMock,
|
$this->l10nMock,
|
|
@ -32,31 +32,31 @@ class SettingsControllerTest extends TestCase {
|
||||||
/** @var SettingsController */
|
/** @var SettingsController */
|
||||||
private $controller;
|
private $controller;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $requestMock;
|
private $requestMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $l10nMock;
|
private $l10nMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $userManagerMock;
|
private $userManagerMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $userSessionMock;
|
private $userSessionMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\KeyManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $keyManagerMock;
|
private $keyManagerMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Crypto\Crypt|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $cryptMock;
|
private $cryptMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Session|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $sessionMock;
|
private $sessionMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\ISession|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $ocSessionMock;
|
private $ocSessionMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Util|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $utilMock;
|
private $utilMock;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
|
@ -96,7 +96,7 @@ class SettingsControllerTest extends TestCase {
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$this->ocSessionMock = $this->getMockBuilder('\OCP\ISession')->disableOriginalConstructor()->getMock();
|
$this->ocSessionMock = $this->getMockBuilder('OCP\ISession')->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$this->userSessionMock->expects($this->any())
|
$this->userSessionMock->expects($this->any())
|
||||||
->method('getUID')
|
->method('getUID')
|
|
@ -29,11 +29,11 @@ use Test\TestCase;
|
||||||
|
|
||||||
class StatusControllerTest extends TestCase {
|
class StatusControllerTest extends TestCase {
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $requestMock;
|
private $requestMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $l10nMock;
|
private $l10nMock;
|
||||||
|
|
||||||
/** @var \OCA\Encryption\Session | \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Session | \PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $sessionMock;
|
protected $sessionMock;
|
|
@ -22,29 +22,28 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace OCA\Encryption\Tests\lib\Crypto;
|
namespace OCA\Encryption\Tests\Crypto;
|
||||||
|
|
||||||
|
|
||||||
use OCA\Encryption\Crypto\Crypt;
|
use OCA\Encryption\Crypto\Crypt;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class cryptTest extends TestCase {
|
class CryptTest extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $userSession;
|
private $userSession;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
|
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
|
||||||
private $l;
|
private $l;
|
||||||
|
|
||||||
/** @var Crypt */
|
/** @var Crypt */
|
||||||
private $crypt;
|
private $crypt;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace OCA\Encryption\Tests\lib\Crypto;
|
namespace OCA\Encryption\Tests\Crypto;
|
||||||
|
|
||||||
|
|
||||||
use OCA\Encryption\Crypto\Crypt;
|
use OCA\Encryption\Crypto\Crypt;
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace OCA\Encryption\Tests\lib\Crypto;
|
namespace OCA\Encryption\Tests\Crypto;
|
||||||
|
|
||||||
|
|
||||||
use OCA\Encryption\Crypto\EncryptAll;
|
use OCA\Encryption\Crypto\EncryptAll;
|
|
@ -20,7 +20,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OCA\Encryption\Tests\lib\Crypto;
|
namespace OCA\Encryption\Tests\Crypto;
|
||||||
|
|
||||||
use OCA\Encryption\Exceptions\PublicKeyMissingException;
|
use OCA\Encryption\Exceptions\PublicKeyMissingException;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
@ -31,31 +31,31 @@ class EncryptionTest extends TestCase {
|
||||||
/** @var Encryption */
|
/** @var Encryption */
|
||||||
private $instance;
|
private $instance;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\KeyManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $keyManagerMock;
|
private $keyManagerMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Crypto\EncryptAll|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $encryptAllMock;
|
private $encryptAllMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Crypto\DecryptAll|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $decryptAllMock;
|
private $decryptAllMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Session|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $sessionMock;
|
private $sessionMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Crypto\Crypt|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $cryptMock;
|
private $cryptMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Util|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $utilMock;
|
private $utilMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $loggerMock;
|
private $loggerMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $l10nMock;
|
private $l10nMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\Files\Storage|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $storageMock;
|
private $storageMock;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
@ -410,7 +410,9 @@ class EncryptionTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPrepareDecryptAll() {
|
public function testPrepareDecryptAll() {
|
||||||
|
/** @var \Symfony\Component\Console\Input\InputInterface $input */
|
||||||
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
||||||
|
/** @var \Symfony\Component\Console\Output\OutputInterface $output */
|
||||||
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
||||||
|
|
||||||
$this->decryptAllMock->expects($this->once())->method('prepare')
|
$this->decryptAllMock->expects($this->once())->method('prepare')
|
|
@ -65,6 +65,7 @@ class HookManagerTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testRegisterHooksWithInstance() {
|
public function testRegisterHooksWithInstance() {
|
||||||
$mock = $this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock();
|
$mock = $this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock();
|
||||||
|
/** @var \OCA\Encryption\Hooks\Contracts\IHook $mock */
|
||||||
self::$instance->registerHook($mock);
|
self::$instance->registerHook($mock);
|
||||||
|
|
||||||
$hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
|
$hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
|
|
@ -69,6 +69,10 @@ class UserHooksTest extends TestCase {
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $cryptMock;
|
private $cryptMock;
|
||||||
|
/**
|
||||||
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||||
|
*/
|
||||||
|
private $loggerMock;
|
||||||
/**
|
/**
|
||||||
* @var UserHooks
|
* @var UserHooks
|
||||||
*/
|
*/
|
||||||
|
@ -91,15 +95,16 @@ class UserHooksTest extends TestCase {
|
||||||
public function testLogout() {
|
public function testLogout() {
|
||||||
$this->sessionMock->expects($this->once())
|
$this->sessionMock->expects($this->once())
|
||||||
->method('clear');
|
->method('clear');
|
||||||
|
$this->instance->logout();
|
||||||
$this->assertNull($this->instance->logout());
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPostCreateUser() {
|
public function testPostCreateUser() {
|
||||||
$this->userSetupMock->expects($this->once())
|
$this->userSetupMock->expects($this->once())
|
||||||
->method('setupUser');
|
->method('setupUser');
|
||||||
|
|
||||||
$this->assertNull($this->instance->postCreateUser($this->params));
|
$this->instance->postCreateUser($this->params);
|
||||||
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPostDeleteUser() {
|
public function testPostDeleteUser() {
|
||||||
|
@ -107,7 +112,8 @@ class UserHooksTest extends TestCase {
|
||||||
->method('deletePublicKey')
|
->method('deletePublicKey')
|
||||||
->with('testUser');
|
->with('testUser');
|
||||||
|
|
||||||
$this->assertNull($this->instance->postDeleteUser($this->params));
|
$this->instance->postDeleteUser($this->params);
|
||||||
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -273,6 +279,7 @@ class UserHooksTest extends TestCase {
|
||||||
]
|
]
|
||||||
)->setMethods(['initMountPoints'])->getMock();
|
)->setMethods(['initMountPoints'])->getMock();
|
||||||
|
|
||||||
|
/** @var \OCA\Encryption\Hooks\UserHooks $userHooks */
|
||||||
$this->assertNull($userHooks->setPassphrase($this->params));
|
$this->assertNull($userHooks->setPassphrase($this->params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +292,8 @@ class UserHooksTest extends TestCase {
|
||||||
->method('setupUser')
|
->method('setupUser')
|
||||||
->with('testUser', 'password');
|
->with('testUser', 'password');
|
||||||
|
|
||||||
$this->assertNull($this->instance->postPasswordReset($this->params));
|
$this->instance->postPasswordReset($this->params);
|
||||||
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
|
@ -43,25 +43,25 @@ class KeyManagerTest extends TestCase {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $systemKeyId;
|
private $systemKeyId;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\Encryption\Keys\IStorage|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $keyStorageMock;
|
private $keyStorageMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Crypto\Crypt|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $cryptMock;
|
private $cryptMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $userMock;
|
private $userMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Session|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $sessionMock;
|
private $sessionMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $logMock;
|
private $logMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCA\Encryption\Util|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $utilMock;
|
private $utilMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $configMock;
|
private $configMock;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
@ -245,6 +245,7 @@ class KeyManagerTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testInit($useMasterKey) {
|
public function testInit($useMasterKey) {
|
||||||
|
|
||||||
|
/** @var \OCA\Encryption\KeyManager|\PHPUnit_Framework_MockObject_MockObject $instance */
|
||||||
$instance = $this->getMockBuilder('OCA\Encryption\KeyManager')
|
$instance = $this->getMockBuilder('OCA\Encryption\KeyManager')
|
||||||
->setConstructorArgs(
|
->setConstructorArgs(
|
||||||
[
|
[
|
||||||
|
@ -588,6 +589,7 @@ class KeyManagerTest extends TestCase {
|
||||||
->with('/admin/files/myfile.txt')
|
->with('/admin/files/myfile.txt')
|
||||||
->willReturn(false);
|
->willReturn(false);
|
||||||
|
|
||||||
|
/** @var \OC\Files\View $view */
|
||||||
$this->assertSame(0, $this->instance->getVersion('/admin/files/myfile.txt', $view));
|
$this->assertSame(0, $this->instance->getVersion('/admin/files/myfile.txt', $view));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,6 +606,7 @@ class KeyManagerTest extends TestCase {
|
||||||
->with('/admin/files/myfile.txt')
|
->with('/admin/files/myfile.txt')
|
||||||
->willReturn($fileInfo);
|
->willReturn($fileInfo);
|
||||||
|
|
||||||
|
/** @var \OC\Files\View $view */
|
||||||
$this->assertSame(1337, $this->instance->getVersion('/admin/files/myfile.txt', $view));
|
$this->assertSame(1337, $this->instance->getVersion('/admin/files/myfile.txt', $view));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,6 +636,7 @@ class KeyManagerTest extends TestCase {
|
||||||
->with('/admin/files/myfile.txt')
|
->with('/admin/files/myfile.txt')
|
||||||
->willReturn($fileInfo);
|
->willReturn($fileInfo);
|
||||||
|
|
||||||
|
/** @var \OC\Files\View $view */
|
||||||
$this->instance->setVersion('/admin/files/myfile.txt', 5, $view);
|
$this->instance->setVersion('/admin/files/myfile.txt', 5, $view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,6 +648,7 @@ class KeyManagerTest extends TestCase {
|
||||||
->with('/admin/files/myfile.txt')
|
->with('/admin/files/myfile.txt')
|
||||||
->willReturn(false);
|
->willReturn(false);
|
||||||
|
|
||||||
|
/** @var \OC\Files\View $view */
|
||||||
$this->instance->setVersion('/admin/files/myfile.txt', 5, $view);
|
$this->instance->setVersion('/admin/files/myfile.txt', 5, $view);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class MigrationTest extends \Test\TestCase {
|
||||||
private $recovery_key_id = 'recovery_key_id';
|
private $recovery_key_id = 'recovery_key_id';
|
||||||
private $moduleId;
|
private $moduleId;
|
||||||
|
|
||||||
/** @var PHPUnit_Framework_MockObject_MockObject | ILogger */
|
/** @var \PHPUnit_Framework_MockObject_MockObject | ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
public static function setUpBeforeClass() {
|
public static function setUpBeforeClass() {
|
|
@ -32,27 +32,27 @@ use Test\TestCase;
|
||||||
class RecoveryTest extends TestCase {
|
class RecoveryTest extends TestCase {
|
||||||
private static $tempStorage = [];
|
private static $tempStorage = [];
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OCP\Encryption\IFile|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $fileMock;
|
private $fileMock;
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $viewMock;
|
private $viewMock;
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $userSessionMock;
|
private $userSessionMock;
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OCA\Encryption\KeyManager|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $keyManagerMock;
|
private $keyManagerMock;
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $configMock;
|
private $configMock;
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OCA\Encryption\Crypto\Crypt|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $cryptMock;
|
private $cryptMock;
|
||||||
/**
|
/**
|
||||||
|
@ -201,7 +201,8 @@ class RecoveryTest extends TestCase {
|
||||||
|
|
||||||
$this->cryptMock->expects($this->once())
|
$this->cryptMock->expects($this->once())
|
||||||
->method('decryptPrivateKey');
|
->method('decryptPrivateKey');
|
||||||
$this->assertNull($this->instance->recoverUsersFiles('password', 'admin'));
|
$this->instance->recoverUsersFiles('password', 'admin');
|
||||||
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRecoverFile() {
|
public function testRecoverFile() {
|
||||||
|
@ -265,9 +266,11 @@ class RecoveryTest extends TestCase {
|
||||||
->will($this->returnSelf());
|
->will($this->returnSelf());
|
||||||
|
|
||||||
$this->cryptMock = $this->getMockBuilder('OCA\Encryption\Crypto\Crypt')->disableOriginalConstructor()->getMock();
|
$this->cryptMock = $this->getMockBuilder('OCA\Encryption\Crypto\Crypt')->disableOriginalConstructor()->getMock();
|
||||||
|
/** @var \OCP\Security\ISecureRandom $randomMock */
|
||||||
$randomMock = $this->getMock('OCP\Security\ISecureRandom');
|
$randomMock = $this->getMock('OCP\Security\ISecureRandom');
|
||||||
$this->keyManagerMock = $this->getMockBuilder('OCA\Encryption\KeyManager')->disableOriginalConstructor()->getMock();
|
$this->keyManagerMock = $this->getMockBuilder('OCA\Encryption\KeyManager')->disableOriginalConstructor()->getMock();
|
||||||
$this->configMock = $this->getMock('OCP\IConfig');
|
$this->configMock = $this->getMock('OCP\IConfig');
|
||||||
|
/** @var \OCP\Encryption\Keys\IStorage $keyStorageMock */
|
||||||
$keyStorageMock = $this->getMock('OCP\Encryption\Keys\IStorage');
|
$keyStorageMock = $this->getMock('OCP\Encryption\Keys\IStorage');
|
||||||
$this->fileMock = $this->getMock('OCP\Encryption\IFile');
|
$this->fileMock = $this->getMock('OCP\Encryption\IFile');
|
||||||
$this->viewMock = $this->getMock('OC\Files\View');
|
$this->viewMock = $this->getMock('OC\Files\View');
|
|
@ -34,6 +34,7 @@ class SessionTest extends TestCase {
|
||||||
* @var Session
|
* @var Session
|
||||||
*/
|
*/
|
||||||
private $instance;
|
private $instance;
|
||||||
|
/** @var \OCP\ISession|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $sessionMock;
|
private $sessionMock;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -29,11 +29,11 @@ use Test\TestCase;
|
||||||
|
|
||||||
class SetupTest extends TestCase {
|
class SetupTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OCA\Encryption\KeyManager|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $keyManagerMock;
|
private $keyManagerMock;
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var \OCA\Encryption\Crypto\Crypt|\PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
private $cryptMock;
|
private $cryptMock;
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +55,8 @@ class SetupTest extends TestCase {
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
/** @var \OCP\ILogger $logMock */
|
||||||
|
/** @var \OCP\IUserSession $userSessionMock */
|
||||||
$this->instance = new Setup($logMock,
|
$this->instance = new Setup($logMock,
|
||||||
$userSessionMock,
|
$userSessionMock,
|
||||||
$this->cryptMock,
|
$this->cryptMock,
|
|
@ -30,16 +30,16 @@ use Test\TestCase;
|
||||||
class UtilTest extends TestCase {
|
class UtilTest extends TestCase {
|
||||||
private static $tempStorage = [];
|
private static $tempStorage = [];
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $configMock;
|
private $configMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $filesMock;
|
private $filesMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $userManagerMock;
|
private $userManagerMock;
|
||||||
|
|
||||||
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
/** @var \OCP\Files\Mount\IMountPoint|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $mountMock;
|
private $mountMock;
|
||||||
|
|
||||||
/** @var Util */
|
/** @var Util */
|
||||||
|
@ -72,10 +72,13 @@ class UtilTest extends TestCase {
|
||||||
$this->filesMock = $this->getMock('OC\Files\View');
|
$this->filesMock = $this->getMock('OC\Files\View');
|
||||||
$this->userManagerMock = $this->getMock('\OCP\IUserManager');
|
$this->userManagerMock = $this->getMock('\OCP\IUserManager');
|
||||||
|
|
||||||
|
/** @var \OCA\Encryption\Crypto\Crypt $cryptMock */
|
||||||
$cryptMock = $this->getMockBuilder('OCA\Encryption\Crypto\Crypt')
|
$cryptMock = $this->getMockBuilder('OCA\Encryption\Crypto\Crypt')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
/** @var \OCP\ILogger $loggerMock */
|
||||||
$loggerMock = $this->getMock('OCP\ILogger');
|
$loggerMock = $this->getMock('OCP\ILogger');
|
||||||
|
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSessionMock */
|
||||||
$userSessionMock = $this->getMockBuilder('OCP\IUserSession')
|
$userSessionMock = $this->getMockBuilder('OCP\IUserSession')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->setMethods([
|
->setMethods([
|
||||||
|
@ -97,7 +100,7 @@ class UtilTest extends TestCase {
|
||||||
->will($this->returnSelf());
|
->will($this->returnSelf());
|
||||||
|
|
||||||
|
|
||||||
$this->configMock = $configMock = $this->getMock('OCP\IConfig');
|
$this->configMock = $this->getMock('OCP\IConfig');
|
||||||
|
|
||||||
$this->configMock->expects($this->any())
|
$this->configMock->expects($this->any())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
|
@ -107,7 +110,7 @@ class UtilTest extends TestCase {
|
||||||
->method('setUserValue')
|
->method('setUserValue')
|
||||||
->will($this->returnCallback([$this, 'setValueTester']));
|
->will($this->returnCallback([$this, 'setValueTester']));
|
||||||
|
|
||||||
$this->instance = new Util($this->filesMock, $cryptMock, $loggerMock, $userSessionMock, $configMock, $this->userManagerMock);
|
$this->instance = new Util($this->filesMock, $cryptMock, $loggerMock, $userSessionMock, $this->configMock, $this->userManagerMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,8 +160,8 @@ class UtilTest extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataTestShouldEncryptHomeStorage
|
* @dataProvider dataTestShouldEncryptHomeStorage
|
||||||
* @param $returnValue return value from getAppValue()
|
* @param string $returnValue return value from getAppValue()
|
||||||
* @param $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testShouldEncryptHomeStorage($returnValue, $expected) {
|
public function testShouldEncryptHomeStorage($returnValue, $expected) {
|
||||||
$this->configMock->expects($this->once())->method('getAppValue')
|
$this->configMock->expects($this->once())->method('getAppValue')
|
||||||
|
@ -195,12 +198,16 @@ class UtilTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetStorage() {
|
public function testGetStorage() {
|
||||||
|
$return = $this->getMockBuilder('OC\Files\Storage\Storage')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
$path = '/foo/bar.txt';
|
$path = '/foo/bar.txt';
|
||||||
$this->filesMock->expects($this->once())->method('getMount')->with($path)
|
$this->filesMock->expects($this->once())->method('getMount')->with($path)
|
||||||
->willReturn($this->mountMock);
|
->willReturn($this->mountMock);
|
||||||
$this->mountMock->expects($this->once())->method('getStorage')->willReturn(true);
|
$this->mountMock->expects($this->once())->method('getStorage')->willReturn($return);
|
||||||
|
|
||||||
$this->assertTrue($this->instance->getStorage($path));
|
$this->assertEquals($return, $this->instance->getStorage($path));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue