2015-03-30 14:23:10 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Test\Files\Storage\Wrapper;
|
|
|
|
|
2015-04-02 19:12:20 +03:00
|
|
|
use OC\Files\Storage\Temporary;
|
2015-03-30 14:23:10 +03:00
|
|
|
use OC\Files\View;
|
|
|
|
|
|
|
|
class Encryption extends \Test\Files\Storage\Storage {
|
|
|
|
|
|
|
|
/**
|
2015-04-02 19:12:20 +03:00
|
|
|
* @var Temporary
|
2015-03-30 14:23:10 +03:00
|
|
|
*/
|
|
|
|
private $sourceStorage;
|
|
|
|
|
2015-04-22 13:12:27 +03:00
|
|
|
/**
|
|
|
|
* @var \OC\Encryption\Keys\Storage | \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
private $keyStore;
|
|
|
|
|
2015-03-30 14:23:10 +03:00
|
|
|
public function setUp() {
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
2015-04-02 15:44:58 +03:00
|
|
|
$mockModule = $this->buildMockModule();
|
2015-03-30 14:23:10 +03:00
|
|
|
$encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager')
|
|
|
|
->disableOriginalConstructor()
|
2015-04-02 19:12:20 +03:00
|
|
|
->setMethods(['getDefaultEncryptionModule', 'getEncryptionModule', 'isEnabled'])
|
2015-03-31 00:19:35 +03:00
|
|
|
->getMock();
|
2015-03-30 14:23:10 +03:00
|
|
|
$encryptionManager->expects($this->any())
|
|
|
|
->method('getDefaultEncryptionModule')
|
2015-04-02 15:44:58 +03:00
|
|
|
->willReturn($mockModule);
|
|
|
|
$encryptionManager->expects($this->any())
|
|
|
|
->method('getEncryptionModule')
|
|
|
|
->willReturn($mockModule);
|
2015-04-02 19:12:20 +03:00
|
|
|
$encryptionManager->expects($this->any())
|
|
|
|
->method('isEnabled')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$config = $this->getMockBuilder('\OCP\IConfig')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-04-15 14:19:17 +03:00
|
|
|
$groupManager = $this->getMockBuilder('\OC\Group\Manager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-03-30 14:23:10 +03:00
|
|
|
|
2015-04-15 14:19:17 +03:00
|
|
|
$util = $this->getMock('\OC\Encryption\Util', ['getUidAndFilename'], [new View(), new \OC\User\Manager(), $groupManager, $config]);
|
2015-04-02 15:44:58 +03:00
|
|
|
$util->expects($this->any())
|
|
|
|
->method('getUidAndFilename')
|
|
|
|
->willReturnCallback(function ($path) {
|
|
|
|
return ['user1', $path];
|
|
|
|
});
|
2015-04-02 19:12:20 +03:00
|
|
|
|
2015-04-02 15:44:58 +03:00
|
|
|
$file = $this->getMockBuilder('\OC\Encryption\File')
|
|
|
|
->disableOriginalConstructor()
|
2015-04-09 19:30:45 +03:00
|
|
|
->setMethods(['getAccessList'])
|
2015-04-02 15:44:58 +03:00
|
|
|
->getMock();
|
2015-04-09 19:30:45 +03:00
|
|
|
$file->expects($this->any())->method('getAccessList')->willReturn([]);
|
2015-03-30 14:23:10 +03:00
|
|
|
|
|
|
|
$logger = $this->getMock('\OC\Log');
|
|
|
|
|
2015-04-02 19:12:20 +03:00
|
|
|
$this->sourceStorage = new Temporary(array());
|
2015-04-22 13:12:27 +03:00
|
|
|
$this->keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage')
|
2015-04-02 15:44:58 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
2015-04-07 11:03:44 +03:00
|
|
|
$mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(['getOption'])
|
|
|
|
->getMock();
|
|
|
|
$mount->expects($this->any())->method('getOption')->willReturn(true);
|
2015-04-02 15:44:58 +03:00
|
|
|
$this->instance = new EncryptionWrapper([
|
2015-03-30 14:23:10 +03:00
|
|
|
'storage' => $this->sourceStorage,
|
|
|
|
'root' => 'foo',
|
2015-04-07 11:03:44 +03:00
|
|
|
'mountPoint' => '/',
|
|
|
|
'mount' => $mount
|
2015-03-30 14:23:10 +03:00
|
|
|
],
|
2015-04-22 13:12:27 +03:00
|
|
|
$encryptionManager, $util, $logger, $file, null, $this->keyStore
|
2015-03-30 14:23:10 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-02 15:44:58 +03:00
|
|
|
/**
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected function buildMockModule() {
|
|
|
|
$encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
|
|
|
|
->disableOriginalConstructor()
|
2015-04-14 13:53:13 +03:00
|
|
|
->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize'])
|
2015-04-02 15:44:58 +03:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
|
|
|
|
$encryptionModule->expects($this->any())->method('getDisplayName')->willReturn('Unit test module');
|
|
|
|
$encryptionModule->expects($this->any())->method('begin')->willReturn([]);
|
|
|
|
$encryptionModule->expects($this->any())->method('end')->willReturn('');
|
|
|
|
$encryptionModule->expects($this->any())->method('encrypt')->willReturnArgument(0);
|
|
|
|
$encryptionModule->expects($this->any())->method('decrypt')->willReturnArgument(0);
|
|
|
|
$encryptionModule->expects($this->any())->method('update')->willReturn(true);
|
|
|
|
$encryptionModule->expects($this->any())->method('shouldEncrypt')->willReturn(true);
|
2015-04-03 12:42:25 +03:00
|
|
|
$encryptionModule->expects($this->any())->method('getUnencryptedBlockSize')->willReturn(8192);
|
2015-04-02 15:44:58 +03:00
|
|
|
return $encryptionModule;
|
|
|
|
}
|
2015-04-22 13:12:27 +03:00
|
|
|
|
|
|
|
public function testRename() {
|
|
|
|
$this->keyStore
|
|
|
|
->expects($this->once())
|
|
|
|
->method('renameKeys');
|
|
|
|
$this->instance->mkdir('folder');
|
|
|
|
$this->instance->rename('folder', 'flodder');
|
|
|
|
}
|
2015-03-30 14:23:10 +03:00
|
|
|
}
|
2015-04-02 15:44:58 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// FIXME: this is too bad and needs adjustment
|
|
|
|
//
|
|
|
|
class EncryptionWrapper extends \OC\Files\Storage\Wrapper\Encryption {
|
|
|
|
private $keyStore;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
$parameters,
|
|
|
|
\OC\Encryption\Manager $encryptionManager = null,
|
|
|
|
\OC\Encryption\Util $util = null,
|
|
|
|
\OC\Log $logger = null,
|
|
|
|
\OC\Encryption\File $fileHelper = null,
|
|
|
|
$uid = null,
|
|
|
|
$keyStore = null
|
|
|
|
) {
|
|
|
|
$this->keyStore = $keyStore;
|
|
|
|
parent::__construct($parameters, $encryptionManager, $util, $logger, $fileHelper, $uid);
|
|
|
|
}
|
|
|
|
|
2015-04-22 12:18:18 +03:00
|
|
|
protected function getKeyStorage() {
|
2015-04-02 15:44:58 +03:00
|
|
|
return $this->keyStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|